diff --git a/code/ui/blocks/src/controls/Boolean.stories.tsx b/code/ui/blocks/src/controls/Boolean.stories.tsx index 001a13dcaef7..54344b5850d4 100644 --- a/code/ui/blocks/src/controls/Boolean.stories.tsx +++ b/code/ui/blocks/src/controls/Boolean.stories.tsx @@ -1,6 +1,6 @@ import { expect } from '@storybook/jest'; import type { Meta, StoryObj } from '@storybook/react'; -import { within, fireEvent } from '@storybook/testing-library'; +import { within, fireEvent, waitFor } from '@storybook/testing-library'; import { addons } from '@storybook/preview-api'; import { RESET_STORY_ARGS, STORY_ARGS_UPDATED } from '@storybook/core-events'; import { BooleanControl } from './Boolean'; @@ -15,7 +15,6 @@ const meta = { info: 'This is info for the Boolean control stories', jsx: { useBooleanShorthandSyntax: false }, }, - args: { name: 'boolean' }, } as Meta; export default meta; @@ -23,25 +22,29 @@ export default meta; export const True: StoryObj = { args: { value: true, + name: 'True', }, }; export const False: StoryObj = { args: { value: false, + name: 'False', }, }; export const Undefined: StoryObj = { args: { value: undefined, + name: 'Undefined', }, }; export const Toggling: StoryObj = { args: { value: undefined, + name: 'Toggling', }, - play: async ({ canvasElement, id }) => { + play: async ({ canvasElement, id, args, step }) => { const channel = addons.getChannel(); channel.emit(RESET_STORY_ARGS, { storyId: id }); @@ -50,28 +53,37 @@ export const Toggling: StoryObj = { }); const canvas = within(canvasElement); + await step('Change from Undefined to False', async () => { + const setBooleanControl = canvas.getByText('Set boolean'); + await fireEvent.click(setBooleanControl); - // from Undefined to False - const setBooleanControl = canvas.getByText('Set boolean'); - await fireEvent.click(setBooleanControl); - - let toggle = await canvas.findByTitle('Change to true'); - expect(toggle).toBeInTheDocument(); + const toggle = await canvas.findByLabelText(args.name); + await expect(toggle).toBeVisible(); + }); - // from False to True - await fireEvent.click(toggle); - toggle = await canvas.findByTitle('Change to false'); - expect(toggle).toBeInTheDocument(); + await step('Change from False to True', async () => { + const toggle = canvas.getByRole('switch'); + await fireEvent.click(toggle); + await waitFor(async () => { + await expect(toggle).toBeChecked(); + }); + }); - // from True to False - await fireEvent.click(toggle); - toggle = await canvas.findByTitle('Change to true'); - expect(toggle).toBeInTheDocument(); + await step('Change from True to False', async () => { + const toggle = canvas.getByRole('switch'); + await fireEvent.click(toggle); + await waitFor(async () => { + await expect(toggle).not.toBeChecked(); + }); + }); }, }; export const TogglingInDocs: StoryObj = { ...Toggling, + args: { + name: 'Toggling In Docs', + }, parameters: { docs: { autoplay: true, diff --git a/code/ui/blocks/src/controls/Boolean.tsx b/code/ui/blocks/src/controls/Boolean.tsx index 9d591d1a9c75..54b71b0b30b8 100644 --- a/code/ui/blocks/src/controls/Boolean.tsx +++ b/code/ui/blocks/src/controls/Boolean.tsx @@ -112,16 +112,17 @@ export const BooleanControl: FC = ({ name, value, onChange, onBlur const parsedValue = typeof value === 'string' ? parse(value) : value; return ( -