Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
daniele-mng committed Jul 9, 2024
1 parent 065b112 commit 18a2ac2
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/web/components/conditionalRoute/__tests__/ConditionalRoute.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* SPDX-FileCopyrightText: 2024 Greenbone AG
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import {describe, test, expect} from '@gsa/testing';
import {screen, rendererWith} from 'web/utils/testing';
import {Route, MemoryRouter} from 'react-router-dom';
import ConditionalRoute from 'web/components/conditionalRoute/ConditionalRoute';
import Capabilities from 'gmp/capabilities/capabilities';

const MockComponent = () => <div>Mock Component</div>;

describe('ConditionalRoute', () => {
const featureList = [
{name: 'ENABLED_FEATURE', _enabled: 1},
{name: 'DISABLED_FEATURE', _enabled: 0},
];
const capabilities = new Capabilities(['everything'], featureList);
const {render} = rendererWith({capabilities, router: true});
test.each([
{
feature: 'ENABLED_FEATURE',
expectedText: 'Mock Component',
description: 'renders the component when the feature is enabled',
},
{
feature: 'DISABLED_FEATURE',
expectedText: 'Not Found',
description: 'redirects when the feature is disabled',
},
{
feature: 'unknown-feature',
expectedText: 'Not Found',
description: 'does not render the component for an unknown feature',
},
])('$description', ({feature, expectedText}) => {
render(
<MemoryRouter>
<ConditionalRoute component={MockComponent} feature={feature} />
<Route path="/notfound" render={() => <div>Not Found</div>} />
</MemoryRouter>,
);

expect(screen.getByText(expectedText)).toBeVisible();
});
});

0 comments on commit 18a2ac2

Please sign in to comment.