-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAltRadio.test.stories.tsx
More file actions
50 lines (39 loc) · 1.38 KB
/
AltRadio.test.stories.tsx
File metadata and controls
50 lines (39 loc) · 1.38 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
import type { Meta, StoryObj } from '@storybook/react';
import { expect, fn, userEvent, within } from 'storybook/test';
import { AltRadioStateful } from './AltRadio';
const meta: Meta<typeof AltRadioStateful> = {
component: AltRadioStateful,
parameters: {
layout: 'centered',
},
tags: ['!dev'],
args: {
label: '1:1',
name: 'default-input',
onBlur: fn(),
onChange: fn(),
onFocus: fn(),
onInput: fn(),
},
};
export default meta;
type Story = StoryObj<typeof AltRadioStateful>;
export const Default: Story = {
name: 'Default',
play: async ({ canvasElement, step, args }) => {
const canvas = within(canvasElement);
const input = canvas.getByRole('button');
await step('Radio Button handles focus event', async () => {
await expect(args.onFocus).not.toHaveBeenCalled();
await userEvent.click(input);
await expect(args.onFocus).toHaveBeenCalledOnce();
await expect(args.onChange).toHaveBeenCalledOnce();
await expect(args.onInput).toHaveBeenCalledOnce();
});
await step('Radio Button handles blur event', async () => {
await expect(args.onBlur).not.toHaveBeenCalled();
await userEvent.click(canvasElement);
await expect(args.onBlur).toHaveBeenCalledOnce();
});
},
};