Skip to content

Commit 875733b

Browse files
committed
feat: add storybook stories
1 parent c1259da commit 875733b

File tree

4 files changed

+226
-0
lines changed

4 files changed

+226
-0
lines changed

src/pages/formInline.stories.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import type { Meta, StoryObj } from '@storybook/vue3'
2+
import { expect, userEvent, within } from '@storybook/test'
3+
import FormInline from './formInline.vue'
4+
5+
type Story = StoryObj<typeof FormInline>
6+
7+
const meta: Meta<typeof FormInline> = {
8+
title: 'FormInline',
9+
}
10+
export default meta
11+
12+
export const Default: Story = {
13+
render: () => ({
14+
components: { FormInline },
15+
template: '<FormInline />',
16+
}),
17+
}
18+
19+
export const EmptyForm: Story = {
20+
render: () => ({
21+
components: { FormInline },
22+
template: '<FormInline />',
23+
}),
24+
play: async ({ canvasElement }) => {
25+
// Arrange
26+
const canvas = within(canvasElement)
27+
28+
// Act
29+
await userEvent.type(canvas.getByPlaceholderText('email'), '{tab}')
30+
await userEvent.type(canvas.getByPlaceholderText('password'), '{tab}')
31+
32+
// Assert
33+
expect(await canvas.findByText('emailは必須項目です')).toBeInTheDocument()
34+
expect(await canvas.findByText('passwordは必須項目です')).toBeInTheDocument()
35+
const isDisabled = (await canvas.findByRole('button') as HTMLButtonElement).disabled
36+
expect(isDisabled).toBe(true)
37+
},
38+
}
39+
40+
export const InvalidEmailForm: Story = {
41+
render: () => ({
42+
components: { FormInline },
43+
template: '<FormInline />',
44+
}),
45+
play: async ({ canvasElement }) => {
46+
// Arrange
47+
const canvas = within(canvasElement)
48+
49+
// Act
50+
await userEvent.type(canvas.getByPlaceholderText('email'), 'test{tab}')
51+
52+
// Assert
53+
expect(await canvas.findByText('emailは有効なメールアドレスではありません')).toBeInTheDocument()
54+
const isDisabled = (await canvas.findByRole('button') as HTMLButtonElement).disabled
55+
expect(isDisabled).toBe(true)
56+
},
57+
}
58+
59+
export const FullForm: Story = {
60+
render: () => ({
61+
components: { FormInline },
62+
template: '<FormInline />',
63+
}),
64+
play: async ({ canvasElement }) => {
65+
// Arrange
66+
const canvas = within(canvasElement)
67+
68+
// Act
69+
await userEvent.type(canvas.getByPlaceholderText('email'), 'test@test.com')
70+
await userEvent.type(canvas.getByPlaceholderText('password'), 'test')
71+
72+
// Assert
73+
const isDisabled = (await canvas.findByRole('button') as HTMLButtonElement).disabled
74+
expect(isDisabled).toBe(false)
75+
},
76+
}

