Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import {
4 resolveThreadSelectionNavigationAction,
5 resolveThreadSelectionOverlayState,
6} from "./adaptive-navigation";
7
8describe("resolveThreadSelectionNavigationAction", () => {
9 it("retains the draft screen despite its query-shaped path", () => {
10 expect(
11 resolveThreadSelectionNavigationAction({
12 usesSplitView: true,
13 pathname: "/threads?draft=local",
14 workspaceRouteName: "Thread",
15 }),
16 ).toBe("set-params");
17 });
18 it("replaces nested thread content when a persistent sidebar selects a peer", () => {
19 expect(
20 resolveThreadSelectionNavigationAction({
21 usesSplitView: true,
22 pathname: "/threads/environment/thread/files/path",
23 }),
24 ).toBe("replace");
25 });
26
27 it("pushes from Home so the back stack survives collapsing to compact", () => {
28 expect(
29 resolveThreadSelectionNavigationAction({
30 usesSplitView: true,
31 pathname: "/",
32 }),
33 ).toBe("push");
34 });
35});
36
37describe("resolveThreadSelectionOverlayState", () => {
38 const stack = {
39 key: "workspace",
40 type: "stack",
41 stale: false as const,
42 routeNames: ["Home", "Thread", "ThreadFiles", "Connections", "SettingsLegal"],
43 };
44 const home = { key: "home", name: "Home" };
45 const thread = {
46 key: "thread",
47 name: "Thread",
48 params: { environmentId: "environment", threadId: "old-thread" },
49 };
50 const files = { key: "files", name: "ThreadFiles", params: thread.params };
51 const settings = { key: "settings", name: "Connections" };
52 const params = { environmentId: "environment", threadId: "new-thread" };
53
54 it("replaces the underlying file route and dismisses every overlay above it", () => {
55 expect(
56 resolveThreadSelectionOverlayState({
57 state: {
58 ...stack,
59 index: 4,
60 routes: [home, thread, files, settings, { key: "legal", name: "SettingsLegal" }],
61 },
62 workspaceRouteKey: files.key,
63 action: "replace",
64 params,
65 }),
66 ).toEqual({ ...stack, index: 2, routes: [home, thread, { name: "Thread", params }] });
67 });
68
69 it("dismisses an overlay when selecting the current thread without replacing its route key", () => {
70 expect(
71 resolveThreadSelectionOverlayState({
72 state: { ...stack, index: 2, routes: [home, thread, settings] },
73 workspaceRouteKey: thread.key,
74 action: "set-params",
75 params: thread.params,
76 }),
77 ).toEqual({ ...stack, index: 1, routes: [home, thread] });
78 });
79
80 it.each([home, files])(
81 "keeps $name in the back stack when pushing from beneath a sheet",
82 (route) => {
83 expect(
84 resolveThreadSelectionOverlayState({
85 state: { ...stack, index: 1, routes: [route, settings] },
86 workspaceRouteKey: route.key,
87 action: "push",
88 params,
89 }),
90 ).toEqual({ ...stack, index: 1, routes: [route, { name: "Thread", params }] });
91 },
92 );
93});
94
95it("replacing a draft underneath an overlay removes its draft identity", () => {
96 const result = resolveThreadSelectionOverlayState({
97 state: {
98 key: "root",
99 type: "stack",
100 stale: false,
101 routeNames: ["Thread", "Connections"],
102 index: 1,
103 routes: [
104 { key: "draft", name: "Thread", params: { draft: { draftId: "old" } } },
105 { key: "settings", name: "Connections" },
106 ],
107 },
108 workspaceRouteKey: "draft",
109 action: "set-params",
110 params: { environmentId: "env", threadId: "live" },
111 });
112 expect(result?.routes[0]?.params).toEqual({ environmentId: "env", threadId: "live" });
113});