Skip to content
Source
Sign inSign up
fuko/trytanstackdb-v2
Open History to see the last commit

content.test.ts

58 lines1.9 KB

1import { createMemoryHistory, createRouter } from "@tanstack/react-router";
2import { describe, expect, it } from "vite-plus/test";
3​
4import { createSeedData } from "@/fixtures";
5import { resolveFolderView } from "@/lib/notes/folder-views";
6import { routeTree } from "@/routeTree.gen";
7​
8import { GUIDE_SECTIONS } from "./content";
9​
10const router = createRouter({
11 routeTree,
12 history: createMemoryHistory(),
13 context: { queryClient: undefined as never },
14});
15​
16describe("guide sections", () => {
17 it("have unique ids", () => {
18 const ids = GUIDE_SECTIONS.map((section) => section.id);
19 expect(new Set(ids).size).toBe(ids.length);
20 });
21​
22 it("have short chip labels", () => {
23 for (const section of GUIDE_SECTIONS) expect(section.shortTitle.length).toBeLessThanOrEqual(20);
24 });
25​
26 it("deep-link the hands-on ones into the app", () => {
27 const targets = Object.fromEntries(
28 GUIDE_SECTIONS.filter((section) => section.tryIt).map((section) => [
29 section.id,
30 router.buildLocation(section.tryIt!).pathname,
31 ]),
32 );
33 expect(targets).toEqual({
34 introduction: "/",
35 collections: "/",
36 "live-queries": "/folders/all",
37 "optimistic-updates": "/folders/work",
38 rollbacks: "/",
39 aggregations: "/analytics",
40 });
41 });
42​
43 it("only point at screens that exist", () => {
44 const { folders } = createSeedData();
45 for (const section of GUIDE_SECTIONS) {
46 if (!section.tryIt) continue;
47 const { pathname } = router.buildLocation(section.tryIt);
48 const matches = router.matchRoutes(pathname);
49 const leaf = matches.at(-1);
50 if (!leaf) throw new Error(`${section.id} → ${pathname} matches no route`);
51 expect(leaf.routeId, `${section.id} → ${pathname}`).not.toBe("__root__");
52 const { folderId } = leaf.params as { folderId?: string };
53 if (folderId) {
54 expect(resolveFolderView(folderId, folders), `${section.id} → ${pathname}`).toBeDefined();
55 }
56 }
57 });
58});