| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { pagePath, underWorkspace, workspacePage, workspaceRedirect } from "./workspace-nav.ts"; |
| 5 | |
| 6 | test("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); |
| 22 | }); |
| 23 | |
| 24 | test("old addresses go to where their pages are now", () => { |
| 25 | assert.equal(workspaceRedirect("/acme/-/members"), "/acme/-/people"); |
| 26 | assert.equal(workspaceRedirect("/acme/-/home", "?x=1"), "/acme/-/today?x=1"); |
| 27 | // Code's Overview lives at -/overview now: not an old address. |
| 28 | assert.equal(workspaceRedirect("/acme/-/overview"), null); |
| 29 | assert.equal(workspaceRedirect("/acme/-/soon/teams"), "/acme/-/teams"); |
| 30 | // Agent templates were the Marketplace's Agents tab. |
| 31 | assert.equal(workspaceRedirect("/acme/-/marketplace/agents"), "/acme/-/agents/templates"); |
| 32 | assert.equal(workspaceRedirect("/acme/-/marketplace/agents/qa.data", "?_routes=x"), "/acme/-/agents/templates/qa"); |
| 33 | assert.equal(workspaceRedirect("/acme/-/marketplace/agentsx"), null); |
| 34 | assert.equal(workspaceRedirect("/acme/-/marketplace/extensions"), null); |
| 35 | assert.equal(workspaceRedirect("/acme/-/soon/insights", "?x=1"), "/acme/-/insights?x=1"); |
| 36 | assert.equal(workspaceRedirect("/acme/-/soon/board"), null); |
| 37 | assert.equal(workspaceRedirect("/acme/-/people"), null); |
| 38 | assert.equal(workspaceRedirect("/acme/web"), null); |
| 39 | }); |
| 40 | |
| 41 | test("?tab= opens that page, keeping the rest of the query", () => { |
| 42 | assert.equal(workspaceRedirect("/acme", "?tab=repositories"), "/acme/-/projects"); |
| 43 | assert.equal(workspaceRedirect("/acme", "?tab=projects&q=api"), "/acme/-/projects?q=api"); |
| 44 | assert.equal(workspaceRedirect("/acme", "?tab=members"), "/acme/-/people"); |
| 45 | assert.equal(workspaceRedirect("/acme", "?tab=overview"), "/acme"); |
| 46 | assert.equal(workspaceRedirect("/acme", "?tab=settings"), "/acme/-/settings"); |
| 47 | assert.equal(workspaceRedirect("/acme", "?tab=nonsense"), null); |
| 48 | assert.equal(workspaceRedirect("/acme", ""), null); |
| 49 | }); |
| 50 | |
| 51 | test("a click's data request is for the same page as a full load", () => { |
| 52 | assert.equal(pagePath("/acme/-/insights.data"), "/acme/-/insights"); |
| 53 | assert.equal(pagePath("/acme/-/insights/"), "/acme/-/insights"); |
| 54 | assert.equal(workspaceRedirect("/acme/-/members.data", "?_routes=routes%2Fworkspace%2Fmoved-members"), "/acme/-/people"); |
| 55 | assert.equal(workspaceRedirect("/acme/-/members.data", "?_routes=x&q=ada"), "/acme/-/people?q=ada"); |
| 56 | }); |
| 57 | |
| 58 | test("an alias or old name leads to the same page under the workspace", () => { |
| 59 | assert.equal(underWorkspace("/g1t", "", "flagon-io"), "/flagon-io"); |
| 60 | assert.equal(underWorkspace("/g1t/g1t/issues", "?q=is%3Aopen", "flagon-io"), "/flagon-io/g1t/issues?q=is%3Aopen"); |
| 61 | assert.equal(underWorkspace("/g1t/g1t/blob/main/README.md", "", "flagon-io"), "/flagon-io/g1t/blob/main/README.md"); |
| 62 | assert.equal(underWorkspace("/g1t/-/people/", "", "flagon-io"), "/flagon-io/-/people"); |
| 63 | }); |
| 64 | |
| 65 | test("a click's data request for an alias leads to the page, not its data", () => { |
| 66 | assert.equal(underWorkspace("/g1t.data", "?_routes=routes%2Fworkspace%2Flayout", "flagon-io"), "/flagon-io"); |
| 67 | assert.equal( |
| 68 | underWorkspace("/g1t/g1t/pulls.data", "?_routes=routes%2Frepo%2Flayout&state=closed", "flagon-io"), |
| 69 | "/flagon-io/g1t/pulls?state=closed", |
| 70 | ); |
| 71 | }); |
| 72 | |
| 73 | test("the dock's mode follows the address", async () => { |
| 74 | const { modeOf, modeHome, homePath } = await import("./workspace-nav.ts"); |
| 75 | assert.equal(modeOf("/", "acme"), "today"); |
| 76 | assert.equal(modeOf("/acme", "acme"), "today"); |
| 77 | assert.equal(modeOf("/acme/-/today", "acme"), "today"); |
| 78 | // g1t's own public pages light no mode. |
| 79 | assert.equal(modeOf("/explore", "acme"), "site"); |
| 80 | assert.equal(modeOf("/u/ada", "acme"), "site"); |
| 81 | assert.equal(modeOf("/search.data", "acme"), "site"); |
| 82 | assert.equal(modeOf("/notifications", "acme"), "notifications"); |
| 83 | assert.equal(modeOf("/settings/emails", "acme"), "account"); |
| 84 | assert.equal(modeOf("/acme/-/chat/general", "acme"), "chat"); |
| 85 | assert.equal(modeOf("/acme/-/chat/dm/c1.data", "acme"), "chat"); |
| 86 | assert.equal(modeOf("/acme/-/agents", "acme"), "agents"); |
| 87 | assert.equal(modeOf("/acme/-/agents/ship/profile", "acme"), "agents"); |
| 88 | assert.equal(modeOf("/acme/-/context", "acme"), "agents"); |
| 89 | assert.equal(modeOf("/acme/-/memory", "acme"), "agents"); |
| 90 | assert.equal(modeOf("/acme/-/artifacts", "acme"), "artifacts"); |
| 91 | assert.equal(modeOf("/acme/-/artifacts/spaces/general", "acme"), "artifacts"); |
| 92 | // Docs mode is gone: its old addresses are nobody's mode, so they fall to Code's not-found page. |
| 93 | assert.equal(modeOf("/acme/-/docs", "acme"), "code"); |
| 94 | assert.equal(modeOf("/acme/-/overview", "acme"), "code"); |
| 95 | assert.equal(modeOf("/acme/-/projects", "acme"), "code"); |
| 96 | assert.equal(modeOf("/acme/-/security", "acme"), "code"); |
| 97 | assert.equal(modeOf("/acme/-/security/settings", "acme"), "workspace"); |
| 98 | assert.equal(modeOf("/acme/-/people", "acme"), "people"); |
| 99 | assert.equal(modeOf("/acme/-/teams/web", "acme"), "people"); |
| 100 | assert.equal(modeOf("/acme/-/apps", "acme"), "apps"); |
| 101 | assert.equal(modeOf("/acme/-/billing", "acme"), "workspace"); |
| 102 | assert.equal(modeOf("/acme/-/tokens", "acme"), "workspace"); |
| 103 | assert.equal(modeOf("/acme/-/workspace", "acme"), "workspace"); |
| 104 | assert.equal(modeOf("/acme/web/pulls", "acme"), "code"); |
| 105 | assert.equal(modeOf("/new", "acme"), "code"); |
| 106 | // Another workspace's chat is not this one's mode; its repositories are Code's. |
| 107 | assert.equal(modeOf("/other/-/chat", "acme"), "code"); |
| 108 | assert.equal(modeHome("today", "acme"), "/acme/-/today"); |
| 109 | assert.equal(modeHome("notifications", "acme"), "/notifications"); |
| 110 | assert.equal(modeHome("people", "acme"), "/acme/-/people"); |
| 111 | assert.equal(modeHome("apps", "acme"), "/acme/-/apps"); |
| 112 | assert.equal(modeHome("code", "acme"), "/acme/-/overview"); |
| 113 | assert.equal(modeHome("workspace", "acme"), "/acme/-/workspace"); |
| 114 | assert.equal(homePath("acme"), "/acme/-/today"); |
| 115 | assert.equal(homePath("acme", "?agent=new"), "/acme/-/overview?agent=new"); |
| 116 | assert.equal(homePath("acme", "?tab=landed&_routes=x"), "/acme/-/overview?tab=landed"); |
| 117 | }); |
| 118 | |
| 119 | test("a member without Code access is sent around Code's pages", async () => { |
| 120 | const { codeGate } = await import("./workspace-nav.ts"); |
| 121 | const none = ["acme"]; |
| 122 | assert.equal(codeGate("/", "", none, "acme"), "/acme/-/today"); |
| 123 | assert.equal(codeGate("/", "", none, "other"), null); |
| 124 | assert.equal(codeGate("/acme", "", none, "acme"), "/acme/-/today"); |
| 125 | assert.equal(codeGate("/acme/web/pull/3", "?x=1", none, "acme"), "/acme/-/code-access?from=%2Facme%2Fweb%2Fpull%2F3%3Fx%3D1"); |
| 126 | assert.equal(codeGate("/acme/-/projects", "", none, "acme"), "/acme/-/code-access?from=%2Facme%2F-%2Fprojects"); |
| 127 | assert.equal(codeGate("/acme/-/chat/general", "", none, "acme"), null); |
| 128 | assert.equal(codeGate("/acme/-/code-access", "", none, "acme"), null); |
| 129 | assert.equal(codeGate("/other/web", "", none, "acme"), null); |
| 130 | assert.equal(codeGate("/acme/web", "", [], "acme"), null); |
| 131 | }); |