mirror of
https://github.com/Unleash/unleash.git
synced 2025-08-18 13:48:58 +02:00
add test
Signed-off-by: andreas-unleash <andreas@getunleash.ai>
This commit is contained in:
parent
c84f39ad7c
commit
8070d98e1c
@ -0,0 +1,68 @@
|
|||||||
|
import { render, screen } from '@testing-library/react';
|
||||||
|
import { testServerRoute, testServerSetup } from 'utils/testServer';
|
||||||
|
import { FeatureToggleSwitch } from './FeatureToggleSwitch';
|
||||||
|
import { MemoryRouter, Route, Routes } from 'react-router-dom';
|
||||||
|
import { FC } from 'react';
|
||||||
|
import { UIProviderContainer } from '../../../../providers/UIProvider/UIProviderContainer';
|
||||||
|
import { ThemeProvider } from '../../../../../themes/ThemeProvider';
|
||||||
|
import { AccessProviderMock } from '../../../../providers/AccessProvider/AccessProviderMock';
|
||||||
|
import { UPDATE_FEATURE_ENVIRONMENT } from '../../../../providers/AccessProvider/permissions';
|
||||||
|
|
||||||
|
const server = testServerSetup();
|
||||||
|
|
||||||
|
const UnleashUiSetup: FC<{ path: string; pathTemplate: string }> = ({
|
||||||
|
children,
|
||||||
|
path,
|
||||||
|
pathTemplate,
|
||||||
|
}) => (
|
||||||
|
<UIProviderContainer>
|
||||||
|
<AccessProviderMock
|
||||||
|
permissions={[{ permission: UPDATE_FEATURE_ENVIRONMENT }]}
|
||||||
|
>
|
||||||
|
<MemoryRouter initialEntries={[path]}>
|
||||||
|
<ThemeProvider>
|
||||||
|
{/*<AnnouncerProvider>*/}
|
||||||
|
<Routes>
|
||||||
|
<Route path={pathTemplate} element={children} />
|
||||||
|
</Routes>
|
||||||
|
{/*</AnnouncerProvider>*/}
|
||||||
|
</ThemeProvider>
|
||||||
|
</MemoryRouter>
|
||||||
|
</AccessProviderMock>
|
||||||
|
</UIProviderContainer>
|
||||||
|
);
|
||||||
|
|
||||||
|
test('it should show prod guard when production environment', () => {
|
||||||
|
testServerRoute(server, '/api/admin/ui-config', {});
|
||||||
|
testServerRoute(
|
||||||
|
server,
|
||||||
|
'/api/admin/projects/default/features/some-feature',
|
||||||
|
{
|
||||||
|
name: 'feature1',
|
||||||
|
environments: [
|
||||||
|
{ name: 'env1', type: 'production', enabled: false },
|
||||||
|
{ name: 'env2', enabled: false },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
render(
|
||||||
|
<UnleashUiSetup
|
||||||
|
path={'/projects/default/features/some-feature'}
|
||||||
|
pathTemplate={'/projects/:projectId/features/:featureId/*'}
|
||||||
|
>
|
||||||
|
<FeatureToggleSwitch
|
||||||
|
featureId={'some-feature'}
|
||||||
|
environmentName={'env1'}
|
||||||
|
projectId={'default'}
|
||||||
|
value={false}
|
||||||
|
/>
|
||||||
|
</UnleashUiSetup>
|
||||||
|
);
|
||||||
|
|
||||||
|
const toggle = screen.getByRole(`checkbox`);
|
||||||
|
toggle.click();
|
||||||
|
expect(
|
||||||
|
screen.getByText('Changing production environment')
|
||||||
|
).toBeInTheDocument();
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user