| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { frameOf, projectPageAt, projectPages } from "./chrome.ts"; |
| 5 | |
| 6 | const visitor = { signedIn: false, workspace: false }; |
| 7 | const member = { signedIn: true, workspace: true }; |
| 8 | const newcomer = { signedIn: true, workspace: false }; |
| 9 | |
| 10 | test("signing in, signing up and choosing a workspace stand alone, for everyone", () => { |
| 11 | for (const path of [ |
| 12 | "/login", |
| 13 | "/login/two-factor", |
| 14 | "/register", |
| 15 | "/register/", |
| 16 | "/invite/abc123", |
| 17 | "/verify", |
| 18 | "/confirm-email", |
| 19 | "/forgot", |
| 20 | "/reset", |
| 21 | "/device", |
| 22 | "/oauth/authorize", |
| 23 | "/auth/github/callback", |
| 24 | "/auth/github/username", |
| 25 | "/workspaces/new", |
| 26 | "/workspaces/new.data", |
| 27 | ]) { |
| 28 | for (const viewer of [visitor, member, newcomer]) assert.equal(frameOf(path, viewer), "standalone", path); |
| 29 | } |
| 30 | }); |
| 31 | |
| 32 | test("answering an invitation stands alone until you belong to a workspace", () => { |
| 33 | assert.equal(frameOf("/invitations", newcomer), "standalone"); |
| 34 | assert.equal(frameOf("/invitations", member), "app"); |
| 35 | }); |
| 36 | |
| 37 | test("someone signed in gets the app everywhere else, public pages included", () => { |
| 38 | for (const path of ["/", "/explore", "/u/ada", "/other/web", "/acme/-/today", "/notifications", "/pricing", "/does/not/exist"]) { |
| 39 | assert.equal(frameOf(path, member), "app", path); |
| 40 | assert.equal(frameOf(path, newcomer), "app", path); |
| 41 | } |
| 42 | }); |
| 43 | |
| 44 | test("a visitor gets the public frame everywhere else", () => { |
| 45 | for (const path of ["/", "/explore", "/search", "/u/ada", "/acme", "/acme/web", "/acme/web/issues/4", "/policies/privacy", "/nothing/here/at/all"]) { |
| 46 | assert.equal(frameOf(path, visitor), "public", path); |
| 47 | } |
| 48 | // A workspace named like a page is still a workspace, and still public to a visitor. |
| 49 | assert.equal(frameOf("/loginx", visitor), "public"); |
| 50 | }); |
| 51 | |
| 52 | test("a project's menu hides member-only pages from everyone else", () => { |
| 53 | const visitor = projectPages(false); |
| 54 | assert.deepEqual(visitor.slice(0, 5), ["code", "issues", "pulls", "agents", "actions"]); |
| 55 | for (const page of ["security", "settings"] as const) { |
| 56 | assert.ok(!visitor.includes(page), page); |
| 57 | assert.ok(projectPages(true).includes(page), page); |
| 58 | } |
| 59 | // Security needs push once the role is known: Read and Triage do not see it. |
| 60 | assert.ok(!projectPages(true, { push: false }).includes("security")); |
| 61 | assert.ok(projectPages(true, { push: true }).includes("security")); |
| 62 | // Anyone who can read a repository sees its deployments. |
| 63 | assert.ok(visitor.includes("deployments") && projectPages(true).includes("deployments")); |
| 64 | }); |
| 65 | |
| 66 | test("the phone's project strip lights the page a path is under", () => { |
| 67 | assert.equal(projectPageAt(""), "overview"); |
| 68 | assert.equal(projectPageAt("blob/main/README.md"), "code"); |
| 69 | assert.equal(projectPageAt("commit/abc123"), "code"); |
| 70 | assert.equal(projectPageAt("issues/12"), "issues"); |
| 71 | assert.equal(projectPageAt("milestones"), "issues"); |
| 72 | assert.equal(projectPageAt("pull/3/files"), "pulls"); |
| 73 | assert.equal(projectPageAt("queue"), "pulls"); |
| 74 | assert.equal(projectPageAt("sessions/abc"), "agents"); |
| 75 | assert.equal(projectPageAt("actions/runs/9"), "actions"); |
| 76 | assert.equal(projectPageAt("security/secret-scanning"), "security"); |
| 77 | assert.equal(projectPageAt("stargazers"), "insights"); |
| 78 | assert.equal(projectPageAt("settings/branches"), "settings"); |
| 79 | assert.equal(projectPageAt("soon/logs", { logs: "observability" }), "observability"); |
| 80 | assert.equal(projectPageAt("soon/boards", { boards: "issues" }), "issues"); |
| 81 | assert.equal(projectPageAt("pulse"), null); |
| 82 | }); |