// The sectionEnter rule, against the shape of the one manifest that uses it. import assert from "node:assert/strict"; import test from "node:test"; import { applySectionEnter, sectionEnterFlags, usesSectionEnter } from "./sections.mjs"; const clip = (id, section, extra = {}) => ({ type: "clip", id, section, ...extra }); test("a clip enters a section when its section differs from the previous clip's", () => { const tl = [ { type: "card", id: "t0" }, clip("a", 1), clip("b", 1), { type: "card", id: "mid" }, clip("c", 1), clip("d", 2), clip("e"), clip("f", 2), { type: "scroll", id: "s" }, ]; assert.deepEqual(sectionEnterFlags(tl), [false, true, false, false, false, true, false, true, false]); }); test("applySectionEnter leaves a timeline that never used the flag alone", () => { const tl = [clip("a", 1), clip("b", 2)]; assert.deepEqual(applySectionEnter(tl), []); assert.equal(usesSectionEnter(tl), false); assert.equal("sectionEnter" in tl[0], false); }); test("applySectionEnter is the identity on a timeline already in order, and fixes a move", () => { const tl = [clip("a", 1, { sectionEnter: true }), clip("b", 1), clip("c", 2, { sectionEnter: true }), clip("d", 2)]; assert.deepEqual(applySectionEnter(tl), []); // d moved to the front: d enters 2, a enters 1, c no longer enters (b was 1, c is 2 -> still enters) const moved = [tl[3], tl[0], tl[1], tl[2]]; assert.deepEqual(applySectionEnter(moved).sort(), ["d"]); assert.equal(moved[0].sectionEnter, true); assert.equal(moved[3].sectionEnter, true); // and moving it back removes the flag again (deleted, never written false) const back = [moved[1], moved[2], moved[3], moved[0]]; assert.deepEqual(applySectionEnter(back), ["d"]); assert.equal("sectionEnter" in back[3], false); });