// The join preview's cut (release 38 lane E, join-preview.mjs). // // Run with: pnpm test:scripts import assert from "node:assert/strict"; import test from "node:test"; import { JOIN_PREVIEW_SECONDS, joinPreviewTimeline } from "./join-preview.mjs"; const clip = (id, a, b, extra = {}) => ({ type: "clip", id, channel: "ch", video: "v1", start: a - 1.5, end: b + 1.5, cutStart: a, cutEnd: b, ...extra }); const M = (timeline, render = {}) => ({ render: { transition: 0.22, transitionStyle: "blurslide", ...render }, timeline }); test("four clips from the first: each keeps the last seconds of its cut, the last its first seconds; cards left out", () => { const tl = [{ type: "card", id: "t0" }, clip("a", 10, 20), clip("b", 30, 32), clip("c", 40, 50, { muteFrom: 41 }), clip("d", 60, 70), clip("e", 80, 90)]; const out = joinPreviewTimeline(M(tl)); assert.deepEqual(out.map((e) => [e.id, e.cutStart, e.cutEnd, e.start, e.end]), [ ["a", 20 - JOIN_PREVIEW_SECONDS, 20, 8.5, 21.5], ["b", 30, 32, 28.5, 33.5], ["c", 47, 50, 38.5, 51.5], ["d", 60, 63, 58.5, 71.5], ]); assert.equal(out[2].muteFrom, 41, "a mute mark before the shortened cut stays (it mutes all of it, as in the cut)"); // From a named clip. assert.deepEqual(joinPreviewTimeline(M(tl), { from: "c" }).map((e) => e.id), ["c", "d", "e"]); // A clip with no cut fields is shortened the same way, inside its edges. const plain = joinPreviewTimeline(M([{ type: "clip", id: "x", start: 0, end: 10 }, { type: "clip", id: "y", start: 20, end: 30 }])); assert.deepEqual(plain.map((e) => [e.cutStart, e.cutEnd]), [[7, 10], [20, 23]]); }); test("refused: a deck, a montage, hard cuts, fewer than two clips, an unknown clip", () => { const tl = [clip("a", 10, 20), clip("b", 30, 40)]; assert.throws(() => joinPreviewTimeline(M(tl, { chrome: { engine: "hyperframes", layout: "deck" } })), /plain cut's: this one is drawn under the deck/); assert.throws(() => joinPreviewTimeline(M(tl, { montage: {} })), /a montage cuts to its phrases/); assert.throws(() => joinPreviewTimeline(M(tl, { transition: 0 })), /no join to preview/); assert.throws(() => joinPreviewTimeline(M(tl), { from: "b" }), /needs two clips/); assert.throws(() => joinPreviewTimeline(M(tl), { from: "zz" }), /no clip zz/); });