Skip to content

Commit e6e1bbb

Browse files
committed
Use Maps for Pages in props tests
Update tests to match the new Pages shape that uses Maps and id fields. Replace the old pages/folders arrays with pagesBase exposing homePageId/rootFolderId and Map-based pages/folders, add a createPages helper and rootFolder constant, and update tests to call createPages where pages/folders are constructed.
1 parent 4b6d9f0 commit e6e1bbb

1 file changed

Lines changed: 55 additions & 24 deletions

File tree

packages/react-sdk/src/props.test.ts

Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,56 @@ import { isAttributeNameSafe, normalizeProps } from "./props";
44

55
const pagesBase: Pages = {
66
meta: {},
7-
homePage: {
8-
id: "home",
9-
path: "",
10-
name: "Home",
11-
title: "Home",
12-
rootInstanceId: "instance-1",
13-
meta: {},
14-
},
15-
pages: [],
16-
folders: [
17-
{
18-
id: "root",
19-
name: "Root",
20-
slug: "",
21-
children: [],
22-
},
23-
],
7+
homePageId: "home",
8+
rootFolderId: "root",
9+
pages: new Map([
10+
[
11+
"home",
12+
{
13+
id: "home",
14+
path: "",
15+
name: "Home",
16+
title: "Home",
17+
rootInstanceId: "instance-1",
18+
meta: {},
19+
},
20+
],
21+
]),
22+
folders: new Map([
23+
[
24+
"root",
25+
{
26+
id: "root",
27+
name: "Root",
28+
slug: "",
29+
children: [],
30+
},
31+
],
32+
]),
33+
};
34+
35+
const createPages = ({
36+
pages,
37+
folders,
38+
}: {
39+
pages: Array<Pages["pages"] extends Map<string, infer Page> ? Page : never>;
40+
folders: Array<
41+
Pages["folders"] extends Map<string, infer Folder> ? Folder : never
42+
>;
43+
}): Pages => ({
44+
...pagesBase,
45+
pages: new Map([
46+
...pagesBase.pages,
47+
...pages.map((page) => [page.id, page] as const),
48+
]),
49+
folders: new Map(folders.map((folder) => [folder.id, folder] as const)),
50+
});
51+
52+
const rootFolder = {
53+
id: "root",
54+
name: "Root",
55+
slug: "",
56+
children: [],
2457
};
2558

2659
test("normalize asset prop into string", () => {
@@ -194,8 +227,7 @@ test("normalize page prop with path into string", () => {
194227
assetBaseUrl: "",
195228
assets: new Map(),
196229
uploadingImageAssets: [],
197-
pages: {
198-
...pagesBase,
230+
pages: createPages({
199231
pages: [
200232
{
201233
id: "page1",
@@ -206,8 +238,8 @@ test("normalize page prop with path into string", () => {
206238
meta: {},
207239
},
208240
],
209-
folders: [],
210-
},
241+
folders: [rootFolder],
242+
}),
211243
source: "prebuild",
212244
})
213245
).toEqual([
@@ -246,8 +278,7 @@ test("normalize page prop with path and hash into string", () => {
246278
assetBaseUrl: "",
247279
assets: new Map(),
248280
uploadingImageAssets: [],
249-
pages: {
250-
...pagesBase,
281+
pages: createPages({
251282
pages: [
252283
{
253284
id: "page1",
@@ -272,7 +303,7 @@ test("normalize page prop with path and hash into string", () => {
272303
children: ["page1"],
273304
},
274305
],
275-
},
306+
}),
276307
source: "prebuild",
277308
});
278309
expect(result).toEqual([

0 commit comments

Comments
 (0)