2023-04-11 14:47:54 +02:00
|
|
|
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,
|
|
|
|
},
|
2023-10-02 14:25:46 +02:00
|
|
|
],
|
2023-04-11 14:47:54 +02:00
|
|
|
);
|
|
|
|
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 />
|
2023-10-02 14:25:46 +02:00
|
|
|
</AccessProviderMock>,
|
2023-04-11 14:47:54 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
const result = await screen.findByText('change request');
|
|
|
|
expect(result).toBeInTheDocument();
|
|
|
|
|
|
|
|
render(
|
|
|
|
<AccessProviderMock
|
|
|
|
permissions={[
|
|
|
|
{
|
|
|
|
permission: SKIP_CHANGE_REQUEST,
|
|
|
|
project,
|
|
|
|
environment,
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
>
|
|
|
|
<TestComponent />
|
2023-10-02 14:25:46 +02:00
|
|
|
</AccessProviderMock>,
|
2023-04-11 14:47:54 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
const regularModeElement = await screen.findByText('regular mode');
|
|
|
|
expect(regularModeElement).toBeInTheDocument();
|
|
|
|
});
|