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 past twelve markers, and subsections (2026-11-01): the On-screen // Markers editor adds a fourteenth (the cap is 32, marker-limits.mjs), a row's // "sub" makes it a subsection (`level: 2`) and the save writes it; a // subsection as the cut's first marker is refused before a save, and by the // route in the build's words. // Fixture: e2e/fixtures/knobs-fixture.mjs (markers-cap-fixture, sixteen clips). // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const PROJECT = "reports/markers-cap-fixture"; const DIR = path.join(HERE, "..", ".e2e-song", "reports", "markers-cap-fixture"); type Marker = { after: string; label?: string; level?: number }; const markers = (): Marker[] => JSON.parse(readFileSync(path.join(DIR, "video.manifest.json"), "utf8")).render.chrome?.deck?.markers ?? []; const tokenOf = async (request: import("@playwright/test").APIRequestContext) => (await (await request.get(`/api/report/chrome?project=${encodeURIComponent(PROJECT)}`)).json()).token; test("the Markers editor: fourteen markers, two of them subsections; a leading subsection refused", async ({ page, request }) => { test.setTimeout(150_000); const fonts = JSON.parse(readFileSync(path.join(DIR, "video.manifest.json"), "utf8")).render.fontRegular; test.skip(!fonts, "the deck refuses to draw without render.fontRegular/fontBold, and make-fixture.mjs found no font on this machine"); const reset = await request.put("/api/report/chrome", { data: { project: PROJECT, token: await tokenOf(request), markers: [], markerLayout: null } }); expect(reset.ok(), await reset.text()).toBe(true); await page.setViewportSize({ width: 1366, height: 900 }); await page.goto(urls.section(PROJECT, "onscreen")); const ed = page.getByTestId("markers-editor"); await expect(ed).toBeVisible({ timeout: 30_000 }); // Past the old twelve: fourteen rows, each after the next clip; still room for more. for (let i = 0; i < 14; i += 1) { await ed.getByTestId("markers-add").click(); await ed.getByTestId(`marker-label-${i}`).fill(`Part ${i + 1}`); } await expect(ed).toContainText("14 of 32"); await expect(ed.getByTestId("markers-add")).toBeEnabled(); await expect(ed.getByTestId("marker-after-13")).toHaveValue("m14"); // Two subsections. await ed.getByTestId("marker-sub-3").check(); await ed.getByTestId("marker-sub-7").check(); await expect(ed.getByTestId("marker-row-3")).toHaveAttribute("data-level", "2"); await expect(ed.getByTestId("markers-level-refused")).toHaveCount(0); await ed.getByTestId("markers-save").click(); await expect.poll(() => markers().length, { timeout: 30_000 }).toBe(14); expect(markers().map((m, i) => [i, m.level ?? 1]).filter(([, l]) => l === 2)).toEqual([[3, 2], [7, 2]]); expect(markers()[3]).toEqual({ after: "m04", label: "Part 4", level: 2 }); // A subsection as the cut's first marker: said, and the save held. await expect(ed.getByTestId("marker-row-3")).toHaveAttribute("data-level", "2", { timeout: 30_000 }); await ed.getByTestId("marker-sub-0").check(); await expect(ed.getByTestId("markers-level-refused")).toContainText("a subsection needs a section before it"); await expect(ed.getByTestId("markers-save")).toBeDisabled(); await ed.getByTestId("marker-sub-0").uncheck(); await expect(ed.getByTestId("markers-level-refused")).toHaveCount(0); await expect(ed.getByTestId("markers-save")).toBeEnabled(); // The route refuses it in the build's words, and writes nothing. const before = markers(); const r = await request.put("/api/report/chrome", { data: { project: PROJECT, token: await tokenOf(request), markers: [{ after: "m02", label: "Sub", level: 2 }, { after: "m05", label: "Section" }] }, }); expect(r.ok()).toBe(false); expect(await r.text()).toContain("is a subsection (level 2) with no section before it"); expect(markers()).toEqual(before); });