Skip to content

Commit

Permalink
#155 export toaster, fix stories + update IStep interface
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickkuypers committed Nov 13, 2023
1 parent 013c7c4 commit 6d698df
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 45 deletions.
47 changes: 27 additions & 20 deletions src/__tests__/OeWizard.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ describe('OeWizard', () => {
components: { OeWizard },
setup() {
const steps: IStep[] = [
{ name: 'Algemene gegevens', validate: () => Promise.resolve(true) },
{ name: 'Mijn gegevens', validate: () => Promise.resolve(true) },
{ name: 'Bijlagen', validate: () => Promise.resolve(true) },
{ name: 'Overzicht', validate: () => Promise.resolve(true) },
{ 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: true }) },
];

return { steps };
Expand Down Expand Up @@ -152,10 +152,10 @@ describe('OeWizard', () => {
components: { OeWizard },
setup() {
const steps: IStep[] = [
{ name: 'Algemene gegevens', validate: () => Promise.resolve(true) },
{ name: 'Mijn gegevens', validate: () => Promise.resolve(true) },
{ name: 'Bijlagen', validate: () => Promise.resolve(true) },
{ name: 'Overzicht', validate: () => Promise.resolve(true) },
{ 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: true }) },
];

return { steps };
Expand All @@ -178,10 +178,10 @@ describe('OeWizard', () => {
components: { OeWizard },
setup() {
const steps: IStep[] = [
{ name: 'Algemene gegevens', validate: () => Promise.resolve(true) },
{ name: 'Mijn gegevens', validate: () => Promise.resolve(false) },
{ name: 'Bijlagen', validate: () => Promise.resolve(true) },
{ name: 'Overzicht', validate: () => Promise.resolve(true) },
{ 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: true }) },
];

return { steps };
Expand Down Expand Up @@ -210,10 +210,17 @@ describe('OeWizard', () => {
components: { OeWizard },
setup() {
const steps: IStep[] = [
{ name: 'Algemene gegevens', validate: () => Promise.resolve(true) },
{ name: 'Mijn gegevens', validate: () => Promise.resolve(false) },
{ name: 'Bijlagen', validate: () => Promise.resolve(true) },
{ name: 'Overzicht', validate: () => Promise.resolve(true) },
{ name: 'Algemene gegevens', validate: () => Promise.resolve({ valid: true }) },
{
name: 'Mijn gegevens',
validate: () =>
Promise.resolve({
valid: false,
error: { id: '1', title: 'Error titel', content: 'Er heeft zich een error voorgedaan', type: 'error' },
}),
},
{ name: 'Bijlagen', validate: () => Promise.resolve({ valid: true }) },
{ name: 'Overzicht', validate: () => Promise.resolve({ valid: true }) },
];

return { steps };
Expand Down Expand Up @@ -283,10 +290,10 @@ describe('OeWizard', () => {
components: { OeWizard },
setup() {
const steps: IStep[] = [
{ name: 'Algemene gegevens', validate: () => Promise.resolve(true) },
{ name: 'Mijn gegevens', validate: () => Promise.resolve(true), nextStepDisabled: true },
{ name: 'Bijlagen', validate: () => Promise.resolve(true) },
{ name: 'Overzicht', validate: () => Promise.resolve(true) },
{ name: 'Algemene gegevens', validate: () => Promise.resolve({ valid: true }) },
{ name: 'Mijn gegevens', validate: () => Promise.resolve({ valid: true }), nextStepDisabled: true },
{ name: 'Bijlagen', validate: () => Promise.resolve({ valid: true }) },
{ name: 'Overzicht', validate: () => Promise.resolve({ valid: true }) },
];

return { steps };
Expand Down
1 change: 1 addition & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export * from './oe-openlayers';
export * from './oe-zoneerder-config';
export * from './status';
export * from './system-fields';
export * from './toast';
export * from './wizard';
8 changes: 8 additions & 0 deletions src/models/toast.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface IToast {
id?: string;
type: ToastType;
title: string;
content: string | string[];
}

export type ToastType = 'default' | 'error' | 'success' | 'warning';
4 changes: 3 additions & 1 deletion src/models/wizard.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { IToast } from './toast';

export interface IWizardProps {
steps: IStep[];
allowBarNavigation?: boolean;
Expand All @@ -6,6 +8,6 @@ export interface IWizardProps {

export interface IStep {
name: string;
validate: () => Promise<boolean>;
validate: () => Promise<{ valid: boolean; error?: IToast }>;
nextStepDisabled?: boolean;
}
91 changes: 67 additions & 24 deletions src/stories/dumb-components/wizard.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ export const Default: Story = {
},
setup() {
const steps: IStep[] = [
{ name: 'Gegevens EPC', validate: () => Promise.resolve(true) },
{ name: 'Mijn gegevens', validate: () => Promise.resolve(true) },
{ name: 'Bijlagen', validate: () => Promise.resolve(true) },
{ name: 'Overzicht', validate: () => Promise.resolve(true) },
{ name: 'Gegevens EPC', 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: true }) },
];

return { steps };
Expand Down Expand Up @@ -86,10 +86,10 @@ export const BarNavigationAllowed: Story = {
},
setup() {
const steps: IStep[] = [
{ name: 'Gegevens EPC', validate: () => Promise.resolve(true) },
{ name: 'Mijn gegevens', validate: () => Promise.resolve(true) },
{ name: 'Bijlagen', validate: () => Promise.resolve(true) },
{ name: 'Overzicht', validate: () => Promise.resolve(true) },
{ name: 'Gegevens EPC', 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: true }) },
];

return { steps };
Expand Down Expand Up @@ -119,10 +119,29 @@ export const BlockedWhenStepInvalid: Story = {
},
setup() {
const steps: IStep[] = [
{ name: 'Gegevens EPC', validate: () => Promise.resolve(true) },
{ name: 'Mijn gegevens', validate: () => Promise.resolve(true) },
{ name: 'Bijlagen', validate: () => Promise.resolve(false) },
{ name: 'Overzicht', validate: () => Promise.resolve(false) },
{ name: 'Gegevens EPC', validate: () => Promise.resolve({ valid: true }) },
{ name: 'Mijn gegevens', validate: () => Promise.resolve({ valid: true }) },
{
name: 'Bijlagen',
validate: () =>
Promise.resolve({
valid: false,
error: { id: '1', type: 'error', title: 'Er is een fout opgetreden.', content: 'Fout bij de bijlagen.' },
}),
},
{
name: 'Overzicht',
validate: () =>
Promise.resolve({
valid: false,
error: {
id: '2',
type: 'error',
title: 'Er is een fout opgetreden.',
content: 'Fout bij het overzicht.',
},
}),
},
];

return { steps };
Expand Down Expand Up @@ -157,10 +176,10 @@ export const Mobile: Story = {
},
setup() {
const steps: IStep[] = [
{ name: 'Gegevens EPC', validate: () => Promise.resolve(true) },
{ name: 'Mijn gegevens', validate: () => Promise.resolve(true) },
{ name: 'Bijlagen', validate: () => Promise.resolve(true) },
{ name: 'Overzicht', validate: () => Promise.resolve(true) },
{ name: 'Gegevens EPC', 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: true }) },
];

return { steps };
Expand All @@ -182,10 +201,22 @@ export const SubmitDisabledLastStepInvalid: Story = {
},
setup() {
const steps: IStep[] = [
{ name: 'Gegevens EPC', validate: () => Promise.resolve(true) },
{ name: 'Mijn gegevens', validate: () => Promise.resolve(true) },
{ name: 'Bijlagen', validate: () => Promise.resolve(true) },
{ name: 'Overzicht', validate: () => Promise.resolve(false) },
{ name: 'Gegevens EPC', 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,
error: {
id: '2',
type: 'error',
title: 'Er is een fout opgetreden.',
content: 'Fout bij het overzicht.',
},
}),
},
];

return { steps };
Expand All @@ -207,10 +238,22 @@ export const DisableNextStepButton: Story = {
},
setup() {
const steps: IStep[] = [
{ name: 'Gegevens EPC', validate: () => Promise.resolve(true) },
{ name: 'Mijn gegevens', validate: () => Promise.resolve(true), nextStepDisabled: true },
{ name: 'Bijlagen', validate: () => Promise.resolve(true) },
{ name: 'Overzicht', validate: () => Promise.resolve(false) },
{ name: 'Gegevens EPC', validate: () => Promise.resolve({ valid: true }) },
{ name: 'Mijn gegevens', validate: () => Promise.resolve({ valid: true }), nextStepDisabled: true },
{ name: 'Bijlagen', validate: () => Promise.resolve({ valid: true }) },
{
name: 'Overzicht',
validate: () =>
Promise.resolve({
valid: false,
error: {
id: '2',
type: 'error',
title: 'Er is een fout opgetreden.',
content: 'Fout bij het overzicht.',
},
}),
},
];

return { steps };
Expand Down

0 comments on commit 6d698df

Please sign in to comment.