Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: skip change request in UI (#3495)
- Loading branch information
Showing
7 changed files
with
121 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { AccessProviderMock } from '../component/providers/AccessProvider/AccessProviderMock'; | ||
import { useChangeRequestsEnabled } from './useChangeRequestsEnabled'; | ||
import { FC } from 'react'; | ||
import { testServerRoute, testServerSetup } from '../utils/testServer'; | ||
import { | ||
SKIP_CHANGE_REQUEST, | ||
ADMIN, | ||
} from '../component/providers/AccessProvider/permissions'; | ||
|
||
const project = 'project'; | ||
const environment = 'production'; | ||
|
||
const TestComponent: FC = () => { | ||
const { isChangeRequestConfigured } = useChangeRequestsEnabled(project); | ||
|
||
const string = isChangeRequestConfigured('production') | ||
? 'change request' | ||
: 'regular mode'; | ||
|
||
return <div>{string}</div>; | ||
}; | ||
|
||
const server = testServerSetup(); | ||
|
||
testServerRoute( | ||
server, | ||
`/api/admin/projects/${project}/change-requests/config`, | ||
[ | ||
{ | ||
environment, | ||
changeRequestEnabled: true, | ||
}, | ||
] | ||
); | ||
testServerRoute(server, '/api/admin/ui-config', { | ||
versionInfo: { | ||
current: { enterprise: 'present' }, | ||
}, | ||
}); | ||
|
||
test('SKIP_CHANGE_REQUEST disables change request mode', async () => { | ||
render( | ||
<AccessProviderMock | ||
permissions={[ | ||
{ | ||
permission: ADMIN, | ||
project, | ||
environment, | ||
}, | ||
]} | ||
> | ||
<TestComponent /> | ||
</AccessProviderMock> | ||
); | ||
|
||
const result = await screen.findByText('change request'); | ||
expect(result).toBeInTheDocument(); | ||
|
||
render( | ||
<AccessProviderMock | ||
permissions={[ | ||
{ | ||
permission: SKIP_CHANGE_REQUEST, | ||
project, | ||
environment, | ||
}, | ||
]} | ||
> | ||
<TestComponent /> | ||
</AccessProviderMock> | ||
); | ||
|
||
const regularModeElement = await screen.findByText('regular mode'); | ||
expect(regularModeElement).toBeInTheDocument(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
exports.up = function (db, callback) { | ||
db.runSql( | ||
` | ||
UPDATE permissions SET display_name = 'Skip change request process' WHERE permission = 'SKIP_CHANGE_REQUEST'; | ||
`, | ||
callback, | ||
); | ||
}; | ||
|
||
exports.down = function (db, callback) { | ||
db.runSql( | ||
` | ||
UPDATE permissions SET display_name = 'Skip change request process (API-only)' WHERE permission = 'SKIP_CHANGE_REQUEST'; | ||
`, | ||
callback, | ||
); | ||
}; |