Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

adaptive-navigation.test.ts

84 lines2.7 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import {
4 resolveThreadSelectionNavigationAction,
5 resolveThreadSelectionOverlayState,
6} from "./adaptive-navigation";
7​
8describe("resolveThreadSelectionNavigationAction", () => {
9 it("replaces nested thread content when a persistent sidebar selects a peer", () => {
10 expect(
11 resolveThreadSelectionNavigationAction({
12 usesSplitView: true,
13 pathname: "/threads/environment/thread/files/path",
14 }),
15 ).toBe("replace");
16 });
17​
18 it("pushes from Home so the back stack survives collapsing to compact", () => {
19 expect(
20 resolveThreadSelectionNavigationAction({
21 usesSplitView: true,
22 pathname: "/",
23 }),
24 ).toBe("push");
25 });
26});
27​
28describe("resolveThreadSelectionOverlayState", () => {
29 const stack = {
30 key: "workspace",
31 type: "stack",
32 stale: false as const,
33 routeNames: ["Home", "Thread", "ThreadFiles", "SettingsSheet", "SettingsLegal"],
34 };
35 const home = { key: "home", name: "Home" };
36 const thread = {
37 key: "thread",
38 name: "Thread",
39 params: { environmentId: "environment", threadId: "old-thread" },
40 };
41 const files = { key: "files", name: "ThreadFiles", params: thread.params };
42 const settings = { key: "settings", name: "SettingsSheet" };
43 const params = { environmentId: "environment", threadId: "new-thread" };
44​
45 it("replaces the underlying file route and dismisses every overlay above it", () => {
46 expect(
47 resolveThreadSelectionOverlayState({
48 state: {
49 ...stack,
50 index: 4,
51 routes: [home, thread, files, settings, { key: "legal", name: "SettingsLegal" }],
52 },
53 workspaceRouteKey: files.key,
54 action: "replace",
55 params,
56 }),
57 ).toEqual({ ...stack, index: 2, routes: [home, thread, { name: "Thread", params }] });
58 });
59​
60 it("dismisses an overlay when selecting the current thread without replacing its route key", () => {
61 expect(
62 resolveThreadSelectionOverlayState({
63 state: { ...stack, index: 2, routes: [home, thread, settings] },
64 workspaceRouteKey: thread.key,
65 action: "set-params",
66 params: thread.params,
67 }),
68 ).toEqual({ ...stack, index: 1, routes: [home, thread] });
69 });
70​
71 it.each([home, files])(
72 "keeps $name in the back stack when pushing from beneath a sheet",
73 (route) => {
74 expect(
75 resolveThreadSelectionOverlayState({
76 state: { ...stack, index: 1, routes: [route, settings] },
77 workspaceRouteKey: route.key,
78 action: "push",
79 params,
80 }),
81 ).toEqual({ ...stack, index: 1, routes: [route, { name: "Thread", params }] });
82 },
83 );
84});