| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | import type { SessionDraftSummary } from "../generated/desktopContract.generated"; |
| 4 | import { workspaceDraftBadge } from "../lib/projectTreeTopic"; |
| 5 | |
| 6 | function summary(patch: Partial<SessionDraftSummary>): SessionDraftSummary { |
| 7 | return { id: "draft", workspaceId: "ws", scope: "global", workspaceRoot: "", revision: 1, hasContent: false, updatedAt: 1, ...patch }; |
| 8 | } |
| 9 | |
| 10 | test("a clean empty draft does not badge its workspace", () => { |
| 11 | assert.equal(workspaceDraftBadge([summary({ state: "saved" })], "global", ""), undefined); |
| 12 | assert.equal(workspaceDraftBadge([summary({})], "global", ""), undefined); |
| 13 | assert.equal(workspaceDraftBadge([summary({ scope: "project", workspaceRoot: "/repo/agent" })], "project", "/repo/agent"), undefined); |
| 14 | }); |
| 15 | |
| 16 | test("unsent content badges only the owning workspace", () => { |
| 17 | const drafts = [ |
| 18 | summary({ id: "g", hasContent: true }), |
| 19 | summary({ id: "p", scope: "project", workspaceRoot: "/repo/agent", hasContent: true }), |
| 20 | ]; |
| 21 | assert.equal(workspaceDraftBadge(drafts, "global", "")?.id, "g"); |
| 22 | assert.equal(workspaceDraftBadge(drafts, "project", "/repo/agent")?.id, "p"); |
| 23 | assert.equal(workspaceDraftBadge(drafts, "project", "/repo/other"), undefined); |
| 24 | }); |
| 25 | |
| 26 | test("an unsettled save keeps the badge while the content is still empty", () => { |
| 27 | for (const state of ["dirty", "saving", "error", "conflict"]) { |
| 28 | assert.equal(workspaceDraftBadge([summary({ state })], "global", "")?.state, state); |
| 29 | } |
| 30 | }); |
| 31 |