Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [open-formulieren/open-forms#4918] Pass initial_data_reference when redirecting to formstart #754

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/components/Form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -350,16 +350,18 @@ const Form = () => {
) : null;

if (state.startingError) throw state.startingError;

let startPageUrl = introductionPageContent ? 'introductie' : 'startpagina';
const extraStartUrlParams = {};
if (initialDataReference) extraStartUrlParams.initial_data_reference = initialDataReference;
if (initialDataReference) {
extraStartUrlParams.initial_data_reference = initialDataReference;
startPageUrl = `${startPageUrl}?${new URLSearchParams(extraStartUrlParams).toString()}`;
}

// Route the correct page based on URL
const router = (
<Routes>
<Route
path=""
element={<Navigate replace to={introductionPageContent ? 'introductie' : 'startpagina'} />}
/>
<Route path="" element={<Navigate replace to={startPageUrl} />} />

<Route
path="introductie"
Expand Down
33 changes: 33 additions & 0 deletions src/components/Form.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,36 @@ 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"
/>
);

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