src/pages/formScript.stories.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import type { Meta, StoryObj } from '@storybook/vue3'
2+
import { expect, userEvent, waitFor, within } from '@storybook/test'
3+
import FormScript from './formScript.vue'
4+
5+
type Story = StoryObj<typeof FormScript>
6+
7+
const meta: Meta<typeof FormScript> = {
8+
title: 'FormScript',
9+
}
10+
export default meta
11+
12+
export const Default: Story = {
13+
render: () => ({
14+
components: { FormScript },
15+
template: '<FormScript />',
16+
}),
17+
}
18+
19+
export const EmptyForm: Story = {
20+
render: () => ({
21+
components: { FormScript },
22+
template: '<FormScript />',
23+
}),
24+
play: async ({ canvasElement }) => {
25+
// Arrange
26+
const canvas = within(canvasElement)
27+
const email = canvas.getByPlaceholderText('email')
28+
const password = canvas.getByPlaceholderText('password')
29+
30+
// Act
31+
await userEvent.type(email, 'test')
32+
await userEvent.clear(email)
33+
await userEvent.type(password, 'test')
34+
await userEvent.clear(password)
35+
36+
// Assert
37+
expect(await canvas.findByText('emailは必須項目です')).toBeInTheDocument()
38+
expect(await canvas.findByText('passwordは必須項目です')).toBeInTheDocument()
39+
const isDisabled = (await canvas.findByRole('button') as HTMLButtonElement).disabled
40+
expect(isDisabled).toBe(true)
41+
},
42+
}
43+
44+
export const InvalidEmailForm: Story = {
45+
render: () => ({
46+
components: { FormScript },
47+
template: '<FormScript />',
48+
}),
49+
play: async ({ canvasElement }) => {
50+
// Arrange
51+
const canvas = within(canvasElement)
52+
53+
// Act
54+
await userEvent.type(canvas.getByPlaceholderText('email'), 'test')
55+
56+
// Assert
57+
expect(await canvas.findByText('emailは有効なメールアドレスではありません')).toBeInTheDocument()
58+
const isDisabled = (await canvas.findByRole('button') as HTMLButtonElement).disabled
59+
expect(isDisabled).toBe(true)
60+
},
61+
}
62+
63+
export const FullForm: Story = {
64+
render: () => ({
65+
components: { FormScript },
66+
template: '<FormScript />',
67+
}),
68+
play: async ({ canvasElement }) => {
69+
// Arrange
70+
const canvas = within(canvasElement)
71+
72+
// Act
73+
await userEvent.type(canvas.getByPlaceholderText('email'), 'test@test.com')
74+
await userEvent.type(canvas.getByPlaceholderText('password'), 'test')
75+
76+
await waitFor(async () => {
77+
// Assert
78+
const isDisabled = (await canvas.findByRole('button') as HTMLButtonElement).disabled
79+
expect(isDisabled).toBe(false)
80+
})
81+
},
82+
}

src/pages/index.stories.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import type { Meta, StoryObj } from '@storybook/vue3'
2+
import { http, HttpResponse } from 'msw'
3+
import { within, userEvent, expect } from '@storybook/test'
4+
import Index from './index.vue'
5+
6+
type Story = StoryObj<typeof Index>
7+
8+
const meta: Meta<typeof Index> = {
9+
title: 'Index',
10+
}
11+
export default meta
12+
13+
export const Default: Story = {
14+
render: () => ({
15+
components: { Index },
16+
template: '<Index />',
17+
}),
18+
}
19+
20+
export const GetUuid: Story = {
21+
render: () => ({
22+
components: { Index },
23+
template: '<Index />',
24+
}),
25+
parameters: {
26+
msw: {
27+
handlers: [
28+
http.get('https://httpbin.org/uuid', () => {
29+
return HttpResponse.json({
30+
uuid: 'test uuid',
31+
})
32+
}),
33+
],
34+
},
35+
},
36+
play: async ({ canvasElement }) => {
37+
// Arrange
38+
const canvas = within(canvasElement)
39+
40+
// Act
41+
await userEvent.click(await canvas.findByText('Get uuid'))
42+
43+
// Assert
44+
await expect(await canvas.findByText('UUID = test uuid')).toBeInTheDocument()
45+
},
46+
}

src/pages/myPage.stories.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { Meta, StoryObj } from '@storybook/vue3'
2+
import MyPage from './myPage.vue'
3+
import { useUserStore } from '~/store/user'
4+
5+
type Story = StoryObj<typeof MyPage>
6+
7+
const meta: Meta<typeof MyPage> = {
8+
title: 'MyPage',
9+
}
10+
export default meta
11+
12+
export const Default: Story = {
13+
render: () => ({
14+
setup() {
15+
const store = useUserStore()
16+
store.user.email = 'foo@bar.com'
17+
store.user.password = 'foobar'
18+
},
19+
components: { MyPage },
20+
template: '<MyPage />',
21+
}),
22+
}

0 commit comments

Comments
 (0)