import test from "node:test"; import assert from "node:assert/strict"; import { createState, selectState, isCaptureMode, getCaptureSection, } from "../src/scripts/state.mjs"; test("initial product illustrations remain ready for image capture", () => { assert.deepEqual(createState(), { filter: "waiting", context: "source", }); assert.notEqual(createState(), createState()); }); test("selections return a new state without changing other illustrations", () => { const original = Object.freeze(createState()); for (const [key, values] of Object.entries({ filter: ["all", "waiting", "connections"], context: ["source", "work", "action"], })) { for (const value of values) { const next = selectState(original, key, value); assert.deepEqual(next, { ...original, [key]: value }); assert.notEqual(next, original); } } assert.equal(original.filter, "waiting"); }); test("unknown keys and unsupported values cannot enter product state", () => { const original = createState(); for (const [key, value] of [ ["view", "grid"], ["filter", "review"], ["step", "3"], ["constructor", "bad"], ["__proto__", "bad"], ]) { assert.deepEqual(selectState(original, key, value), original); } }); test("only the explicit capture flag enables a still presentation", () => { assert.equal(isCaptureMode("?capture=1"), true); for (const query of ["", "?capture=0", "?capture=true", "?other=1"]) { assert.equal(isCaptureMode(query), false); } }); test("isolated capture only accepts known sections with explicit capture mode", () => { for (const section of [ "hero", "workflow", "video", "selector", "agent", "prepared", "context", "progression", "stats", "modules", "closing", ]) { assert.equal(getCaptureSection(`?capture=1§ion=${section}`), section); } for (const search of [ "", "?section=hero", "?capture=0§ion=hero", "?capture=1", "?capture=1§ion=unknown", "?capture=1§ion=views", "?capture=1§ion=recurring", ]) { assert.equal(getCaptureSection(search), null); } });