import test from "node:test"; import assert from "node:assert/strict"; import { SONG_FLOW, SONG_PIECE_TAB_IDS, SONG_STEPS, bucketOfSongStep, songStepOf, songSteps, songTabOf, songTabOfNote, songTabOfSection, } from "./song-tabs.mjs"; import { STAGE_STEPS, pieceSteps, stageOfPiece, stepOfPiece } from "./tabs.mjs"; import { STAGES, stageBar, stageOf } from "../work/facets.mjs"; const states = (steps) => steps.map((s) => s.state); test("a song piece: five tabs, Overview first; every section on one of them", () => { assert.deepEqual(SONG_PIECE_TAB_IDS, ["overview", "cuts", "spec", "cover", "notes"]); assert.equal(songTabOfSection("cuts"), "cuts"); assert.equal(songTabOfSection("unattributed"), "cuts"); assert.equal(songTabOfSection("bench"), "cuts"); assert.equal(songTabOfSection("operations"), "spec"); assert.equal(songTabOfSection("plans"), "spec"); assert.equal(songTabOfSection("faces"), "cover"); assert.equal(songTabOfSection("notes"), "notes"); assert.equal(songTabOfSection("slots"), "overview"); assert.equal(songTabOfSection("tools"), "overview"); assert.throws(() => songTabOfSection("timeline"), /no section "timeline" on a song piece/); }); test("a song piece's address picks the tab: ?tab=, else a note's target where it is drawn, else the Overview", () => { assert.equal(songTabOf({}), "overview"); assert.equal(songTabOf({ tab: "spec" }), "spec"); assert.equal(songTabOf({ tab: "build" }), "overview"); assert.equal(songTabOf({ tab: "cover", note: "song" }), "cover"); assert.equal(songTabOf({ note: "song" }), "notes"); for (const t of ["cut:vertical", "file:wide.mp4", "file:variants/wide-nokit.mp4", "moment:wide.mp4@2.00", "source:abc123", "clip:abc@1.5"]) { assert.equal(songTabOfNote(t), "cuts", t); assert.equal(songTabOf({ note: t }), "cuts", t); } assert.equal(songTabOf({ note: "plan:alpha.plan.json" }), "spec"); assert.equal(songTabOf({ note: "thumb:alpha-1" }), "cover"); assert.equal(songTabOf({ note: "n-1234" }), "overview"); }); test("a song walks Spec → Cuts → Done by the one stage rule", () => { assert.deepEqual(SONG_STEPS.map((s) => s.label), ["Spec", "Cuts", "Done"]); // Scaffolded: a spec.json, no cut yet. assert.deepEqual(states(songSteps({ reached: { spec: true }, lifecycle: "active" })), ["current", "todo", "todo"]); // Nothing at all (a directory with only verdicts.json): the Spec is where it starts. assert.deepEqual(states(songSteps({ reached: {}, lifecycle: "active" })), ["current", "todo", "todo"]); // Some cuts built. assert.deepEqual(states(songSteps({ reached: { spec: true, cuts: true }, lifecycle: "active" })), ["done", "current", "todo"]); // Cuts with no spec.json: the Spec is to do, and says why. const nospec = songSteps({ reached: { cuts: true }, lifecycle: "active" }); assert.deepEqual(states(nospec), ["todo", "current", "todo"]); assert.equal(nospec[0].title, "no spec.json"); // Every cut built (the derived `shipped`): at Done -- a suggestion, not the lifecycle. assert.deepEqual(states(songSteps({ reached: { spec: true, cuts: true, done: true }, lifecycle: "active" })), ["done", "done", "current"]); // Marked done: every stage done. assert.deepEqual(states(songSteps({ reached: { cuts: true }, lifecycle: "done" })), ["done", "done", "done"]); // The shared rule switches on the flow the kind declares. assert.deepEqual(pieceSteps({ kind: SONG_FLOW, reached: { spec: true, cuts: true }, lifecycle: "active" }).map((s) => s.id), ["spec", "cuts", "done"]); // ...and the four-stage pieces are untouched by it. assert.deepEqual(pieceSteps({ kind: "project", reached: { video: true }, lifecycle: "active" }).map((s) => s.id), STAGE_STEPS.map((s) => s.id)); }); test("the song's stepper and Work's stage facet give the same answer", () => { for (const reached of [ { spec: true }, { spec: true, cuts: true }, { cuts: true }, { spec: true, cuts: true, done: true }, { research: false, article: false, video: true, deliver: true, spec: true, cuts: true, done: true }, ]) { const piece = { kind: SONG_FLOW, reached }; const current = pieceSteps({ ...piece, lifecycle: "active" }).find((s) => s.state === "current").id; assert.equal(songStepOf(piece), current); assert.equal(stepOfPiece(piece), current); // Work's bucket is the one the song's current step stands in for -- from the piece page's rule. const bucket = stageOf({ kind: SONG_FLOW, stage: "built", looksDone: [], reached }); assert.equal(bucket, bucketOfSongStep(current)); assert.equal(stageOfPiece(piece), bucket); assert.ok(STAGES.includes(bucket)); // Work's bar is the song's own: three steps, the current one lit, its word. const bar = stageBar(piece, bucket); assert.equal(bar.steps, 3); assert.equal(SONG_STEPS[bar.step - 1].id, current); assert.equal(bar.label, SONG_STEPS[bar.step - 1].label.toLowerCase()); } assert.equal(stageOf({ kind: SONG_FLOW, stage: "draft", looksDone: [], reached: { spec: true } }), "article"); assert.equal(stageOf({ kind: SONG_FLOW, stage: "built", looksDone: [], reached: { spec: true, cuts: true } }), "video"); assert.equal(stageOf({ kind: SONG_FLOW, stage: "shipped", looksDone: ["x: every cut shipped"], reached: { cuts: true, done: true } }), "deliver"); // A four-stage piece's bar is unchanged: four bars at its bucket, the caller's word. assert.deepEqual(stageBar({ kind: "project", reached: { video: true } }, "video"), { step: 3, steps: 4, label: null }); });