import { test, expect } from "@playwright/test"; import { readFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // The deck's claim checks (render.chrome.deck.claims; report-to-video // claims.mjs) in the On-screen section's claims editor, beside the markers: // - add a count claim: the build's validator speaks as it is typed (his // words, the window's dates), the playhead fills its clip and second, a // tally that names no verdict is refused by the writer in the build's words; // - add a goalpost with a second step (he moves it); save; reload; edit; // remove the count -- render.chrome.deck.claims follows each save. // Fixture: e2e/fixtures/knobs-fixture.mjs (knobs-deck-fixture: the deck on, two clips). // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const FIXTURE = path.join(HERE, "..", ".e2e-song"); const DECK_PROJECT = "reports/knobs-deck-fixture"; const DECK_DIR = path.join(FIXTURE, "reports", "knobs-deck-fixture"); type Manifest = { render: Record & { chrome?: { deck?: Record } } }; const readManifest = (): Manifest => JSON.parse(readFileSync(path.join(DECK_DIR, "video.manifest.json"), "utf8")); const claims = () => readManifest().render.chrome?.deck?.claims; test("the claims editor: a count and a goalpost -- validated as typed, the playhead, saved, edited, removed", async ({ page, request }) => { test.setTimeout(150_000); test.skip(!readManifest().render.fontRegular, "the deck refuses to draw without render.fontRegular/fontBold, and make-fixture.mjs found no font on this machine"); // From no claims, whatever an earlier run left. const token = (await (await request.get(`/api/report/chrome?project=${encodeURIComponent(DECK_PROJECT)}`)).json()).token; const reset = await request.put("/api/report/chrome", { data: { project: DECK_PROJECT, token, claims: null } }); expect(reset.ok(), await reset.text()).toBe(true); await page.goto(urls.section(DECK_PROJECT, "onscreen")); const ed = page.getByTestId("claims-editor"); await expect(ed).toBeVisible({ timeout: 30_000 }); await expect(ed).toContainText("No claim checks"); // A count: the validator names what is missing, in the build's words. await ed.getByTestId("claims-add-count").click(); await ed.getByTestId("claim-from-0").fill(""); await ed.getByTestId("claim-to-0").fill(""); const errs = ed.getByTestId("claim-errors-0"); await expect(errs).toContainText("said must be his words, in quotes"); await expect(errs).toContainText("window.from must be a date (YYYY-MM-DD)"); await expect(ed.getByTestId("claims-save")).toBeDisabled(); await ed.getByTestId("claim-said-0").fill("“less than ten” in a year"); await ed.getByTestId("claim-from-0").fill("2025-10-22"); await ed.getByTestId("claim-to-0").fill("2025-01-01"); await expect(errs).toContainText("window.from 2025-10-22 is after its to 2025-01-01"); await ed.getByTestId("claim-to-0").fill("2026-10-22"); await ed.getByTestId("claim-op-0").selectOption("<"); await ed.getByTestId("claim-value-0").fill("10"); // The playhead: the scrubber on the second clip gives its id and a source second inside it. const scrub = page.getByTestId("onscreen-scrubber"); await expect(scrub).toBeVisible({ timeout: 30_000 }); const max = Number(await scrub.getAttribute("max")); await scrub.fill(String(Math.round(max * 0.8 * 100) / 100)); await expect(page.getByTestId("onscreen-current")).toHaveText("c02"); await ed.getByTestId("claim-playhead-0").click(); await expect(ed.getByTestId("claim-at-0")).toHaveValue("c02"); const t = Number(await ed.getByTestId("claim-t-0").inputValue()); expect(t).toBeGreaterThanOrEqual(8.5); expect(t).toBeLessThanOrEqual(12); // A tally that names no verdict: the writer refuses it, in the build's words. await ed.getByTestId("claim-tally-0").fill("Grift"); await expect(errs).toHaveCount(0); await ed.getByTestId("claims-save").click(); await expect(page.getByText(/could not save the claim checks/)).toBeVisible({ timeout: 15_000 }); await expect(page.getByText(/tally "Grift" names no verdict/).first()).toBeVisible(); expect(claims()).toBeUndefined(); await ed.getByTestId("claim-tally-0").fill("CONTRADICTED"); // A goalpost: his first deadline, then the step that moves it. await ed.getByTestId("claims-add-goalpost").click(); await ed.getByTestId("claim-label-1").fill("Pill test results"); await ed.getByTestId("claim-step-at-1-0").selectOption("c01"); await ed.getByTestId("claim-step-t-1-0").fill("4.5"); await ed.getByTestId("claim-step-said-1-0").fill("“3–5 weeks”"); await ed.getByTestId("claim-step-from-1-0").fill("2026-09-23"); await ed.getByTestId("claim-step-add-1").click(); await ed.getByTestId("claim-step-at-1-1").selectOption("c02"); await ed.getByTestId("claim-step-t-1-1").fill("10"); await ed.getByTestId("claim-step-said-1-1").fill("“6–8 weeks”"); await ed.getByTestId("claim-step-from-1-1").fill("2026-10-15"); await ed.getByTestId("claim-step-due0-1-1").fill("P8W"); await ed.getByTestId("claim-step-due1-1-1").fill("P6W"); await expect(ed.getByTestId("claim-errors-1")).toContainText("steps[1].due P8W is longer than P6W: the soonest first"); await ed.getByTestId("claim-step-due0-1-1").fill("P6W"); await ed.getByTestId("claim-step-due1-1-1").fill("P8W"); await expect(ed.getByTestId("claim-errors-1")).toHaveCount(0); await ed.getByTestId("claims-save").click(); await expect.poll(() => claims()).toEqual([ { kind: "count", at: "c02", t, said: "“less than ten” in a year", window: { from: "2025-10-22", to: "2026-10-22" }, tally: "CONTRADICTED", claim: { op: "<", value: 10 } }, { kind: "goalpost", label: "Pill test results", steps: [ { at: "c01", t: 4.5, said: "“3–5 weeks”", from: "2026-09-23", due: ["P3W", "P5W"] }, { at: "c02", t: 10, said: "“6–8 weeks”", from: "2026-10-15", due: ["P6W", "P8W"] }, ], }, ]); // Reloaded, it reads back; the preview's schedule says the due windows. Edit, remove, save. await page.reload(); await expect(page.getByTestId("claim-said-0")).toHaveValue("“less than ten” in a year", { timeout: 30_000 }); await expect(page.getByTestId("claim-record-1")).toContainText("due: 14–28 Oct → 26 Nov–10 Dec", { timeout: 30_000 }); await page.getByTestId("claim-per-0").selectOption("P1W"); await page.getByTestId("claim-remove-0").click(); await page.getByTestId("claim-step-remove-0-0").click(); // The save's re-read of the deck (GET /api/report/chrome) held until the next edit is made: // the file is written at once, and an edit made while the editor reads it back is the // operator's -- the saved value arriving after it must not put the old claims back, nor // the save's end mark it saved. (Under a loaded machine the re-read and the recompose // after it are seconds; an edit there used to be lost and Save stay disabled.) let release!: () => void; const reread = new Promise((r) => (release = r)); await page.route( (u) => u.pathname === "/api/report/chrome", async (route) => { if (route.request().method() === "GET") await reread; await route.continue(); }, ); await page.getByTestId("claims-save").click(); await expect.poll(() => claims()).toEqual([ { kind: "goalpost", label: "Pill test results", steps: [{ at: "c02", t: 10, said: "“6–8 weeks”", from: "2026-10-15", due: ["P6W", "P8W"] }] }, ]); // Removing the last claim removes the key -- removed while the save is still reading back. await page.getByTestId("claim-remove-0").click(); release(); await expect(page.getByTestId("onscreen-note")).toHaveText("saved 1 claim check", { timeout: 30_000 }); // The edit stands: no claim left, unsaved. await expect(ed).toContainText(/(^|\D)0 of \d/); await expect(ed).toContainText("unsaved"); await page.getByTestId("claims-save").click({ timeout: 15_000 }); await expect.poll(() => readManifest().render.chrome?.deck && "claims" in readManifest().render.chrome!.deck!).toBe(false); });