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#2952] Support form steps to be N/A by default #575

Merged
merged 1 commit into from
Oct 27, 2023
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
3 changes: 2 additions & 1 deletion src/components/ProgressIndicator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const ProgressIndicator = ({
to: step.href || `/stap/${step.slug}`,
formDefinition: step.formDefinition,
isCompleted: submission ? submission.steps[index].completed : false,
isApplicable: submission ? submission.steps[index].isApplicable : true,
isApplicable: submission ? submission.steps[index].isApplicable : step.isApplicable ?? true,
isCurrent: step.slug === stepSlug,
canNavigateTo: canNavigateToStep(index),
}));
Expand Down Expand Up @@ -131,6 +131,7 @@ ProgressIndicator.propTypes = {
slug: PropTypes.string.isRequired,
href: PropTypes.string,
formDefinition: PropTypes.string.isRequired,
isApplicable: PropTypes.bool,
})
).isRequired,
submissionAllowed: PropTypes.oneOf(Object.values(SUBMISSION_ALLOWED)).isRequired,
Expand Down
89 changes: 57 additions & 32 deletions src/components/ProgressIndicator/test.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {screen} from '@testing-library/react';
import messagesNL from 'i18n/compiled/nl.json';
import React from 'react';
import {createRoot} from 'react-dom/client';
Expand Down Expand Up @@ -137,7 +138,7 @@ it('Form landing page, no submission present in session', () => {
expect(progressIndicatorSteps.textContent).toContain('Bevestiging');
});

it('Progress indicator does NOT let you navigate between steps if you are NOT a form designer', () => {
it('Progress indicator does NOT let you navigate between steps if you are NOT a form designer', async () => {
const steps = [
{
slug: 'step-1',
Expand Down Expand Up @@ -189,20 +190,13 @@ it('Progress indicator does NOT let you navigate between steps if you are NOT a
);
});

const step1 = container.getElementsByTagName('li')[1]; // Item 0 is the 'inloggen' step
const step3 = container.getElementsByTagName('li')[3];

const link = step1.getElementsByTagName('a')[0];
const disabledLink = step3.getElementsByTagName('span')[0];

expect(link).not.toBeUndefined();
expect(disabledLink).not.toBeUndefined();

expect(link.textContent).toContain('Step 1');
expect(disabledLink.textContent).toContain('Step 3');
expect(await screen.findByRole('link', {name: 'Step 1'})).toHaveTextContent('Step 1');
// span element: `generic` role:
expect(await screen.findByRole('generic', {name: 'Step 3'})).toHaveTextContent('Step 3');
expect(await screen.queryByRole('link', {name: 'Step 3'})).toBeNull();
});

it('Progress indicator DOES let you navigate between steps if you ARE a form designer', () => {
it('Progress indicator DOES let you navigate between steps if you ARE a form designer', async () => {
const steps = [
{
slug: 'step-1',
Expand Down Expand Up @@ -254,20 +248,11 @@ it('Progress indicator DOES let you navigate between steps if you ARE a form des
);
});

const step1 = container.getElementsByTagName('li')[1]; // Item 0 is the 'inloggen' step
const step3 = container.getElementsByTagName('li')[3];

const link1 = step1.getElementsByTagName('a')[0];
const link2 = step3.getElementsByTagName('a')[0];

expect(link1).not.toBeUndefined();
expect(link2).not.toBeUndefined();

expect(link1.textContent).toContain('Step 1');
expect(link2.textContent).toContain('Step 3');
expect(await screen.findByRole('link', {name: 'Step 1'})).toHaveTextContent('Step 1');
expect(await screen.findByRole('link', {name: 'Step 3'})).toHaveTextContent('Step 3');
});

it('Progress indicator DOES let you navigate between steps if you are NOT a form designer but a step is NOT applicable', () => {
it('Progress indicator DOES let you navigate between steps if you are NOT a form designer but a step is NOT applicable', async () => {
const steps = [
{
slug: 'step-1',
Expand Down Expand Up @@ -319,15 +304,11 @@ it('Progress indicator DOES let you navigate between steps if you are NOT a form
);
});

const step3 = container.getElementsByTagName('li')[3];

const link = step3.getElementsByTagName('a')[0];

expect(link).not.toBeUndefined();
expect(link.textContent).toContain('Step 3');
expect(await screen.findByRole('link', {name: 'Step 3'})).toBeDefined();
expect(await screen.findByRole('link', {name: 'Step 3'})).toHaveTextContent('Step 3');
});

it('Progress indicator does NOT let you navigate to the overview if a step is blocked', () => {
it('Progress indicator does NOT let you navigate to the overview if a step is blocked', async () => {
const steps = [
{
slug: 'step-1',
Expand Down Expand Up @@ -372,3 +353,47 @@ it('Progress indicator does NOT let you navigate to the overview if a step is bl
expect(overviewSpan).not.toBeUndefined();
expect(overviewSpan.textContent).toContain('Overzicht');
});

it('Progress indicator takes into account default step applicability when on start page', async () => {
const steps = [
{
slug: 'step-1',
formDefinition: 'Step 1',
index: 0,
isApplicable: true,
url: 'http://test.nl/api/v1/forms/111/steps/111',
uuid: '111',
completed: true,
canSubmit: false,
},
{
slug: 'step-2',
formDefinition: 'Step 2',
index: 0,
isApplicable: false,
url: 'http://test.nl/api/v1/forms/111/steps/111',
uuid: '222',
completed: true,
canSubmit: false,
},
];

IsFormDesigner.getValue.mockReturnValue(true);

act(() => {
root.render(
<MemoryRouter initialEntries={['/']}>
<IntlProvider locale="nl" messages={messagesNL}>
<ProgressIndicator
title="Test Name"
steps={steps}
submissionAllowed={SUBMISSION_ALLOWED.yes}
/>
</IntlProvider>
</MemoryRouter>
);
});

expect(await screen.findByRole('link', {name: 'Step 1'})).toBeDefined();
expect(await screen.queryByRole('link', {name: 'Step 2'})).toBeNull();
});