import React from 'react' import { type Meta, type StoryObj } from '@storybook/react' import { expect, fn, userEvent, waitFor, within } from '@storybook/test' import { Icon } from '~components/Icon' import { VisuallyHidden } from '~components/VisuallyHidden' import { Button } from '../index' const onPressEvent = fn() const meta = { title: 'Components/Button/Button tests', component: Button, args: { children: 'Label', onPress: onPressEvent, }, } satisfies Meta export default meta type Story = StoryObj // stress testing the accessible name being derived from the nested children export const IconButtonWithHiddenLabel: Story = { args: { hasHiddenLabel: true, icon: , children: ( Hidden label is accessible ), }, play: async ({ canvasElement }) => { const canvas = within(canvasElement.parentElement!) const button = canvas.getByRole('button') expect(button).toHaveAccessibleName('Hidden label is accessible') }, } export const PendingButton: Story = { render: ({ isPending = false, pendingLabel = 'Loading', ...otherProps }) => { const [isPendingStatus, setIsPendingStatus] = React.useState(isPending) return ( ), play: async ({ canvasElement, step }) => { const canvas = within(canvasElement.parentElement!) const button = canvas.getByRole('button') await step('button icon reflects unfocused state', async () => { await waitFor(() => expect(button).toHaveAccessibleName('Label is unfocused')) }) await step('focus on button and update icon', async () => { await userEvent.tab() await waitFor(() => expect(button).toHaveAccessibleName('Label is focused')) }) }, } export const RACRenderPropsWithClassName: Story = { args: { className: ({ isFocusVisible }) => (isFocusVisible ? '!bg-gray-300' : ''), }, play: async ({ canvasElement }) => { const canvas = within(canvasElement.parentElement!) const button = canvas.getByRole('button') await button.focus() }, }