// The module panel's single-layer preview: composeLayerPreviews (onscreen.mjs) // and the files route's layer names (serve.mjs layerPreviewOf). import { test } from "node:test"; import assert from "node:assert/strict"; import path from "node:path"; import { composeLayerPreviews } from "./onscreen.mjs"; import { layerPreviewOf, layerPreviewSrc, previewDirFor } from "./serve.mjs"; const palette = { bg: "#000000", fg: "#ffffff", muted: "#888888", accent: "#ff0000" }; const render = { width: 1920, height: 1080, fps: 30, palette, chrome: { engine: "hyperframes", layout: "deck", pair: { pairs: [{ then: { clip: "a", date: "2012" }, now: { clip: "b", date: "2026" } }] }, chapter: { list: [{ at: "b", title: "Two" }] }, }, }; const schedule = { kind: "deck", fps: 30, total: 20, transition: 0.5, segments: [["a", 0, 10], ["b", 10, 20]].map(([id, start, end]) => ({ id, type: "clip", start, end, duration: end - start })), }; test("each layer composed alone: a whole page once, a window page per window, a part as the deck's, an absent one off", async () => { const calls = []; const compose = async (args) => { calls.push(args); const name = args.region === "chapter" ? `chapter-preview-${args.segment}` : `${args.region}-preview`; return { projDir: path.join("/p/out/sourced/chrome", name) }; }; const out = await composeLayerPreviews({ dir: "/p", manifestFile: "/p/video.manifest.json" }, "sourced", schedule, ["pair", "chapter", "counter", "status", "nope"], render, { compose }); const by = Object.fromEntries(out.map((l) => [l.id, l])); assert.equal(by.pair.name, "pair-preview"); assert.equal(by.pair.geometry.width > 0, true); assert.deepEqual(by.chapter.windows.map((w) => [w.segment, w.from, w.name]), [["b", 10, "chapter-preview-b"]]); assert.equal(by.counter.region, "deck"); assert.match(by.status.off, /status/); assert.match(by.nope.error, /no module/); assert.deepEqual(calls.map((c) => [c.region, c.preview, c.segment ?? null]), [["pair", true, null], ["chapter", true, "b"]]); assert.ok(calls.every((c) => c.schedule === schedule && c.manifestPath === "/p/video.manifest.json")); }); test("the files route serves a layer's project by its name, a window's only for the cut's own entry", async () => { assert.equal(layerPreviewOf("pair-preview"), "pair-preview"); // Every module Play draws as a layer is served by the files route (its iframe would be a 404 otherwise). const { playModules } = await import("umtool-report-to-video/modules"); for (const m of playModules()) assert.equal(layerPreviewOf(`${m.region}-preview`), `${m.region}-preview`, m.id); assert.equal(layerPreviewOf("chapter-preview-b", ["a", "b"]), "chapter-preview-b"); assert.equal(layerPreviewOf("chapter-preview-zz", ["a", "b"]), null); assert.equal(layerPreviewOf("chapter-preview-..", [".."]), null); // The gap mark's windows are its marks (`.g`), served for the cut's own entries only. assert.equal(layerPreviewOf("gap-cue-preview-b.g0", ["a", "b"]), "gap-cue-preview-b.g0"); assert.equal(layerPreviewOf("gap-cue-preview-b.g12", ["b"]), "gap-cue-preview-b.g12"); assert.equal(layerPreviewOf("gap-cue-preview-zz.g0", ["a", "b"]), null); assert.equal(layerPreviewOf("gap-cue-preview-b", ["b"]), null, "a mark id, not an entry's"); assert.equal(layerPreviewOf("deck-preview"), null); assert.deepEqual(previewDirFor("/p", "sourced", ["status-preview", "index.html"], []), { dir: "/p/out/sourced/chrome/status-preview", rest: ["index.html"] }); // The deck's own preview, as it always was. assert.equal(previewDirFor("/p", "sourced", ["index.html"], []).dir, "/p/out/sourced/chrome/deck-preview"); assert.equal(layerPreviewSrc("reports/x", "sourced", "pair-preview"), "/api/report/chrome/files/" + layerPreviewSrc("reports/x", "sourced", "pair-preview").split("/api/report/chrome/files/")[1]); }); // THE PLAY LAYERS (the module contract's `play`): what the full preview -- // Play the cut, the clip editor's live preview -- returns beside the deck. test("the full preview's play layers: every `play` module the cut draws, by z, with geometry, src and its windows", async () => { const { composePlayLayers } = await import("./onscreen.mjs"); const { playModules } = await import("umtool-report-to-video/modules"); // The contract: the story modules (and the other overlays with a page of their own) declare it; the // deck, the feed, the popup posts, the stamps and the finale are still drawn by their own paths. const ids = playModules().map((m) => m.id); for (const id of ["chapter", "pair", "status"]) assert.ok(ids.includes(id), id); for (const id of ["shell", "feed", "popup-posts", "stamp", "finale"]) assert.ok(!ids.includes(id), id); const story = { ...render, chrome: { ...render.chrome, chapter: { list: [{ at: "b", title: "Two" }], seconds: 3 }, status: { items: [{ item: "The lawsuit", announced: { clip: "a", date: "2019-06-01" }, outcome: "no follow-up found" }] }, }, }; const calls = []; const compose = async (args) => { calls.push(args); const name = args.region === "chapter" ? `chapter-preview-${args.segment}` : `${args.region}-preview`; return { projDir: path.join("/p/out/sourced/chrome", name) }; }; const out = await composePlayLayers({ dir: "/p", manifestFile: "/p/video.manifest.json" }, "sourced", schedule, story, { compose, srcOf: (name) => `/files/${name}/index.html`, }); assert.deepEqual(out.map((l) => l.id), ["pair", "status", "chapter"]); assert.deepEqual(out.map((l) => l.z), [...out.map((l) => l.z)].sort((x, y) => x - y)); const by = Object.fromEntries(out.map((l) => [l.id, l])); for (const l of out) { assert.equal(l.clock, "cut"); assert.equal(l.ready, `${l.region}:ready`); assert.ok(l.geometry.width > 0 && l.geometry.height > 0, l.id); } // A whole-cut page: one src, up for the whole cut. assert.equal(by.pair.src, "/files/pair-preview/index.html"); assert.deepEqual([by.pair.from, by.pair.to], [0, 20]); assert.equal(by.status.src, "/files/status-preview/index.html"); // A window page: the first `seconds` of the clip it opens, in cut seconds, its own src. assert.equal(by.chapter.windows.length, 1); const w = by.chapter.windows[0]; assert.equal(w.segment, "b"); assert.equal(w.from, 10); assert.ok(Math.abs(w.to - 13) < 0.05, `to ${w.to}`); assert.equal(w.src, "/files/chapter-preview-b/index.html"); assert.deepEqual(calls.map((c) => [c.region, c.preview, c.segment ?? null]), [["pair", true, null], ["status", true, null], ["chapter", true, "b"]]); // A cut that draws none of them: nothing composed, nothing returned. const none = await composePlayLayers({ dir: "/p" }, "sourced", schedule, { ...render, chrome: { engine: "hyperframes", layout: "deck" } }, { compose, srcOf: (n) => n }); assert.deepEqual(none, []); });