Skip to content
55 linesCodeBlameRaw
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { APPS, MAX_APP_PINS, appPinFromForm, appsFor, dockCookie, isPinnable, pinsIn, readDock, sidebarClosed, sidebarCookie, withPin, writeDock } from "./apps.ts";
5
6test("built-in apps are never pinned; the rest are", () => {
7 for (const app of APPS) assert.equal(isPinnable(app.key), !app.builtin, app.key);
8 assert.equal(isPinnable("nonsense"), false);
9});
10
11test("Code's apps are only for members with Code access", () => {
12 const without = appsFor(false).map((app) => app.key);
13 for (const key of ["code", "projects", "packages", "security", "context", "memory"]) assert.ok(!without.includes(key as never), key);
14 for (const key of ["today", "chat", "notifications", "agents", "artifacts", "people", "workspace", "teams", "usage"]) assert.ok(without.includes(key as never), key);
15 assert.equal(appsFor(true).length, APPS.length);
16});
17
18test("pins are kept per workspace, in the order they were pinned", () => {
19 const value = writeDock(writeDock(null, "acme", ["projects", "usage"]), "Beta", ["teams"]);
20 assert.equal(value, "beta:teams,acme:projects.usage");
21 assert.deepEqual(pinsIn(value, "acme"), ["projects", "usage"]);
22 assert.deepEqual(pinsIn(value, "BETA"), ["teams"]);
23 assert.deepEqual(pinsIn(value, "other"), []);
24 // Unpinning everything keeps the workspace, with no pins.
25 assert.deepEqual(pinsIn(writeDock(value, "acme", []), "acme"), []);
26});
27
28test("a cookie someone wrote by hand reads as far as it makes sense", () => {
29 assert.deepEqual(readDock("acme:projects.today.nonsense.projects,BAD SLUG:usage,beta"), { acme: ["projects"] });
30 assert.deepEqual(readDock(""), {});
31 const many = Array.from({ length: 30 }, () => "usage").join(".");
32 assert.ok(pinsIn(`acme:${many}`, "acme").length <= MAX_APP_PINS);
33});
34
35test("a pin form pins or unpins one app", () => {
36 const form = (fields: Record<string, string>) => {
37 const data = new FormData();
38 for (const [name, value] of Object.entries(fields)) data.set(name, value);
39 return data;
40 };
41 assert.deepEqual(appPinFromForm(form({ intent: "pin", app: "teams" })), { app: "teams", pinned: true });
42 assert.deepEqual(appPinFromForm(form({ intent: "unpin", app: "teams" })), { app: "teams", pinned: false });
43 assert.equal(appPinFromForm(form({ intent: "pin", app: "chat" })), null);
44 assert.equal(appPinFromForm(form({ intent: "drop", app: "teams" })), null);
45 assert.deepEqual(withPin(["projects", "teams"], "projects", true), ["teams", "projects"]);
46 assert.deepEqual(withPin(["projects", "teams"], "projects", false), ["teams"]);
47});
48
49test("the cookies last a year and are secure when the site is", () => {
50 assert.match(dockCookie("acme:teams", true), /^g1t_dock=acme%3Ateams; Path=\/; Max-Age=31536000; SameSite=Lax; Secure$/);
51 assert.equal(sidebarCookie(true, false), "g1t_sidebar=closed; Path=/; Max-Age=31536000; SameSite=Lax");
52 assert.equal(sidebarClosed("closed"), true);
53 assert.equal(sidebarClosed("open"), false);
54 assert.equal(sidebarClosed(null), false);
55});