-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ [open-formulieren/open-forms#5016] Stories for referentielijsten op…
…tions
- Loading branch information
Showing
9 changed files
with
641 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
import {Meta, StoryObj} from '@storybook/react'; | ||
import {expect, fn, userEvent, within} from '@storybook/test'; | ||
|
||
import ComponentEditForm from '@/components/ComponentEditForm'; | ||
import {BuilderContextDecorator} from '@/sb-decorators'; | ||
import {rsSelect} from '@/utils/storybookTestHelpers'; | ||
|
||
export default { | ||
title: 'Builder components/Radio/Referentielijsten', | ||
component: ComponentEditForm, | ||
decorators: [BuilderContextDecorator], | ||
parameters: { | ||
builder: {enableContext: true}, | ||
}, | ||
args: { | ||
isNew: true, | ||
component: { | ||
id: 'wqimsadk', | ||
type: 'radio', | ||
key: 'radio', | ||
label: 'A radio field', | ||
dataSrc: 'values', | ||
dataType: 'string', | ||
openForms: { | ||
dataSrc: 'manual', | ||
translations: {}, | ||
}, | ||
data: {values: [{value: '', label: ''}]}, | ||
values: [{value: '', label: ''}], | ||
defaultValue: '', | ||
}, | ||
onCancel: fn(), | ||
onRemove: fn(), | ||
onSubmit: fn(), | ||
builderInfo: { | ||
title: 'Select', | ||
icon: 'plus-square', | ||
group: 'basic', | ||
weight: 60, | ||
schema: {}, | ||
}, | ||
}, | ||
} as Meta<typeof ComponentEditForm>; | ||
|
||
type Story = StoryObj<typeof ComponentEditForm>; | ||
|
||
export const StoreValuesInComponent: Story = { | ||
name: 'On save: store proper values in the component', | ||
play: async ({canvasElement, step, args}) => { | ||
const canvas = within(canvasElement); | ||
|
||
await step('Fill in options', async () => { | ||
const dataSourceInput = canvas.getByLabelText('Data source'); | ||
await rsSelect(dataSourceInput, 'Referentielijsten API'); | ||
|
||
const serviceInput = canvas.getByLabelText('Referentielijsten service'); | ||
await rsSelect(serviceInput, 'Referentielijsten'); | ||
|
||
const codeInput = canvas.getByLabelText('Referentielijsten table code'); | ||
await userEvent.type(codeInput, 'tabel1'); | ||
|
||
await userEvent.click(canvas.getByRole('button', {name: 'Save'})); | ||
|
||
expect(args.onSubmit).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
openForms: { | ||
code: 'tabel1', | ||
dataSrc: 'referentielijsten', | ||
service: 'referentielijsten', | ||
translations: {}, | ||
}, | ||
type: 'radio', | ||
}) | ||
); | ||
}); | ||
}, | ||
}; | ||
|
||
export const SwitchToVariableResetOptions: Story = { | ||
name: 'On switch from referentielijsten to variable: reset the options', | ||
play: async ({canvasElement, step, args}) => { | ||
const canvas = within(canvasElement); | ||
|
||
await step('Fill in options', async () => { | ||
const dataSourceInput = canvas.getByLabelText('Data source'); | ||
await rsSelect(dataSourceInput, 'Referentielijsten API'); | ||
|
||
const serviceInput = canvas.getByLabelText('Referentielijsten service'); | ||
await rsSelect(serviceInput, 'Referentielijsten'); | ||
|
||
const codeInput = canvas.getByLabelText('Referentielijsten table code'); | ||
await userEvent.type(codeInput, 'tabel1'); | ||
|
||
await rsSelect(dataSourceInput, 'From variable'); | ||
|
||
const itemsExpressionInput = canvas.getByTestId('jsonEdit'); | ||
await userEvent.clear(itemsExpressionInput); | ||
await userEvent.type(itemsExpressionInput, '"foo"'); | ||
|
||
await userEvent.click(canvas.getByRole('button', {name: 'Save'})); | ||
|
||
expect(args.onSubmit).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
openForms: { | ||
dataSrc: 'variable', | ||
itemsExpression: 'foo', | ||
translations: {}, | ||
}, | ||
type: 'radio', | ||
}) | ||
); | ||
}); | ||
}, | ||
}; | ||
|
||
export const SwitchToManualResetOptions: Story = { | ||
name: 'On switch from referentielijsten to manual: reset the options', | ||
play: async ({canvasElement, step, args}) => { | ||
const canvas = within(canvasElement); | ||
|
||
await step('Fill in options', async () => { | ||
const dataSourceInput = canvas.getByLabelText('Data source'); | ||
await rsSelect(dataSourceInput, 'Referentielijsten API'); | ||
|
||
const serviceInput = canvas.getByLabelText('Referentielijsten service'); | ||
await rsSelect(serviceInput, 'Referentielijsten'); | ||
|
||
const codeInput = canvas.getByLabelText('Referentielijsten table code'); | ||
await userEvent.type(codeInput, 'tabel1'); | ||
|
||
await rsSelect(dataSourceInput, 'Manually fill in'); | ||
|
||
const labelInput = canvas.getByTestId('input-values[0].label'); | ||
await userEvent.type(labelInput, 'Foo'); | ||
|
||
await userEvent.click(canvas.getByRole('button', {name: 'Save'})); | ||
|
||
expect(args.onSubmit).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
openForms: { | ||
dataSrc: 'manual', | ||
translations: {}, | ||
}, | ||
type: 'radio', | ||
values: [ | ||
{ | ||
label: 'Foo', | ||
value: 'foo', | ||
openForms: { | ||
translations: {}, | ||
}, | ||
}, | ||
], | ||
}) | ||
); | ||
}); | ||
}, | ||
}; |
Oops, something went wrong.