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.
| Integrations are a directory of connectors, for a workspace and for each person | 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; | |
| 3 | ||
| 4 | import { connectorsFor } from "@g1t/contracts/connectors"; | |
| 5 | ||
| 6 | import { | |
| 7 | arrange, | |
| 8 | askHref, | |
| 9 | categoriesWith, | |
| 10 | categoryCounts, | |
| 11 | categoryFilter, | |
| 12 | groupByCategory, | |
| 13 | matchesQuery, | |
| 14 | monogram, | |
| 15 | tileColor, | |
| 16 | } from "./connectors.ts"; | |
| 17 | ||
| 18 | const workspace = connectorsFor("workspace"); | |
| 19 | const personal = connectorsFor("personal"); | |
| 20 | const none = new Set<string>(); | |
| 21 | ||
| 22 | test("the two contexts list different connectors", () => { | |
| 23 | const ids = (views: typeof workspace) => new Set(views.map((view) => view.id)); | |
| 24 | assert.ok(ids(personal).has("google-calendar")); | |
| 25 | assert.ok(!ids(workspace).has("google-calendar"), "a calendar is your own"); | |
| 26 | assert.ok(ids(workspace).has("sentry")); | |
| 27 | assert.ok(!ids(personal).has("sentry"), "alerts are the workspace's"); | |
| 28 | assert.ok(ids(workspace).has("github") && ids(personal).has("github"), "GitHub is both"); | |
| 29 | }); | |
| 30 | ||
| 31 | test("a category shows only its own connectors, sorted into connected, available and soon", () => { | |
| 32 | const found = arrange(workspace, { category: "monitoring", query: "", connected: new Set(["sentry"]) }); | |
| 33 | assert.deepEqual(found.connected.map((view) => view.id), ["sentry"]); | |
| 34 | assert.ok(found.available.some((view) => view.id === "datadog")); | |
| 35 | assert.ok(!found.available.some((view) => view.id === "sentry"), "connected is not also available"); | |
| 36 | assert.ok(found.soon.some((view) => view.id === "pagerduty")); | |
| 37 | for (const view of [...found.connected, ...found.available, ...found.soon]) assert.equal(view.category, "monitoring"); | |
| 38 | }); | |
| 39 | ||
| 40 | test("all shows everything once", () => { | |
| 41 | const found = arrange(workspace, { category: "all", query: "", connected: none }); | |
| 42 | assert.equal(found.available.length + found.soon.length, workspace.length); | |
| 43 | }); | |
| 44 | ||
| 45 | test("search finds by name, description, tag and keyword, across every category", () => { | |
| 46 | const found = arrange(workspace, { category: "design", query: "sentry", connected: none }); | |
| 47 | assert.deepEqual(found.available.map((view) => view.id), ["sentry"], "a search is not held to the category"); | |
| 48 | assert.ok(matchesQuery(personal.find((view) => view.id === "google-calendar")!, "in a meeting")); | |
| 49 | assert.ok(matchesQuery(workspace.find((view) => view.id === "anthropic")!, "claude")); | |
| 50 | assert.ok(matchesQuery(workspace.find((view) => view.id === "incident-io")!, "incidentio")); | |
| 51 | assert.ok(matchesQuery(workspace.find((view) => view.id === "pagerduty")!, "opens ISSUES")); | |
| 52 | assert.ok(!matchesQuery(workspace.find((view) => view.id === "figma")!, "kubernetes")); | |
| 53 | }); | |
| 54 | ||
| 55 | test("the navigation counts each category and leaves out empty ones", () => { | |
| 56 | const counts = categoryCounts(workspace); | |
| 57 | assert.equal(counts.all, workspace.length); | |
| 58 | assert.ok(counts.ai >= 14); | |
| 59 | const mine = categoriesWith(personal).map((category) => category.id); | |
| 60 | assert.ok(mine.includes("calendar")); | |
| 61 | const groups = groupByCategory(personal); | |
| 62 | assert.equal(groups.reduce((sum, group) => sum + group.views.length, 0), personal.length); | |
| 63 | }); | |
| 64 | ||
| 65 | test("an unknown category is all of them", () => { | |
| 66 | assert.equal(categoryFilter("ai"), "ai"); | |
| 67 | assert.equal(categoryFilter("nope"), "all"); | |
| 68 | assert.equal(categoryFilter(null), "all"); | |
| 69 | }); | |
| 70 | ||
| 71 | test("a tile has the connector's letters and a steady colour", () => { | |
| 72 | assert.equal(monogram("PagerDuty"), "PD"); | |
| 73 | assert.equal(monogram("Google Calendar"), "GC"); | |
| 74 | assert.equal(monogram("Sentry"), "S"); | |
| 75 | assert.equal(monogram("incident.io"), "II"); | |
| 76 | assert.equal(monogram("1Password"), "1P"); | |
| 77 | assert.equal(tileColor("figma"), tileColor("figma")); | |
| 78 | }); | |
| 79 | ||
| 80 | test("asking for a connector names it and who it is for", () => { | |
| 81 | const href = askHref({ connector: { id: "slack", name: "Slack" }, scope: "workspace", workspace: "acme", address: "hey@example.com" }); | |
| 82 | assert.ok(href.startsWith("mailto:hey@example.com?subject=Integration%20request%3A%20Slack")); | |
| 83 | assert.ok(decodeURIComponent(href).includes("For the workspace: acme")); | |
| 84 | const mine = askHref({ connector: { id: "google-calendar", name: "Google Calendar" }, scope: "personal", workspace: null, address: "hey@example.com" }); | |
| 85 | assert.ok(decodeURIComponent(mine).includes("For my own account.")); | |
| 86 | }); |