Skip to content

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

51 lines2,655 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.

Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { readCookie } from "./mission.ts";
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look5import { chosenWorkspace, forgetWorkspace, rememberWorkspace, workspaceFor } from "./workspace-choice.ts";
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put6
7const mine = [{ slug: "flagon-io" }, { slug: "syntaqx" }];
8
9test("the chosen workspace holds while you are a member, else the first", () => {
10 assert.equal(chosenWorkspace(mine, "syntaqx")?.slug, "syntaqx");
11 assert.equal(chosenWorkspace(mine, "SYNTAQX")?.slug, "syntaqx");
12 assert.equal(chosenWorkspace(mine, "someone-else")?.slug, "flagon-io");
13 assert.equal(chosenWorkspace(mine, null)?.slug, "flagon-io");
14 assert.equal(chosenWorkspace([], "syntaqx"), null);
15});
16
Usage, Billing settings and prepaid AI credit; fixes from the UX audit17test("a project in one of your workspaces is about that workspace", () => {
18 // Chose Flagon, looking at syntaqx/g1t: syntaqx, the project's own.
19 assert.equal(workspaceFor(mine, "flagon-io", { owner: "syntaqx", repo: "g1t" })?.slug, "syntaqx");
20 assert.equal(workspaceFor(mine, "syntaqx", { owner: "Flagon-IO", repo: "g1t" })?.slug, "flagon-io");
21});
22
23test("a project somewhere you do not belong leaves the chosen workspace", () => {
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put24 // A public project somewhere else entirely: still Flagon.
25 assert.equal(workspaceFor(mine, "flagon-io", { owner: "acme", repo: "web" })?.slug, "flagon-io");
26 // Mission control: still Flagon.
27 assert.equal(workspaceFor(mine, "flagon-io", {})?.slug, "flagon-io");
28});
29
30test("a workspace's own pages are about that workspace", () => {
31 assert.equal(workspaceFor(mine, "flagon-io", { owner: "syntaqx" })?.slug, "syntaqx");
32 // Not yours: the chosen one.
33 assert.equal(workspaceFor(mine, "flagon-io", { owner: "acme" })?.slug, "flagon-io");
34});
35
36test("the cookie reads back what was remembered", () => {
37 const set = rememberWorkspace("Flagon-IO", true);
38 assert.match(set, /^g1t_ws=flagon-io; Path=\/; Max-Age=31536000; SameSite=Lax; Secure$/);
39 assert.equal(readCookie("a=1; g1t_ws=flagon-io; b=2", "g1t_ws"), "flagon-io");
40 assert.equal(readCookie(null, "g1t_ws"), null);
41 assert.equal(readCookie("g1t_ws=%E0%A4%A", "g1t_ws"), null);
42});
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look43
44test("a deleted workspace you had chosen gives way to another, or to none", () => {
45 // syntaqx deleted: the cookie still names it, and you are in Flagon only.
46 assert.equal(chosenWorkspace([{ slug: "flagon-io" }], "syntaqx")?.slug, "flagon-io");
47 assert.equal(workspaceFor([{ slug: "flagon-io" }], "syntaqx", {})?.slug, "flagon-io");
48 // In no workspace at all: an account still works, with nothing chosen.
49 assert.equal(workspaceFor([], "syntaqx", {}), null);
50 assert.match(forgetWorkspace(true), /^g1t_ws=; Path=\/; Max-Age=0; SameSite=Lax; Secure$/);
51});