Skip to content

Commit

Permalink
✅ [open-formulieren/open-forms#4918] Add test for passing initial_dat…
Browse files Browse the repository at this point in the history
…a_reference when redirecting
  • Loading branch information
stevenbal committed Dec 16, 2024
1 parent 567b294 commit 1bb68b9
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions src/components/Form.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import {render, screen, waitFor, waitForElementToBeRemoved} from '@testing-library/react';
import {act, render, screen, waitFor, waitForElementToBeRemoved} 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 {RouterProvider, createMemoryRouter, useNavigate} from 'react-router-dom';

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

import Form from './Form';
import {START_FORM_QUERY_PARAM} from './constants';

window.scrollTo = vi.fn();
Expand Down Expand Up @@ -114,3 +115,38 @@ test('Start form with object reference query param', async () => {
const requestBody = await startSubmissionRequest.json();
expect(requestBody.initialDataReference).toBe('foo');
});

// Regression test for https://github.com/open-formulieren/open-forms/issues/4918
test.each([
{
introductionPageContent: '',
buttonText: 'Login with DigiD',
expectedUrl:
'http://mock-digid.nl/login?next=http%3A%2F%2Flocalhost%2F%3F_start%3D1%26initial_data_reference%3Dfoo',
},
{
introductionPageContent: 'foo',
buttonText: 'Continue',
expectedUrl: '/startpagina?initial_data_reference=foo',
},
])(
'Redirect to start page or introduction page should preserve initial_data_reference param',
async ({introductionPageContent, buttonText, expectedUrl}) => {
mswServer.use(mockAnalyticsToolConfigGet(), mockSubmissionPost(), mockSubmissionStepGet());

render(
<Wrapper
form={buildForm({
loginOptions: [{identifier: 'digid', label: 'DigiD', url: 'http://mock-digid.nl/login'}],
introductionPageContent: introductionPageContent,
})}
initialEntry={`/?initial_data_reference=foo`}
/>
);

await waitFor(() => {
const loginLink = screen.getByRole('link', {name: buttonText});
expect(loginLink).toHaveAttribute('href', expectedUrl);
});
}
);

0 comments on commit 1bb68b9

Please sign in to comment.