import type { Meta, StoryObj } from '@storybook/react-vite'; import { fn, expect, userEvent, within } from 'storybook/test'; import { Button } from './Button'; const meta = { title: 'Atoms/Button', component: Button, tags: ['autodocs'], args: { onClick: fn() }, argTypes: { variant: { control: 'select', options: ['primary', 'secondary', 'danger', 'ghost', 'icon'], }, size: { control: 'select', options: ['sm', 'md', 'lg'], }, }, } satisfies Meta; export default meta; type Story = StoryObj; export const Primary: Story = { args: { variant: 'primary', children: 'Primary Button' }, }; export const Secondary: Story = { args: { variant: 'secondary', children: 'Secondary Button' }, }; export const Danger: Story = { args: { variant: 'danger', children: 'Danger Button' }, }; export const Ghost: Story = { args: { variant: 'ghost', children: 'Ghost Button' }, }; export const Icon: Story = { args: { variant: 'icon', children: ( ), 'aria-label': 'Add to cart', }, }; export const Small: Story = { args: { variant: 'primary', size: 'sm', children: 'Small Button' }, }; export const Large: Story = { args: { variant: 'primary', size: 'lg', children: 'Large Button' }, }; export const WithLeftIcon: Story = { args: { variant: 'secondary', children: 'Add to Cart', leftIcon: ( ), }, }; export const Disabled: Story = { args: { variant: 'primary', children: 'Disabled', disabled: true }, }; export const ClickTest: Story = { args: { variant: 'primary', children: 'Click me' }, play: async ({ canvasElement, args }) => { const canvas = within(canvasElement); const button = canvas.getByRole('button'); await userEvent.click(button); await expect(args.onClick).toHaveBeenCalled(); }, };