-
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.
Merge pull request #57 from open-formulieren/feature/56-radio-compone…
…nt-edit-form Implement radio component edit form
- Loading branch information
Showing
12 changed files
with
786 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,87 @@ | ||
import {expect} from '@storybook/jest'; | ||
import {Meta, StoryObj} from '@storybook/react'; | ||
import {within} from '@storybook/testing-library'; | ||
|
||
import {withFormik} from '@/sb-decorators'; | ||
|
||
import Radio from './radio'; | ||
|
||
export default { | ||
title: 'Formio/Components/Radio', | ||
component: Radio, | ||
decorators: [withFormik], | ||
parameters: { | ||
modal: {noModal: true}, | ||
formik: {initialValues: {'my-radio': ''}}, | ||
}, | ||
args: { | ||
name: 'my-radio', | ||
label: '', | ||
tooltip: '', | ||
options: [ | ||
{value: 'a', label: 'A'}, | ||
{value: 'b', label: 'B'}, | ||
], | ||
}, | ||
} as Meta<typeof Radio>; | ||
|
||
type Story = StoryObj<typeof Radio>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
label: 'Labeled radio', | ||
}, | ||
}; | ||
|
||
export const WithInitialChecked: Story = { | ||
parameters: { | ||
formik: { | ||
initialValues: { | ||
'my-radio': 'b', | ||
}, | ||
}, | ||
}, | ||
args: { | ||
label: 'Labeled radio', | ||
}, | ||
|
||
play: async ({canvasElement}) => { | ||
const canvas = within(canvasElement); | ||
|
||
await expect(canvas.getByLabelText('A')).not.toBeChecked(); | ||
await expect(canvas.getByLabelText('B')).toBeChecked(); | ||
}, | ||
}; | ||
|
||
export const WithToolTip: Story = { | ||
args: { | ||
label: 'With tooltip', | ||
tooltip: 'Hiya!', | ||
}, | ||
}; | ||
|
||
export const WithDescription: Story = { | ||
args: { | ||
label: 'With description', | ||
description: 'A description', | ||
}, | ||
}; | ||
|
||
export const WithErrors: Story = { | ||
args: { | ||
label: 'With errors', | ||
}, | ||
|
||
parameters: { | ||
formik: { | ||
initialValues: {'my-radio': ''}, | ||
initialErrors: {'my-radio': 'Example error', 'other-field': 'Other error'}, | ||
}, | ||
}, | ||
|
||
play: async ({canvasElement}) => { | ||
const canvas = within(canvasElement); | ||
await expect(canvas.queryByText('Other error')).not.toBeInTheDocument(); | ||
await expect(canvas.queryByText('Example error')).toBeInTheDocument(); | ||
}, | ||
}; |
Oops, something went wrong.