| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { routeFor, sitePathOf } from "./links.ts"; |
| 5 | |
| 6 | test("a g1t:// link names a site path, as on the desktop", () => { |
| 7 | assert.equal(sitePathOf("g1t://acme/-/chat/dm/chn_1"), "/acme/-/chat/dm/chn_1"); |
| 8 | assert.equal(sitePathOf("g1t:///acme/rocket/pull/3?tab=files"), "/acme/rocket/pull/3?tab=files"); |
| 9 | assert.equal(sitePathOf("https://g1t.sh/acme"), null); |
| 10 | }); |
| 11 | |
| 12 | test("Chat's pages open the app's Chat", () => { |
| 13 | assert.equal(routeFor("/acme/-/chat"), "/chat?workspace=acme"); |
| 14 | assert.equal(routeFor("/acme/-/chat/general"), "/chat/general?workspace=acme"); |
| 15 | assert.equal(routeFor("/acme/-/chat/dm/chn_1"), "/chat/chn_1?workspace=acme"); |
| 16 | assert.equal(routeFor("/acme/-/chat/browse"), null); |
| 17 | }); |
| 18 | |
| 19 | test("Code's pages open the app's Code", () => { |
| 20 | assert.equal(routeFor("/acme/rocket"), "/code/acme/rocket"); |
| 21 | assert.equal(routeFor("/acme/rocket/pull/14"), "/code/acme/rocket/pull/14"); |
| 22 | assert.equal(routeFor("/acme/rocket/issues/12"), "/code/acme/rocket/issues/12"); |
| 23 | assert.equal(routeFor("/acme/-/overview"), "/code?workspace=acme"); |
| 24 | assert.equal(routeFor("/acme/rocket/pull/14/files"), null); |
| 25 | assert.equal(routeFor("/acme/rocket/issues/new"), null); |
| 26 | }); |
| 27 | |
| 28 | test("the Marketplace, integrations and skills open Customize", () => { |
| 29 | assert.equal(routeFor("/acme/-/marketplace/integrations"), "/customize?workspace=acme"); |
| 30 | assert.equal(routeFor("/acme/-/agents/skills"), "/customize?workspace=acme"); |
| 31 | }); |
| 32 | |
| 33 | test("the app's sign-in comes back to its own screen, and the site's own pages stay on the site", () => { |
| 34 | assert.equal(routeFor("/oauth/callback?code=c&state=s"), "/oauth/callback?code=c&state=s"); |
| 35 | assert.equal(routeFor("/settings/tokens"), null); |
| 36 | assert.equal(routeFor("/"), "/"); |
| 37 | }); |
| 38 | |
| 39 | test("a connect link points the app at a g1t", () => { |
| 40 | assert.equal(routeFor("/connect?server=https%3A%2F%2Fg1t.example.com"), "/connect?server=https%3A%2F%2Fg1t.example.com"); |
| 41 | assert.equal(sitePathOf("g1t://connect?server=https%3A%2F%2Fg1t.example.com"), "/connect?server=https%3A%2F%2Fg1t.example.com"); |
| 42 | // A workspace named connect is still a workspace. |
| 43 | assert.equal(routeFor("/connect/-/chat"), "/chat?workspace=connect"); |
| 44 | assert.equal(routeFor("/connect/web"), "/code/connect/web"); |
| 45 | }); |