Skip to content

Commit

Permalink
✅ [open-formulieren/open-forms#4929] Add tests for top-level Cosign c…
Browse files Browse the repository at this point in the history
…omponent (start)

The top-level component is responsible for some state management while
the child route ./start actually ensures the right component gets
rendered.

Setting up the tests like this gets the boilerplate out of the way and
allows us to test from the user perspective for the more complicated
stuff in the cosign component.
  • Loading branch information
sergei-maertens committed Jan 8, 2025
1 parent bf2b51f commit 083942f
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions src/components/CoSign/Cosign.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import {render, screen} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import messagesEN from 'i18n/compiled/en.json';
import {IntlProvider} from 'react-intl';
import {RouterProvider, createMemoryRouter} from 'react-router-dom';

import {ConfigContext, FormContext} from 'Context';
import {BASE_URL, buildForm} from 'api-mocks';
import mswServer from 'api-mocks/msw-server';
import {mockSubmissionPost, mockSubmissionStepGet} from 'api-mocks/submissions';

import Cosign from './Cosign';
import {default as nestedRoutes} from './routes';

beforeEach(() => {
localStorage.clear();
});

afterEach(() => {
localStorage.clear();
});

const TEST_FORM = buildForm({
loginOptions: [
{
identifier: 'digid',
label: 'DigiD',
url: '#',
logo: {
title: 'DigiD simulatie',
imageSrc: './digid.png',
href: 'https://www.digid.nl/',
appearance: 'dark',
},
isForGemachtigde: false,
},
],
cosignLoginOptions: [
{
identifier: 'digid',
label: 'DigiD Cosign',
url: 'http://localhost:8000/auth/digid/?next=http://localhost:8000/cosign&code=123',
logo: {
title: 'DigiD simulatie',
imageSrc: './digid.png',
href: 'https://www.digid.nl/',
appearance: 'dark',
},
isForGemachtigde: false,
},
],
loginRequired: true,
});

const routes = [
{
path: '/cosign/*',
element: <Cosign />,
children: nestedRoutes,
},
];

const Wrapper = () => {
const router = createMemoryRouter(routes, {
initialEntries: ['/cosign/start'],
initialIndex: 0,
});
return (
<ConfigContext.Provider
value={{
baseUrl: BASE_URL,
clientBaseUrl: 'http://localhost/',
basePath: '',
baseTitle: '',
requiredFieldsWithAsterisk: true,
}}
>
<IntlProvider locale="en" messages={messagesEN}>
<FormContext.Provider value={TEST_FORM}>
<RouterProvider router={router} />
</FormContext.Provider>
</IntlProvider>
</ConfigContext.Provider>
);
};

test('Cosign start route renders start/login page', async () => {
render(<Wrapper />);

expect(await screen.findByRole('link', {name: 'Login with DigiD Cosign'})).toBeVisible();
});

0 comments on commit 083942f

Please sign in to comment.