Skip to content
81 linesCodeBlameRaw
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { VISITOR_LINKS, projectPageAt, projectPages, usesAppShell } from "./chrome.ts";
5
6test("someone signed in always gets the sidebar", () => {
7 for (const path of ["/", "/pricing", "/acme/web", "/explore", "/does/not/exist"]) {
8 assert.equal(usesAppShell(path, true), true, path);
9 }
10});
11
12test("a visitor gets the sidebar on app pages", () => {
13 for (const path of [
14 "/acme/web",
15 "/acme/web/code",
16 "/acme/web/issues/4",
17 "/acme",
18 "/nothing/here/at/all",
19 ]) {
20 assert.equal(usesAppShell(path, false), true, path);
21 }
22});
23
24test("a visitor gets the marketing frame on the front, pricing and sign-in pages", () => {
25 for (const path of ["/", "/pricing", "/pricing/", "/login", "/register", "/verify", "/confirm-email", "/forgot", "/reset", "/device", "/oauth/authorize"]) {
26 assert.equal(usesAppShell(path, false), false, path);
27 }
28});
29
30test("a visitor reads profiles, Explore and Search in the public frame, with no sidebar", () => {
31 for (const path of ["/u/ada", "/u/ada/", "/explore", "/explore/", "/search"]) {
32 assert.equal(usesAppShell(path, false), false, path);
33 }
34 // A workspace named like a page is still a workspace.
35 assert.equal(usesAppShell("/u", false), true);
36 assert.equal(usesAppShell("/explorers", false), true);
37});
38
39test("a visitor reads the policies, security, support and status in the marketing frame", () => {
40 for (const path of ["/policies", "/policies/terms", "/policies/privacy/", "/security", "/support", "/status"]) {
41 assert.equal(usesAppShell(path, false), false, path);
42 }
43 // A workspace's own security page is still the app's.
44 assert.equal(usesAppShell("/acme/-/security", false), true);
45});
46
47test("a visitor's sidebar offers Explore and Search", () => {
48 assert.deepEqual(VISITOR_LINKS.map((link) => link.to), ["/explore", "/search"]);
49});
50
51test("a project's menu hides member-only pages from everyone else", () => {
52 const visitor = projectPages(false);
53 assert.deepEqual(visitor.slice(0, 5), ["code", "issues", "pulls", "agents", "actions"]);
54 for (const page of ["security", "settings"] as const) {
55 assert.ok(!visitor.includes(page), page);
56 assert.ok(projectPages(true).includes(page), page);
57 }
58 // Security needs push once the role is known: Read and Triage do not see it.
59 assert.ok(!projectPages(true, { push: false }).includes("security"));
60 assert.ok(projectPages(true, { push: true }).includes("security"));
61 // Anyone who can read a repository sees its deployments.
62 assert.ok(visitor.includes("deployments") && projectPages(true).includes("deployments"));
63});
64
65test("the phone's project strip lights the page a path is under", () => {
66 assert.equal(projectPageAt(""), "overview");
67 assert.equal(projectPageAt("blob/main/README.md"), "code");
68 assert.equal(projectPageAt("commit/abc123"), "code");
69 assert.equal(projectPageAt("issues/12"), "issues");
70 assert.equal(projectPageAt("milestones"), "issues");
71 assert.equal(projectPageAt("pull/3/files"), "pulls");
72 assert.equal(projectPageAt("queue"), "pulls");
73 assert.equal(projectPageAt("sessions/abc"), "agents");
74 assert.equal(projectPageAt("actions/runs/9"), "actions");
75 assert.equal(projectPageAt("security/secret-scanning"), "security");
76 assert.equal(projectPageAt("stargazers"), "insights");
77 assert.equal(projectPageAt("settings/branches"), "settings");
78 assert.equal(projectPageAt("soon/logs", { logs: "observability" }), "observability");
79 assert.equal(projectPageAt("soon/boards", { boards: "issues" }), "issues");
80 assert.equal(projectPageAt("pulse"), null);
81});