Skip to content

Commit 9fbbed8

Browse files
committed
test(ui): split bootstrap navigation visibility coverage
1 parent 00102d3 commit 9fbbed8

2 files changed

Lines changed: 90 additions & 80 deletions

File tree

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { describe, expect, it } from "vitest";
2+
import {
3+
SIDEBAR_SESSION_NAV_COLLAPSE_QUERY,
4+
withSidebarNavCollapseIntent,
5+
} from "../app-session-route-paths.ts";
6+
import { bootstrapApplication } from "./bootstrap.ts";
7+
import { loadSettings, saveSettings } from "./settings.ts";
8+
9+
const SIDEBAR_COLLAPSE_SEARCH = new URLSearchParams({
10+
[SIDEBAR_SESSION_NAV_COLLAPSE_QUERY.name]: SIDEBAR_SESSION_NAV_COLLAPSE_QUERY.value,
11+
}).toString();
12+
13+
describe("withSidebarNavCollapseIntent", () => {
14+
it.each([
15+
["/chat/main/research", "/chat/main/research?nav=collapsed"],
16+
["/chat/main?catalog=codex&thread=one", "/chat/main?catalog=codex&thread=one&nav=collapsed"],
17+
["/chat/main?nav=collapsed&catalog=codex", "/chat/main?nav=collapsed&catalog=codex"],
18+
["/chat/main?catalog=codex#details", "/chat/main?catalog=codex&nav=collapsed#details"],
19+
])("marks %s exactly once while preserving its route", (href, expected) => {
20+
expect(withSidebarNavCollapseIntent(href)).toBe(expected);
21+
});
22+
});
23+
24+
describe("normalizeInitialApplicationLocation", () => {
25+
it.each([
26+
{
27+
initialUrl: `/chat/research/conversation?keep=yes&${SIDEBAR_COLLAPSE_SEARCH}#details`,
28+
expectedUrl: "/chat/research/conversation?keep=yes#details",
29+
navCollapsed: true,
30+
},
31+
{
32+
initialUrl: `/chat/research?${SIDEBAR_COLLAPSE_SEARCH}`,
33+
expectedUrl: "/chat/research",
34+
navCollapsed: true,
35+
},
36+
{
37+
initialUrl: `/chat?${SIDEBAR_COLLAPSE_SEARCH}`,
38+
expectedUrl: "/chat",
39+
navCollapsed: false,
40+
},
41+
{
42+
initialUrl: `/dashboard/research/conversation?${SIDEBAR_COLLAPSE_SEARCH}`,
43+
expectedUrl: "/dashboard/research/conversation",
44+
navCollapsed: false,
45+
},
46+
{
47+
initialUrl: "/settings/appearance",
48+
expectedUrl: "/settings/appearance",
49+
navCollapsed: false,
50+
},
51+
])("seeds sidebar visibility once from explicit new-tab intent at $initialUrl", (testCase) => {
52+
const previousSettings = loadSettings();
53+
const previousUrl = window.location.href;
54+
window.history.replaceState({}, "", testCase.initialUrl);
55+
let runtime: ReturnType<typeof bootstrapApplication> | undefined;
56+
57+
try {
58+
runtime = bootstrapApplication({
59+
sessionPathBuilderReady: new Promise<void>(() => {}),
60+
});
61+
expect(runtime.context.navigation.snapshot.navCollapsed).toBe(testCase.navCollapsed);
62+
expect(`${window.location.pathname}${window.location.search}${window.location.hash}`).toBe(
63+
testCase.expectedUrl,
64+
);
65+
} finally {
66+
runtime?.stop();
67+
window.history.replaceState({}, "", previousUrl);
68+
saveSettings(previousSettings);
69+
}
70+
});
71+
72+
it("keeps the sidebar expanded for an unmarked chat-session deep link", () => {
73+
const previousSettings = loadSettings();
74+
const previousUrl = window.location.href;
75+
window.history.replaceState({}, "", "/chat/research/conversation");
76+
let runtime: ReturnType<typeof bootstrapApplication> | undefined;
77+
78+
try {
79+
runtime = bootstrapApplication({
80+
sessionPathBuilderReady: new Promise<void>(() => {}),
81+
});
82+
expect(runtime.context.navigation.snapshot.navCollapsed).toBe(false);
83+
} finally {
84+
runtime?.stop();
85+
window.history.replaceState({}, "", previousUrl);
86+
saveSettings(previousSettings);
87+
}
88+
});
89+
});

‎ui/src/app/bootstrap.test.ts‎

