Skip to content

g1t/apps/web/app/lib/workspace-nav.test.ts

75 lines4,281 bytesCodeBlame

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Navigation: the workspace's own page with tabs, pins and recent in the sidebar1import assert from "node:assert/strict";
2import { test } from "node:test";
3
Merge branch 'worktree-agent-ad7c6d88d93adc817'4import { SETTINGS_PAGES, WORKSPACE_PAGES, pagePath, sidebarCurrent, workspacePage, workspaceRedirect } from "./workspace-nav.ts";
Navigation: the workspace's own page with tabs, pins and recent in the sidebar5
Merge branch 'worktree-agent-ad7c6d88d93adc817'6test("a path is one of the workspace's pages, or none", () => {
7 assert.equal(workspacePage("/acme", "acme"), "overview");
8 assert.equal(workspacePage("/Acme/", "acme"), "overview");
9 assert.equal(workspacePage("/acme.data", "acme"), "overview");
10 assert.equal(workspacePage("/acme/-/projects", "acme"), "projects");
11 assert.equal(workspacePage("/acme/-/people", "acme"), "people");
12 assert.equal(workspacePage("/acme/-/packages", "acme"), "packages");
13 assert.equal(workspacePage("/acme/-/teams", "acme"), "teams");
14 assert.equal(workspacePage("/acme/-/insights", "acme"), "insights");
15 // One package or team has a page of its own; settings and the rest have headings.
16 assert.equal(workspacePage("/acme/-/packages/npm/web", "acme"), null);
17 assert.equal(workspacePage("/acme/-/teams/web", "acme"), null);
18 assert.equal(workspacePage("/acme/-/settings", "acme"), null);
19 assert.equal(workspacePage("/acme/-/agents", "acme"), null);
20 assert.equal(workspacePage("/acme/web", "acme"), null);
21 assert.equal(workspacePage("/other", "acme"), null);
Navigation: the workspace's own page with tabs, pins and recent in the sidebar22});
23
Merge branch 'worktree-agent-ad7c6d88d93adc817'24test("every page that once had a tab has a sidebar row", () => {
25 for (const page of ["overview", ...WORKSPACE_PAGES] as const) {
26 const path = page === "overview" ? "/acme" : `/acme/-/${page}`;
27 assert.equal(sidebarCurrent(path, "acme"), page, path);
28 }
Navigation: the workspace's own page with tabs, pins and recent in the sidebar29});
30
Merge branch 'worktree-agent-ad7c6d88d93adc817'31test("one sidebar row is current wherever you are in the workspace", () => {
32 assert.equal(sidebarCurrent("/", "acme"), "mission");
33 assert.equal(sidebarCurrent("/inbox", "acme"), "inbox");
34 assert.equal(sidebarCurrent("/support", "acme"), "support");
35 assert.equal(sidebarCurrent("/acme/-/projects.data", "acme"), "projects");
36 // Within a team or a package, its row stays lit.
37 assert.equal(sidebarCurrent("/acme/-/teams/web/settings", "acme"), "teams");
38 assert.equal(sidebarCurrent("/acme/-/packages/npm/web", "acme"), "packages");
39 assert.equal(sidebarCurrent("/acme/-/agents", "acme"), "agents");
40 assert.equal(sidebarCurrent("/acme/-/usage", "acme"), "usage");
41 // Every page the Settings row drills into.
42 for (const page of SETTINGS_PAGES) assert.equal(sidebarCurrent(`/acme/-/${page}`, "acme"), "settings", page);
43 // Another workspace's pages, a project and a person light nothing here.
44 assert.equal(sidebarCurrent("/other/-/projects", "acme"), null);
45 assert.equal(sidebarCurrent("/acme/web", "acme"), null);
46 assert.equal(sidebarCurrent("/u/ada", "acme"), null);
47 assert.equal(sidebarCurrent("/acme", null), null);
Navigation: the workspace's own page with tabs, pins and recent in the sidebar48});
49
50test("old addresses go to where their pages are now", () => {
51 assert.equal(workspaceRedirect("/acme/-/members"), "/acme/-/people");
52 assert.equal(workspaceRedirect("/acme/-/overview"), "/acme");
53 assert.equal(workspaceRedirect("/acme/-/soon/teams"), "/acme/-/teams");
54 assert.equal(workspaceRedirect("/acme/-/soon/insights", "?x=1"), "/acme/-/insights?x=1");
55 assert.equal(workspaceRedirect("/acme/-/soon/board"), null);
56 assert.equal(workspaceRedirect("/acme/-/people"), null);
57 assert.equal(workspaceRedirect("/acme/web"), null);
58});
59
Merge branch 'worktree-agent-ad7c6d88d93adc817'60test("?tab= opens that page, keeping the rest of the query", () => {
Navigation: the workspace's own page with tabs, pins and recent in the sidebar61 assert.equal(workspaceRedirect("/acme", "?tab=repositories"), "/acme/-/projects");
62 assert.equal(workspaceRedirect("/acme", "?tab=projects&q=api"), "/acme/-/projects?q=api");
63 assert.equal(workspaceRedirect("/acme", "?tab=members"), "/acme/-/people");
64 assert.equal(workspaceRedirect("/acme", "?tab=overview"), "/acme");
Merge branch 'worktree-agent-ad7c6d88d93adc817'65 assert.equal(workspaceRedirect("/acme", "?tab=settings"), "/acme/-/settings");
Navigation: the workspace's own page with tabs, pins and recent in the sidebar66 assert.equal(workspaceRedirect("/acme", "?tab=nonsense"), null);
67 assert.equal(workspaceRedirect("/acme", ""), null);
68});
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging69
70test("a click's data request is for the same page as a full load", () => {
71 assert.equal(pagePath("/acme/-/insights.data"), "/acme/-/insights");
72 assert.equal(pagePath("/acme/-/insights/"), "/acme/-/insights");
73 assert.equal(workspaceRedirect("/acme/-/members.data", "?_routes=routes%2Fworkspace%2Fmoved-members"), "/acme/-/people");
74 assert.equal(workspaceRedirect("/acme/-/members.data", "?_routes=x&q=ada"), "/acme/-/people?q=ada");
75});

This file's history is long; its oldest lines are credited to the oldest commit read.