// Run with: node_modules/.bin/tsx --test "app/**/*.test.ts" (from editor/). import { test } from "node:test"; import assert from "node:assert/strict"; import { stateCopy, stateTone, type OperationPanelView, } from "./operationState"; function view(over: Partial = {}): OperationPanelView { return { id: "digest", label: "Digest", group: "digest", state: "present", enabled: true, outputs: [], dependsOn: [], ...over, }; } test("every state has a word, and the three digest.spec.ts pins are literal", () => { // These three are e2e contract: digest.spec.ts asserts "not generated" and // "current" as exact text and toContainText("stale") for the third. assert.equal(stateCopy(view({ state: "missing" })), "not generated"); assert.equal(stateCopy(view({ state: "present" })), "current"); assert.equal( stateCopy(view({ state: "stale" })), "stale — regenerating would replace this", ); // `partial` contains "stale" too, so digest.spec.ts's toContainText passes // whether a config change leaves the video wholly stale or part-done. const partial = stateCopy(view({ state: "partial" })); assert.equal( partial, "partly stale — regenerating would replace the stale sections", ); assert.ok(partial.includes("stale")); assert.equal( stateCopy(view({ state: "missing-input" })), "input gone — needs media", ); assert.equal(stateCopy(view({ state: "not-applicable" })), "not applicable"); }); test("deferred carries the kind's own hint, verbatim, and stands alone without one", () => { assert.equal( stateCopy( view({ state: "deferred", deferredHint: "waiting on a normalized transcript", }), ), "held — waiting on a normalized transcript", ); assert.equal(stateCopy(view({ state: "deferred" })), "held"); }); test("blocked names what it is waiting for, one or several", () => { assert.equal( stateCopy( view({ state: "blocked", dependsOn: [{ id: "diarization", label: "Speaker diarization" }], }), ), "waiting on Speaker diarization", ); assert.equal( stateCopy( view({ state: "blocked", dependsOn: [ { id: "diarization", label: "Speaker diarization" }, { id: "transcription", label: "Transcription" }, ], }), ), "waiting on Speaker diarization and Transcription", ); }); test("tone: only a present record is success, and only a state an operator can act on is warning", () => { assert.equal(stateTone("present"), "success"); assert.equal(stateTone("stale"), "warning"); assert.equal(stateTone("partial"), "warning"); assert.equal(stateTone("missing-input"), "warning"); assert.equal(stateTone("missing"), "muted"); assert.equal(stateTone("deferred"), "muted"); assert.equal(stateTone("blocked"), "muted"); assert.equal(stateTone("not-applicable"), "muted"); });