Lines changed: 1 addition & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ import { describe, expect, it, vi } from "vitest";
33
import { CONTROL_UI_BASE_PATH_ATTRIBUTE } from "../../../src/gateway/control-ui-contract.js";
44
import type { GatewayBrowserClient } from "../api/gateway.ts";
55
import { routeIdFromPath, type RouteId } from "../app-routes.ts";
6-
import {
7-
SIDEBAR_SESSION_NAV_COLLAPSE_QUERY,
8-
sessionRefFromPath,
9-
withSidebarNavCollapseIntent,
10-
} from "../app-session-route-paths.ts";
6+
import { sessionRefFromPath } from "../app-session-route-paths.ts";
117
import {
128
isDefaultChatLanding,
139
startModelSetupFirstRunRedirectAfterLocation,
@@ -25,9 +21,6 @@ import { normalizeLegacyTerminalViewLocation } from "./startup-settings.ts";
2521
// performance assertion, so these waits must not inherit vi.waitFor's 1s default:
2622
// under a loaded CI runner that budget expires before startup reaches the step.
2723
const STARTUP_STEP_WAIT = { timeout: 15_000 };
28-
const SIDEBAR_COLLAPSE_SEARCH = new URLSearchParams({
29-
[SIDEBAR_SESSION_NAV_COLLAPSE_QUERY.name]: SIDEBAR_SESSION_NAV_COLLAPSE_QUERY.value,
30-
}).toString();
3124

3225
function deferred<T>() {
3326
let resolve!: (value: T) => void;
@@ -37,17 +30,6 @@ function deferred<T>() {
3730
return { promise, resolve };
3831
}
3932

40-
describe("withSidebarNavCollapseIntent", () => {
41-
it.each([
42-
["/chat/main/research", "/chat/main/research?nav=collapsed"],
43-
["/chat/main?catalog=codex&thread=one", "/chat/main?catalog=codex&thread=one&nav=collapsed"],
44-
["/chat/main?nav=collapsed&catalog=codex", "/chat/main?nav=collapsed&catalog=codex"],
45-
["/chat/main?catalog=codex#details", "/chat/main?catalog=codex&nav=collapsed#details"],
46-
])("marks %s exactly once while preserving its route", (href, expected) => {
47-
expect(withSidebarNavCollapseIntent(href)).toBe(expected);
48-
});
49-
});
50-
5133
describe("normalizeLegacyTerminalViewLocation", () => {
5234
it.each([
5335
{
@@ -557,67 +539,6 @@ describe("normalizeInitialApplicationLocation", () => {
557539
}
558540
});
559541

560-
it.each([
561-
{
562-
initialUrl: `/chat/research/conversation?keep=yes&${SIDEBAR_COLLAPSE_SEARCH}#details`,
563-
expectedUrl: "/chat/research/conversation?keep=yes#details",
564-
navCollapsed: true,
565-
},
566-
{
567-
initialUrl: `/chat/research?${SIDEBAR_COLLAPSE_SEARCH}`,
568-
expectedUrl: "/chat/research",
569-
navCollapsed: true,
570-
},
571-
{
572-
initialUrl: `/chat?${SIDEBAR_COLLAPSE_SEARCH}`,
573-
expectedUrl: "/chat",
574-
navCollapsed: false,
575-
},
576-
{
577-
initialUrl: `/dashboard/research/conversation?${SIDEBAR_COLLAPSE_SEARCH}`,
578-
expectedUrl: "/dashboard/research/conversation",
579-
navCollapsed: false,
580-
},
581-
{
582-
initialUrl: "/settings/appearance",
583-
expectedUrl: "/settings/appearance",
584-
navCollapsed: false,
585-
},
586-
])("seeds sidebar visibility once from explicit new-tab intent at $initialUrl", (testCase) => {
587-
const previousSettings = loadSettings();
588-
const previousUrl = window.location.href;
589-
window.history.replaceState({}, "", testCase.initialUrl);
590-
let runtime: ReturnType<typeof bootstrapApplication> | undefined;
591-
592-
try {
593-
runtime = bootstrapApplication({ sessionPathBuilderReady: deferred<void>().promise });
594-
expect(runtime.context.navigation.snapshot.navCollapsed).toBe(testCase.navCollapsed);
595-
expect(`${window.location.pathname}${window.location.search}${window.location.hash}`).toBe(
596-
testCase.expectedUrl,
597-
);
598-
} finally {
599-
runtime?.stop();
600-
window.history.replaceState({}, "", previousUrl);
601-
saveSettings(previousSettings);
602-
}
603-
});
604-
605-
it("keeps the sidebar expanded for an unmarked chat-session deep link", () => {
606-
const previousSettings = loadSettings();
607-
const previousUrl = window.location.href;
608-
window.history.replaceState({}, "", "/chat/research/conversation");
609-
let runtime: ReturnType<typeof bootstrapApplication> | undefined;
610-
611-
try {
612-
runtime = bootstrapApplication({ sessionPathBuilderReady: deferred<void>().promise });
613-
expect(runtime.context.navigation.snapshot.navCollapsed).toBe(false);
614-
} finally {
615-
runtime?.stop();
616-
window.history.replaceState({}, "", previousUrl);
617-
saveSettings(previousSettings);
618-
}
619-
});
620-
621542
it("does not rewrite browser history when startup contains no URL credentials", () => {
622543
const previousSettings = loadSettings();
623544
const previousUrl = window.location.href;

0 commit comments

Comments
 (0)