Skip to content

Commit

Permalink
feat: add page handler for listing resources
Browse files Browse the repository at this point in the history
  • Loading branch information
karrui committed Jul 15, 2024
1 parent 452d842 commit 6654900
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 1 deletion.
3 changes: 2 additions & 1 deletion apps/studio/src/stories/Page/SitePage.stories.tsx
Original file line number Diff line number Diff line change
@@ -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]"

Expand All @@ -9,7 +10,7 @@ const meta: Meta<typeof SitePage> = {
parameters: {
getLayout: SitePage.getLayout,
msw: {
handlers: [meHandlers.me()],
handlers: [meHandlers.me(), pageHandlers.list.default()],
},
},
decorators: [],
Expand Down
138 changes: 138 additions & 0 deletions apps/studio/tests/msw/handlers/page.ts
Original file line number Diff line number Diff line change
@@ -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: "[email protected]",
lastEditDate: new Date("2024-07-15T09:16:46.640Z"),
},
{
id: "0002",
name: "Test Page 2",
permalink: "/testpage2",
type: "page",
status: "published",
lastEditUser: "[email protected]",
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: "[email protected]",
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: "[email protected]",
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: "[email protected]",
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: "[email protected]",
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"),
},
}

0 comments on commit 6654900

Please sign in to comment.