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"; // --------------------------------------------------------------------------- // Marks (plans/clip-marks.md): the clip editor's Marks box, on every clip. // - Add mark at playhead (the button, and Shift+M): a second mark on a clip // with one makes `claims`, under a NEW id (.2) // - the verdicts offered are this cut's words ("Episodes", "Grift") // - a mark that would sit on another's stamp is refused, the file unchanged // - a mark's verdict, its hold, Shift+S on the selected mark // - Remove back to one mark (`claim` again), Clear (none) // - a clip with no marks shows the box, empty // Fixture: e2e/fixtures/marks-fixture.mjs (r001 carries one mark, at 1.2; the // stamp stays 1 s). // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const DIR = path.join(HERE, "..", ".e2e-song", "reports", "marks-fixture"); const PROJECT = "reports/marks-fixture"; type Mark = { id: string; verdict: string; at?: number; hold?: number }; type Entry = { id: string; type: string; claim?: Mark; claims?: Mark[] }; const entry = (id: string): Entry | null => (JSON.parse(readFileSync(path.join(DIR, "video.manifest.json"), "utf8")).timeline as Entry[]).find((e) => e.id === id) ?? null; test("the Marks box: add at the playhead, this cut's verdicts, Shift+M / Shift+S, overlap refused, remove, clear", async ({ page }) => { test.setTimeout(150_000); await page.setViewportSize({ width: 1366, height: 900 }); await page.goto(urls.clipEditorHref(PROJECT, { clip: "r001", mode: "edit" })); await expect(page.locator("[data-clip-editor]")).toHaveAttribute("data-clip-editor", "r001"); await expect(page.locator("[data-editor-player]")).not.toHaveAttribute("data-editor-player", "looking", { timeout: 15_000 }); const box = page.locator('[data-marks="r001"]'); await expect(box).toHaveAttribute("data-mark-count", "1"); await expect(box.locator('[data-mark="r001"]')).toHaveAttribute("aria-selected", "true"); // This cut's words for the verdicts, its own first. const options = await box.locator('[data-mark-verdict="add"] option').allTextContents(); expect(options.slice(0, 2)).toEqual(["Episodes (CORROBORATED)", "Grift (CONTRADICTED)"]); // The button: a second mark at the playhead (the word at 2.4 s), a NEW id. await page.locator('[data-word-t="2.4"]').click(); await box.locator("[data-mark-add]").click(); await expect.poll(() => entry("r001")?.claims?.map((m) => [m.id, m.verdict, m.at])).toEqual([ ["r001", "CORROBORATED", 1.2], ["r001.2", "CORROBORATED", 2.4], ]); expect(entry("r001")?.claim).toBeUndefined(); await expect(box).toHaveAttribute("data-mark-count", "2"); await expect(box.locator('[data-mark="r001.2"]')).toHaveAttribute("aria-selected", "true"); // Its verdict, from this cut's words. await box.locator('[data-mark-verdict="r001.2"]').selectOption("CONTRADICTED"); await expect.poll(() => entry("r001")?.claims?.[1]?.verdict).toBe("CONTRADICTED"); // Shift+M at 1.8: on the first's stamp (it stays 1 s) -- refused, nothing written. await page.locator('[data-word-t="1.8"]').click(); await page.keyboard.press("Shift+M"); await expect(page.locator("[data-editor-error]")).toContainText("overlap"); expect(entry("r001")?.claims?.length).toBe(2); // A shorter hold on the first, then Shift+S moves the SELECTED mark (the first) to 1.8. await box.locator('[data-mark="r001"]').click(); await expect(box.locator('[data-mark="r001"]')).toHaveAttribute("aria-selected", "true"); const hold = box.locator('[data-mark="r001"] [data-knob="hold"]'); await expect(async () => { await hold.fill("0.5"); await hold.press("Enter"); await expect.poll(() => entry("r001")?.claims?.[0]?.hold, { timeout: 2000 }).toBe(0.5); }).toPass({ timeout: 15_000 }); await page.locator('[data-word-t="1.8"]').click(); await page.keyboard.press("Shift+S"); await expect.poll(() => entry("r001")?.claims?.[0]?.at).toBe(1.8); // S and M alone are still Split and Merge: Shift did neither. expect((JSON.parse(readFileSync(path.join(DIR, "video.manifest.json"), "utf8")).timeline as Entry[]).filter((e) => e.type === "clip").map((e) => e.id)).toEqual(["r001", "r002", "r003"]); // Remove the second: one mark, written as `claim` again. await box.locator('[data-mark-remove="r001.2"]').click(); await expect.poll(() => entry("r001")?.claim).toEqual({ id: "r001", verdict: "CORROBORATED", at: 1.8, hold: 0.5 }); expect(entry("r001")?.claims).toBeUndefined(); // Shift+M on a clip with no marks: its first, under the clip's id. await page.locator('[data-editor-row="r002"]').click(); const box2 = page.locator('[data-marks="r002"]'); await expect(box2).toHaveAttribute("data-mark-count", "0"); await page.locator('[data-word-t="4.71"]').click(); await box2.locator('[data-mark-verdict="add"]').selectOption("CONTRADICTED"); await page.keyboard.press("Shift+M"); await expect.poll(() => entry("r002")?.claim).toEqual({ id: "r002", verdict: "CONTRADICTED", at: 4.71 }); // Clear: no marks. await box2.locator("[data-marks-clear]").click(); await expect.poll(() => entry("r002")?.claim ?? entry("r002")?.claims ?? null).toBeNull(); await expect(box2).toHaveAttribute("data-mark-count", "0"); });