Skip to content

Commit

Permalink
Expect redirect urls
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperpeulen committed May 15, 2024
1 parent ec7bdc9 commit 9eee515
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions app/note/edit/[id]/page.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ export const SavingExistingNoteShouldUpdateDBAndRedirect: Story = {
await userEvent.click(
await canvas.findByRole('menuitem', { name: /done/i }),
)
await expectRedirect()

await expectRedirect('/note/2')

await expect(await db.note.findUnique({ where: { id: 2 } })).toEqual(
expect.objectContaining({
Expand All @@ -90,7 +91,8 @@ export const DeleteNoteRemovesFromDBAndSidebar: Story = {
await userEvent.click(
await canvas.findByRole('menuitem', { name: /delete/i }),
)
await expectRedirect()

await expectRedirect('/')

await expect(
await db.note.findMany({ where: { id: 2 } }),
Expand Down
2 changes: 1 addition & 1 deletion app/note/edit/page.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const SaveNewNote: Story = {
await canvas.findByRole('menuitem', { name: /done/i }),
)

await expectRedirect()
await expectRedirect('/note/3')

await expect(await db.note.findUnique({ where: { id: 3 } })).toEqual(
expect.objectContaining({
Expand Down
6 changes: 4 additions & 2 deletions lib/test-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { expect, waitFor } from '@storybook/test'
import { getRouter } from '@storybook/nextjs/navigation.mock'

export const expectRedirect = () =>
waitFor(() => expect(getRouter().push).toHaveBeenCalled())
export const expectRedirect = (url: string) =>
waitFor(() =>
expect(getRouter().push).toHaveBeenLastCalledWith(url, expect.anything()),
)

0 comments on commit 9eee515

Please sign in to comment.