From f3f74d7e314029620d7db81748a1435bc7848f28 Mon Sep 17 00:00:00 2001 From: Steven Bal Date: Mon, 11 Nov 2024 11:53:14 +0100 Subject: [PATCH] :white_check_mark: [open-formulieren/open-forms#4772] Add story for select component int values --- src/formio/components/Select.stories.js | 55 +++++++++++++++++++++++++ src/formio/components/story-util.js | 12 +++++- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/formio/components/Select.stories.js b/src/formio/components/Select.stories.js index 507c0e235..b5f867b36 100644 --- a/src/formio/components/Select.stories.js +++ b/src/formio/components/Select.stories.js @@ -1,3 +1,4 @@ +import {expect, jest} from '@storybook/jest'; import {userEvent, within} from '@storybook/test'; import {withUtrechtDocument} from 'story-utils/decorators'; @@ -131,3 +132,57 @@ export const MultilineOptions = { }, }, }; + +export const WithIntegerValues = { + render: MultipleFormioComponents, + args: { + onSubmit: jest.fn(), + components: [ + { + type: 'select', + key: 'selectWithInt', + label: 'Select with integer values', + data: { + values: [ + { + label: 'Optie 1', + value: '1', + }, + { + label: 'Optie 2', + value: '2', + }, + ], + }, + validate: { + required: true, + }, + }, + { + label: 'Submit', + showValidations: true, + key: 'submit1', + type: 'button', + input: false, + action: 'submit', + }, + ], + }, + + play: async ({canvasElement, args}) => { + args.onSubmit.mockClear(); + + const canvas = within(canvasElement); + const select = await canvas.findByLabelText('Select with integer values'); + await userEvent.click(select); + + const option = await canvas.findByText('Optie 1'); + await userEvent.click(option); + + await userEvent.click(canvas.getByText('Submit')); + + expect(args.onSubmit).toHaveBeenCalledTimes(1); + const submittedData = args.onSubmit.mock.calls[0][0]; + expect(submittedData.data).toEqual({selectWithInt: '1'}); + }, +}; diff --git a/src/formio/components/story-util.js b/src/formio/components/story-util.js index 365034d0e..c0e543bd1 100644 --- a/src/formio/components/story-util.js +++ b/src/formio/components/story-util.js @@ -11,6 +11,7 @@ const RenderFormioForm = ({ submissionData = {}, evalContext = {}, ofContext = {}, + onSubmit = () => {}, }) => { const config = useContext(ConfigContext); const formioTranslations = useContext(FormioTranslations); @@ -20,6 +21,7 @@ const RenderFormioForm = ({
{}, }) => { // in case this is used as a react component, allow using an alias, because React // reserves the key 'prop' @@ -61,14 +64,21 @@ export const SingleFormioComponent = ({ submissionData={submissionData} evalContext={evalContext} ofContext={ofContext} + onSubmit={onSubmit} /> ); }; -export const MultipleFormioComponents = ({components, evalContext = {}, ofContext = {}}) => ( +export const MultipleFormioComponents = ({ + components, + evalContext = {}, + ofContext = {}, + onSubmit = () => {}, +}) => ( );