import React from 'react' import { type Meta, type StoryObj } from '@storybook/react' import { expect, userEvent, waitFor, within } from '@storybook/test' import { Icon } from '~components/Icon' import { VisuallyHidden } from '~components/VisuallyHidden' import { LinkButton } from '../index' const meta = { title: 'Components/LinkButton/LinkButton tests', component: LinkButton, args: { children: 'Label', }, } satisfies Meta export default meta type Story = StoryObj export const IconLinkButtonWithHiddenLabel: Story = { args: { hasHiddenLabel: true, icon: , children: ( Hidden label is accessible ), }, play: async ({ canvasElement }) => { const canvas = within(canvasElement.parentElement!) const linkButton = canvas.getByRole('link') expect(linkButton).toHaveAccessibleName('Hidden label is accessible') }, } export const RACRenderPropsWithChildren: Story = { render: ({ children: _, ...otherArgs }) => ( {({ isFocusVisible }) => ( <> Label {isFocusVisible ? ' is focused' : ' is unfocused'} )} ), play: async ({ canvasElement, step }) => { const canvas = within(canvasElement.parentElement!) const linkButton = canvas.getByRole('link') await step('link icon reflects unfocused state', async () => { await waitFor(() => expect(linkButton).toHaveAccessibleName('Label is unfocused')) }) await step('focus on link and update icon', async () => { await userEvent.tab() await waitFor(() => expect(linkButton).toHaveAccessibleName('Label is focused')) }) }, } export const RACRenderPropsWithClassName: Story = { args: { className: ({ isFocusVisible }) => (isFocusVisible ? '!bg-gray-300' : ''), }, play: async ({ canvasElement }) => { const canvas = within(canvasElement.parentElement!) const linkButton = canvas.getByRole('link') await linkButton.focus() expect(linkButton).toHaveClass('!bg-gray-300') }, }