Skip to content

Commit

Permalink
#167 Fix wizard submit when last step is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
wouter-adriaens committed Nov 17, 2023
1 parent dbbd49f commit 241ed6d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
43 changes: 43 additions & 0 deletions src/__tests__/OeWizard.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,49 @@ describe('OeWizard', () => {
});
});

describe('last step invalid', () => {
const TestComponent = defineComponent({
components: { OeWizard },
setup() {
const steps: IStep[] = [
{ name: 'Algemene gegevens', validate: () => Promise.resolve({ valid: true }) },
{ name: 'Mijn gegevens', validate: () => Promise.resolve({ valid: true }) },
{ name: 'Bijlagen', validate: () => Promise.resolve({ valid: true }) },
{ name: 'Overzicht', validate: () => Promise.resolve({ valid: false }) },
];

return { steps };
},
template: `
<oe-wizard :steps="steps">
<template #default="{ currentStep, totalSteps }">
<h2>Stap {{ currentStep + 1 }} van {{ totalSteps }}</h2>
</template>
</oe-wizard>
`,
});

beforeEach(() => {
cy.viewport('macbook-16');
});

it('does not submit the wizard when clicking on submit in the latest step when the step is invalid', () => {
const onSubmitSpy = cy.spy().as('onSubmitSpy');

cy.mount(TestComponent, { props: { onSubmit: onSubmitSpy } }).then(() => {
cy.dataCy('next-step-button').click();
cy.dataCy('next-step-button').click();
cy.dataCy('next-step-button').click();

cy.get('.wizard__bar-item--current').invoke('text').should('equal', '4Overzicht');

cy.dataCy('submit-button').should('exist').click();

cy.get('@onSubmitSpy').should('not.have.been.called');
});
});
});

describe('bar navigation allowed', () => {
const TestComponent = defineComponent({
components: { OeWizard },
Expand Down
2 changes: 1 addition & 1 deletion src/components/dumb/OeWizard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const goToStep = async (step: number) => {
};
const submit = async () => {
if (await props.steps[currentStep.value].validate()) {
if ((await props.steps[totalSteps.value - 1].validate()).valid) {
emit('submit');
}
};
Expand Down

0 comments on commit 241ed6d

Please sign in to comment.