From 9eee515fd260c57d76abaab22898731e26ae6f98 Mon Sep 17 00:00:00 2001 From: Kasper Peulen Date: Wed, 15 May 2024 14:11:56 +0200 Subject: [PATCH] Expect redirect urls --- app/note/edit/[id]/page.stories.tsx | 6 ++++-- app/note/edit/page.stories.tsx | 2 +- lib/test-utils.ts | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/note/edit/[id]/page.stories.tsx b/app/note/edit/[id]/page.stories.tsx index 24972b1..1f405cc 100644 --- a/app/note/edit/[id]/page.stories.tsx +++ b/app/note/edit/[id]/page.stories.tsx @@ -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({ @@ -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 } }), diff --git a/app/note/edit/page.stories.tsx b/app/note/edit/page.stories.tsx index 020f42b..e6ab1e6 100644 --- a/app/note/edit/page.stories.tsx +++ b/app/note/edit/page.stories.tsx @@ -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({ diff --git a/lib/test-utils.ts b/lib/test-utils.ts index d016212..6a49158 100644 --- a/lib/test-utils.ts +++ b/lib/test-utils.ts @@ -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()), + )