-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIconButton.test.stories.tsx
More file actions
60 lines (48 loc) · 1.54 KB
/
IconButton.test.stories.tsx
File metadata and controls
60 lines (48 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import type { Meta, StoryObj } from '@storybook/react';
import { expect, fn, userEvent, within } from 'storybook/test';
import IconButton from './IconButton';
const meta: Meta<typeof IconButton> = {
component: IconButton,
parameters: {
layout: 'centered',
},
tags: ['!dev'],
args: {
type: 'primary',
icon: 'edit',
onClick: fn(),
},
};
export default meta;
type Story = StoryObj<typeof IconButton>;
export const TestEnabled: Story = {
name: 'Enabled',
args: {
disabled: false,
},
play: async ({ canvasElement, step, args }) => {
const canvas = within(canvasElement);
await step('Button is clickable', async () => {
const btn = canvas.getByRole('button');
await expect(btn).not.toHaveClass('ids-btn--disabled');
await expect(btn).toHaveAttribute('aria-disabled', 'false');
await userEvent.click(btn);
await expect(args.onClick).toHaveBeenCalledOnce();
});
},
};
export const TestDisabled: Story = {
name: 'Disabled',
args: {
disabled: true,
},
play: async ({ canvasElement, step }) => {
const canvas = within(canvasElement);
await step('Button is not clickable', async () => {
const btn = canvas.getByRole('button');
await expect(btn).toHaveClass('ids-btn--disabled');
await expect(btn).toHaveAttribute('aria-disabled', 'true');
await expect(btn).toHaveStyle({ pointerEvents: 'none' });
});
},
};