-
Notifications
You must be signed in to change notification settings - Fork 3
/
page.stories.tsx
72 lines (64 loc) · 1.95 KB
/
page.stories.tsx
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
61
62
63
64
65
66
67
68
69
70
71
72
import { expect, userEvent, within } from '@storybook/test'
import { type Meta, type StoryObj } from '@storybook/react'
import { cookies } from '@storybook/nextjs/headers.mock'
import Page from './page'
import { db } from '#lib/db'
import { createUserCookie, userCookieKey } from '#lib/session'
import { PageDecorator } from '#.storybook/decorators'
import { expectRedirect } from '#lib/test-utils'
const meta = {
component: Page,
parameters: {
layout: 'fullscreen',
nextjs: {
navigation: {
pathname: '/note/edit',
},
},
},
decorators: [PageDecorator],
async beforeEach() {
cookies().set(userCookieKey, await createUserCookie('storybookjs'))
await db.note.create({
data: {
title: 'Module mocking in Storybook?',
body: "Yup, that's a thing now! 🎉",
createdBy: 'storybookjs',
},
})
await db.note.create({
data: {
title: 'RSC support as well??',
body: 'RSC is pretty cool, even cooler that Storybook supports it!',
createdBy: 'storybookjs',
},
})
},
} satisfies Meta<typeof Page>
export default meta
type Story = StoryObj<typeof meta>
export const EditNewNote: Story = {}
export const SaveNewNote: Story = {
play: async ({ canvasElement, step }) => {
const canvas = within(canvasElement)
const titleInput = await canvas.findByLabelText(
'Enter a title for your note',
)
const bodyInput = await canvas.findByLabelText(
'Enter the body for your note',
)
await userEvent.clear(titleInput)
await userEvent.type(titleInput, 'New Note Title')
await userEvent.type(bodyInput, 'New Note Body')
await userEvent.click(
await canvas.findByRole('menuitem', { name: /done/i }),
)
await expectRedirect('/note/3')
await expect(await db.note.findUnique({ where: { id: 3 } })).toEqual(
expect.objectContaining({
title: 'New Note Title',
body: 'New Note Body',
}),
)
},
}