// render.channelNames (lane channel-title): the cut's own name for a channel, // reaching every place a clip's channel is printed -- the deck's subtitle, the // stacked deck's source line, a short's end card, the analysis item's // citation -- and, absent, leaving every one of them exactly as it was. // // Run with: pnpm test:scripts import assert from "node:assert/strict"; import test from "node:test"; import { deckSchedule, deckText, resolveDeck, stackedSegmentFields } from "./deck.mjs"; import { endCardSources } from "./outro.mjs"; import { analysisSource } from "./modules/analysis.mjs"; const PALETTE = { bg: "#12101a", fg: "#f4f1ea", muted: "#9a93ad", accent: "#a97bff", amber: "#ffc860" }; const BASE = { width: 1920, height: 1080, fps: 30, transition: 0.5, palette: PALETTE, chrome: { engine: "hyperframes", layout: "deck", deck: {} } }; const PROV = { siteOrigin: "https://example.test", channelSlug: "synth-chan", channel: "Synth Sweep" }; // Two recordings of ONE channel whose records carry two uploader names, and a guest. const CLIPS = [ { id: "c1", type: "clip", channel: "synth-chan", video: "a", start: 60, end: 70, date: "2031-03-01" }, { id: "c2", type: "clip", channel: "synth-chan", video: "b", start: 0, end: 20, date: "2031-04-01" }, { id: "c3", type: "clip", channel: "guest-chan", video: "c", start: 0, end: 6, date: "2031-05-01" }, ]; const METAS = [ { title: "Old stream", uploadDate: "20310301", channel: "SYNTH OLD NAME" }, { title: "New stream", uploadDate: "20310401", channel: "Synth Channel" }, { title: "Guest show", uploadDate: "20310501", channel: "Guest Show" }, ]; const DURS = [10, 20, 6]; const sched = (render) => deckSchedule({ entries: CLIPS, durs: DURS, D: 0.5, render, provenance: PROV, metas: METAS }); test("deckSchedule: render.channelNames absent, empty, or naming no clip's channel -- the schedule is what it was", () => { const before = sched(BASE); assert.deepEqual(sched({ ...BASE, channelNames: {} }), before); assert.deepEqual(sched({ ...BASE, channelNames: { "unused-chan": "Nobody" } }), before); assert.equal(before.multiChannel, true); assert.match(before.segments[0].subtitle, /^SYNTH OLD NAME · /, "the record's name, as before"); }); test("deckSchedule: one channel's name for the whole cut -- both recordings say it, the guest is untouched", () => { const before = sched(BASE); const after = sched({ ...BASE, channelNames: { "synth-chan": "Synth Channel" } }); assert.match(after.segments[0].subtitle, /^Synth Channel · Old stream · /); assert.match(after.segments[1].subtitle, /^Synth Channel · New stream · /); assert.equal(after.segments[2].subtitle, before.segments[2].subtitle); // Only the channel's words moved: the rest of the schedule is the same. const strip = (d) => JSON.stringify(d).replaceAll("SYNTH OLD NAME", "Synth Channel"); assert.equal(strip(after), strip(before)); // A clip's own channelTitle still beats the cut's name. const own = deckSchedule({ entries: [{ ...CLIPS[0], channelTitle: "Clip Own" }, ...CLIPS.slice(1)], durs: DURS, D: 0.5, render: { ...BASE, channelNames: { "synth-chan": "Synth Channel" } }, provenance: PROV, metas: METAS, }); assert.match(own.segments[0].subtitle, /^Clip Own · /); }); test("deckText and stackedSegmentFields take the names; without them they say what they said", () => { const deck = resolveDeck(BASE); const a = deckText(CLIPS[0], METAS[0], PROV, deck, true, ""); assert.deepEqual(deckText(CLIPS[0], METAS[0], PROV, deck, true, "", undefined), a); assert.match(deckText(CLIPS[0], METAS[0], PROV, deck, true, "", { "synth-chan": "Synth Channel" }).subtitle, /^Synth Channel · /); const s = stackedSegmentFields(CLIPS[0], METAS[0], PROV, deck); assert.equal(s.vsource.channel, "SYNTH OLD NAME"); assert.equal(stackedSegmentFields(CLIPS[0], METAS[0], PROV, deck, { "synth-chan": "Synth Channel" }).vsource.channel, "Synth Channel"); }); test("endCardSources: the cut's name for a clip with no schedule part; a clip's own title first; absent as before", () => { const timeline = [ { type: "clip", id: "a", channel: "synth-chan", video: "v1", start: 61 }, { type: "clip", id: "b", channel: "synth-chan", video: "v2", start: 5, channelTitle: "Clip Own" }, { type: "clip", id: "c", channel: "guest-chan", video: "v3", start: 7 }, ]; assert.deepEqual(endCardSources(timeline), [{ date: "", label: "1:01" }, { date: "", label: "Clip Own · 0:05" }, { date: "", label: "0:07" }]); assert.deepEqual(endCardSources(timeline, null, { "synth-chan": "Synth Channel" }), [ { date: "", label: "Synth Channel · 1:01" }, { date: "", label: "Clip Own · 0:05" }, { date: "", label: "0:07" }, ]); }); test("analysisSource: the analysis item's citation names the channel by the cut's name", () => { const manifest = { provenance: PROV, render: { ...BASE }, timeline: [...CLIPS, { type: "analysis", id: "x1", audio: { clip: "c1", start: 62 } }] }; const entry = manifest.timeline[3]; assert.equal(analysisSource(entry, manifest, METAS[0]).parts.channel, "SYNTH OLD NAME"); const named = { ...manifest, render: { ...BASE, channelNames: { "synth-chan": "Synth Channel" } } }; assert.equal(analysisSource(entry, named, METAS[0]).parts.channel, "Synth Channel"); });