diff --git a/apps/studio/src/stories/Page/SitePage.stories.tsx b/apps/studio/src/stories/Page/SitePage.stories.tsx index 7006661e48..eb143ac41e 100644 --- a/apps/studio/src/stories/Page/SitePage.stories.tsx +++ b/apps/studio/src/stories/Page/SitePage.stories.tsx @@ -1,5 +1,6 @@ import type { Meta, StoryObj } from "@storybook/react" import { meHandlers } from "tests/msw/handlers/me" +import { pageHandlers } from "tests/msw/handlers/page" import SitePage from "~/pages/sites/[siteId]" @@ -9,7 +10,7 @@ const meta: Meta = { parameters: { getLayout: SitePage.getLayout, msw: { - handlers: [meHandlers.me()], + handlers: [meHandlers.me(), pageHandlers.list.default()], }, }, decorators: [], diff --git a/apps/studio/tests/msw/handlers/page.ts b/apps/studio/tests/msw/handlers/page.ts new file mode 100644 index 0000000000..fdecd68abe --- /dev/null +++ b/apps/studio/tests/msw/handlers/page.ts @@ -0,0 +1,138 @@ +import type { DelayMode } from "msw" +import { delay } from "msw" + +import { trpcMsw } from "../mockTrpc" + +const pageListQuery = (wait?: DelayMode | number) => { + return trpcMsw.page.list.query(async () => { + if (wait !== undefined) { + await delay(wait) + } + return [ + { + id: "0001", + name: "Test Page 1", + permalink: "/", + type: "page", + status: "draft", + lastEditUser: "user1@test.com", + lastEditDate: new Date("2024-07-15T09:16:46.640Z"), + }, + { + id: "0002", + name: "Test Page 2", + permalink: "/testpage2", + type: "page", + status: "published", + lastEditUser: "user2@test.com", + lastEditDate: new Date("2024-06-15T09:16:46.640Z"), + }, + { + id: "0003", + name: "Test Folder 1", + permalink: "/testfolder1", + type: "folder", + status: "folder", + lastEditUser: "folder", + lastEditDate: "folder", + }, + { + id: "0004", + name: "Test Folder 2", + permalink: "/testfolder2", + type: "folder", + status: "folder", + lastEditUser: "folder", + lastEditDate: "folder", + }, + { + id: "0005", + name: "Test Page 5", + permalink: "/", + type: "page", + status: "draft", + lastEditUser: "user1@test.com", + lastEditDate: new Date("2024-07-15T09:16:46.640Z"), + }, + { + id: "0006", + name: "Test Folder 6", + permalink: "/testfolder6", + type: "folder", + status: "folder", + lastEditUser: "folder", + lastEditDate: "folder", + }, + { + id: "0007", + name: "Test Page 7", + permalink: "/testpage7", + type: "page", + status: "published", + lastEditUser: "user7@test.com", + lastEditDate: new Date("2024-06-15T09:16:46.640Z"), + }, + { + id: "0008", + name: "Test Folder 8", + permalink: "/testfolder8", + type: "folder", + status: "folder", + lastEditUser: "folder", + lastEditDate: "folder", + }, + { + id: "0009", + name: "Test Folder 9", + permalink: "/testfolder9", + type: "folder", + status: "folder", + lastEditUser: "folder", + lastEditDate: "folder", + }, + { + id: "0010", + name: "Test Page 10", + permalink: "/testpage10", + type: "page", + status: "published", + lastEditUser: "user2@test.com", + lastEditDate: new Date("2024-06-15T09:16:46.640Z"), + }, + { + id: "0011", + name: "Test Folder 11", + permalink: "/testfolder11", + type: "folder", + status: "folder", + lastEditUser: "folder", + lastEditDate: "folder", + }, + { + id: "0012", + name: "Test Page 12", + permalink: "/testpage12", + type: "page", + status: "draft", + lastEditUser: "user1@test.com", + lastEditDate: new Date("2024-07-15T09:16:46.640Z"), + }, + { + id: "0013", + name: "Test Folder 13", + permalink: "/testfolder13", + type: "folder", + status: "folder", + lastEditUser: "folder", + lastEditDate: "folder", + }, + ] + }) +} + +export const pageHandlers = { + list: { + default: pageListQuery, + loading: () => pageListQuery("infinite"), + }, +}