Skip to content

Commit eff116d

Browse files
committed
add story: input
1 parent 6b92fa4 commit eff116d

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import type { Meta, StoryObj } from '@nuxtjs/storybook'
2+
import { expect, fn, userEvent, within } from '@storybook/test'
3+
import Component from './Base.vue'
4+
5+
const meta = {
6+
component: Component,
7+
8+
argTypes: {
9+
disabled: { control: 'boolean' },
10+
size: {
11+
control: 'select',
12+
options: ['small', 'medium', 'large'],
13+
},
14+
noCorrect: {
15+
control: 'boolean',
16+
description: 'Whether to disable browser autocorrect',
17+
},
18+
onFocus: {
19+
action: 'focus',
20+
description: 'Fired when the input gains focus',
21+
},
22+
onBlur: {
23+
action: 'blur',
24+
description: 'Fired when the input loses focus',
25+
},
26+
},
27+
} satisfies Meta<typeof Component>
28+
29+
export default meta
30+
type Story = StoryObj<typeof meta>
31+
32+
export const Snapshot: Story = {
33+
render: () => ({
34+
template: `
35+
<div style="display: flex; flex-direction: column; gap: 1rem; padding: 1rem;">
36+
<Component size="small" model-value="Small input" />
37+
<Component size="medium" model-value="Medium input" />
38+
<Component size="large" model-value="Large input" />
39+
<Component size="large" model-value="disabled" disabled />
40+
</div>
41+
`,
42+
components: { Component },
43+
}),
44+
}
45+
46+
export const Event: Story = {
47+
args: {
48+
onFocus: fn(),
49+
onBlur: fn(),
50+
},
51+
play: async ({ args, canvasElement }) => {
52+
const canvas = within(canvasElement)
53+
const input = canvas.getByRole('textbox')
54+
55+
await userEvent.click(input)
56+
await expect(args.onFocus).toHaveBeenCalled()
57+
58+
await userEvent.tab()
59+
await expect(args.onBlur).toHaveBeenCalled()
60+
},
61+
}
62+
63+
export const Disable: Story = {
64+
args: { disabled: true },
65+
play: async ({ args, canvasElement }) => {
66+
const canvas = within(canvasElement)
67+
const input = canvas.getByRole('textbox')
68+
69+
await expect(input).toBeDisabled()
70+
await userEvent.click(input)
71+
await expect(args.onFocus).not.toHaveBeenCalled()
72+
},
73+
}
74+
75+
export const NoCorrect: Story = {
76+
args: {
77+
noCorrect: true,
78+
},
79+
play: async ({ canvasElement }) => {
80+
const canvas = within(canvasElement)
81+
const input = canvas.getByRole('textbox')
82+
83+
await expect(input).toHaveAttribute('autocapitalize', 'off')
84+
await expect(input).toHaveAttribute('autocorrect', 'off')
85+
await expect(input).toHaveAttribute('autocomplete', 'off')
86+
await expect(input).toHaveAttribute('spellcheck', 'false')
87+
},
88+
}

0 commit comments

Comments
 (0)