import { test, expect, type Page } from "@playwright/test"; import { readFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // Play and the clip bench as ONE app, the reel strip's zoom and drag, the // working cut's name (operator, 1 Nov 2026; umtool/docs/knobs.md, "Play the // cut"; clip-bench.md, "Walking the cut"). // // play-walk-fixture (WRITABLE, make-fixture.mjs): play-cut-fixture's cut on // vid1 with two sections -- §0 c01 c02 | §1 "Two" k01 c03 c04 -- and two // whole-cut takes made from the manifest as written: draft-1 (the latest, so // the draft's parent) and draft-0 (older, picked). Play plays THE DRAFT (the // manifest) by default (L3). Every write here is undone before the test // ends, except the stamp moved last. // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const FIXTURE = path.join(HERE, "..", ".e2e-song"); const P = "reports/play-walk-fixture"; const DIR = path.join(FIXTURE, "reports", "play-walk-fixture"); type Entry = { id: string; type: string; start?: number; end?: number; claim?: { at?: number } }; const manifest = () => JSON.parse(readFileSync(path.join(DIR, "video.manifest.json"), "utf8")) as { timeline: Entry[]; render: { chrome: { deck: { markers: { after: string }[] } } } }; const order = () => manifest().timeline.map((e) => e.id).join(" "); const afters = () => manifest().render.chrome.deck.markers.map((m) => m.after).join(" "); const root = (page: Page) => page.locator("[data-play-cut]"); const tNow = async (page: Page) => Number(await root(page).getAttribute("data-play-t")); const ready = async (page: Page) => { await expect(root(page)).toHaveAttribute("data-play-state", "paused"); await expect(root(page)).toHaveAttribute("data-play-edges", "render", { timeout: 30_000 }); }; /** The cell's grip band, and a point `frac` of the way across a cell. */ const cellAt = async (page: Page, id: string, frac = 0.5) => { const b = (await page.locator(`[data-play-row="${id}"]`).boundingBox())!; return { x: b.x + b.width * frac, grip: b.y + 6, body: b.y + b.height - 8 }; }; test.beforeEach(() => { test.setTimeout(120_000); }); test("the draft plays by default, named by its parent; a version plays read-only, switched without the URL write cancelling it", async ({ page }) => { await page.setViewportSize({ width: 1366, height: 1000 }); await page.goto(urls.playHref(P)); await ready(page); // No draft pointer yet: the draft's parent is the newest working take, draft-1, and nothing changed since. await expect(page.locator("[data-play-draft]")).toHaveAttribute("data-play-draft", "draft-1"); await expect(page.locator("[data-play-draft]")).toContainText("Draft · from draft-1 · no edits"); await expect(root(page)).toHaveAttribute("data-play-cut", ""); await expect(page.locator('[data-play-take=""]')).toContainText("the working draft"); // The pick (draft-0, from before) is said small, beside: secondary. await expect(page.locator('[data-play-picked="draft-0"]')).toContainText("picked: draft-0"); await page.screenshot({ path: test.info().outputPath("play-draft-label.png") }); // A version link clicked WHILE PLAYING: Play's once-a-second URL write used to cancel it. await page.locator("[data-play-toggle]").click(); await expect.poll(() => tNow(page), { timeout: 20_000 }).toBeGreaterThan(0.3); await page.locator('[data-play-take-link="draft-0"]').click(); await expect(root(page)).toHaveAttribute("data-play-cut", "draft-0", { timeout: 20_000 }); await expect(page).toHaveURL(/take=draft-0/); await expect(page.locator('[data-play-take="draft-0"]')).toContainText("read-only"); await expect(page.locator('[data-play-open-draft="draft-0"]')).toHaveAttribute("href", "/projects/reports/play-walk-fixture/takes/draft-0/open"); // Read-only: Edit goes by Open in draft. await expect(page.locator("[data-play-edit]")).toHaveAttribute("data-play-edit", "open"); // Back to the draft. await page.locator("[data-play-draft-link]").click(); await expect(root(page)).toHaveAttribute("data-play-cut", "", { timeout: 20_000 }); await expect(page).not.toHaveURL(/take=/); }); test("the reel strip zooms like the bench waveform: at the pointer, keys, to the clip and the section, an overview", async ({ page }) => { await page.setViewportSize({ width: 1366, height: 1000 }); await page.goto(urls.playHref(P)); await ready(page); const strip = page.locator("[data-play-strip]"); await expect(strip).toHaveAttribute("data-strip-zoom", "fit"); await expect(page.locator("[data-strip-overview]")).toHaveCount(0); // Ctrl + wheel at c03: zoomed, and c03 is still under the pointer. const c = await cellAt(page, "c03"); await page.mouse.move(c.x, c.body); await page.keyboard.down("Control"); await page.mouse.wheel(0, -400); await page.keyboard.up("Control"); await expect(strip).not.toHaveAttribute("data-strip-zoom", "fit"); const c2 = await cellAt(page, "c03"); const b3 = (await page.locator('[data-play-row="c03"]').boundingBox())!; expect(c.x).toBeGreaterThanOrEqual(b3.x - 2); expect(c.x).toBeLessThanOrEqual(b3.x + b3.width + 2); expect(b3.width).toBeGreaterThan(0); expect(c2.x).toBeGreaterThan(0); // The overview shows the whole cut under a zoomed strip; f fits again. await expect(page.locator("[data-strip-overview] [data-zoom-overview]")).toBeVisible(); await page.locator("body").press("f"); await expect(strip).toHaveAttribute("data-strip-zoom", "fit"); // z zooms in at the playhead; Zoom to section shows §1 (k01 c03 c04) and not c01. await page.locator('[data-play-row="c03"]').press("Enter"); await page.locator("body").press("z"); await expect(strip).not.toHaveAttribute("data-strip-zoom", "fit"); await page.locator("body").press("f"); await page.locator("[data-zoom-section]").click(); await expect(page.locator('[data-play-row="c01"]')).toHaveCount(0); await expect(page.locator('[data-play-row="c04"]')).toHaveCount(1); // Zoomed, a cell names its section; the seam names it above. await expect(page.locator('[data-play-row="c03"]')).toHaveAttribute("aria-label", /§1 Two/); await page.screenshot({ path: test.info().outputPath("strip-zoomed.png") }); // F: the clip on screen fills the strip. await page.locator("body").press("F"); const z = (await strip.getAttribute("data-strip-zoom"))!.split("-").map(Number); expect(z[1] - z[0]).toBeLessThan(4); await page.locator("body").press("f"); }); test("drag to reorder: across a seam into §0, the drop's section said, one write, Undo; a drop that empties a section is refused; Alt+→", async ({ page }) => { await page.setViewportSize({ width: 1366, height: 1000 }); const before = order(); expect(before).toBe("c01 c02 k01 c03 c04"); expect(afters()).toBe("c02"); await page.goto(urls.playHref(P)); await ready(page); // The playhead on c02: it stays on c02 through the move. await page.locator('[data-play-row="c02"]').press("Enter"); await expect(root(page)).toHaveAttribute("data-play-item", "c02"); // Grab c04 by its grip and drag it onto the right half of c01: after c01, in §0. const from = await cellAt(page, "c04"); const to = await cellAt(page, "c01", 0.75); await page.mouse.move(from.x, from.grip); await page.mouse.down(); await page.mouse.move(from.x - 10, from.grip, { steps: 2 }); await page.mouse.move(to.x, to.body, { steps: 8 }); await expect(page.locator("[data-strip-ghost]")).toHaveAttribute("data-strip-ghost", "c04"); await expect(page.locator("[data-strip-drop]")).toHaveAttribute("data-strip-drop-section", "0"); await expect(page.locator("[data-strip-drop]")).toContainText("c04 → §0 (the opening), after c01"); await expect(page.locator("[data-strip-insert]")).toHaveAttribute("data-strip-insert", "c02"); await page.screenshot({ path: test.info().outputPath("strip-mid-drag.png") }); await page.mouse.up(); await expect(page.locator('[data-strip-toast="done"]')).toContainText("Moved: c04 → §0 (the opening), after c01"); await expect.poll(order).toBe("c01 c04 c02 k01 c03"); expect(afters()).toBe("c02"); await expect(page.locator('[data-play-row="c04"]')).toHaveAttribute("data-play-row-section", "0", { timeout: 20_000 }); await expect(root(page)).toHaveAttribute("data-play-item", "c02"); // The draft's name counts the edit. await expect(page.locator("[data-play-draft]")).toContainText("Draft · from draft-1 · 1 edit", { timeout: 20_000 }); await page.screenshot({ path: test.info().outputPath("strip-undo-toast.png") }); // §1 is down to c03: dragging it into §0 would leave §1 with no clip -- refused before any write. const c3 = await cellAt(page, "c03"); const c1 = await cellAt(page, "c01", 0.25); await page.mouse.move(c3.x, c3.grip); await page.mouse.down(); await page.mouse.move(c3.x - 10, c3.grip, { steps: 2 }); await page.mouse.move(c1.x, c1.body, { steps: 8 }); await expect(page.locator("[data-strip-drop]")).toHaveAttribute("data-strip-drop-refused", ""); await page.mouse.up(); await expect(page.locator("[data-strip-refusal]")).toContainText("§1 Two would have no clip left"); expect(order()).toBe("c01 c04 c02 k01 c03"); // Undo: exactly the drop. await page.locator("[data-strip-undo]").click(); await expect(page.locator('[data-strip-toast="undone"]')).toBeVisible(); await expect.poll(order).toBe(before); await expect(page.locator('[data-play-row="c04"]')).toHaveAttribute("data-play-row-section", "1", { timeout: 20_000 }); // Esc cancels a drag: nothing written. const f4 = await cellAt(page, "c04"); await page.mouse.move(f4.x, f4.grip); await page.mouse.down(); await page.mouse.move(f4.x - 120, f4.body, { steps: 6 }); await page.keyboard.press("Escape"); await page.mouse.up(); expect(order()).toBe(before); // The keyboard: Alt+→ on c01 moves it one place (after c02, still §0); Undo. await page.locator('[data-play-row="c01"]').focus(); await page.keyboard.press("Alt+ArrowRight"); await expect.poll(order).toBe("c02 c01 k01 c03 c04"); expect(afters()).toBe("c01"); await expect(page.locator('[data-strip-toast="done"]')).toBeVisible(); await page.locator("[data-strip-undo]").click(); await expect.poll(order).toBe(before); expect(afters()).toBe("c02"); }); test("Play → Edit → the bench in place → Back: the same clip, second and take, no second Play in the history", async ({ page }) => { await page.setViewportSize({ width: 1366, height: 1000 }); await page.goto(urls.playHref(P)); await ready(page); // Into c02, a little way in (a click on a cell's body scrubs there). const mid = await cellAt(page, "c02", 0.6); await page.mouse.click(mid.x, mid.body); await expect(root(page)).toHaveAttribute("data-play-item", "c02"); const t0 = await tNow(page); const item = "c02"; const hist = await page.evaluate(() => history.length); // The deck settled first (composed, or none): the check below is that it is not composed AGAIN. Since the // fixture's "Seizures" composes (fitTallyLabel; before, its chrome was refused at once), composing takes a moment. await expect(root(page)).not.toHaveAttribute("data-play-compose", "composing", { timeout: 60_000 }); const composed = (await root(page).getAttribute("data-play-compose"))!; await page.locator("[data-play-edit]").click(); // In place: Play hidden (kept), the bench on the clip, its address the bench's. await expect(page.locator(`[data-cut-app-bench="${item}"] [data-bench-shell="clip"]`)).toBeVisible({ timeout: 20_000 }); await expect(page.locator("[data-cut-app-play]")).toHaveAttribute("data-cut-app-play", "hidden"); await expect(page).toHaveURL(new RegExp(`/clip/${item}\\?from=play.*order=cut`)); // The bench names the draft it edits: from the latest take, no edits since. await expect(page.locator(`[data-cut-app-bench="${item}"] [data-working-cut]`)).toHaveAttribute("data-working-cut", "draft-1"); await page.screenshot({ path: test.info().outputPath("app-bench-in-place.png") }); // n: the cut's next clip (the reel strip's order), in place. const next = "c03"; await page.locator("body").press("n"); await expect(page.locator(`[data-cut-app-bench="${next}"]`)).toBeVisible({ timeout: 20_000 }); await expect(page).toHaveURL(new RegExp(`/clip/${next}\\?`)); // Back to the cut: Play as it was -- the clip, the second, the take -- and history as it was. await page.locator("[data-back-to-play]").click(); await expect(page.locator("[data-cut-app-play]")).toHaveAttribute("data-cut-app-play", "shown"); await expect(root(page)).toHaveAttribute("data-play-item", item); expect(Math.abs((await tNow(page)) - t0)).toBeLessThan(0.15); await expect(root(page)).toHaveAttribute("data-play-cut", ""); await expect(page).toHaveURL(/\/play\?/); expect(await page.evaluate(() => history.length)).toBe(hist + 2); // ...and Play did not start over: the deck is not being composed again (nothing changed). await expect(root(page)).toHaveAttribute("data-play-compose", composed); expect(composed).not.toBe("composing"); }); test("Back and Forward step between Play and the bench; the bench on its own goes to Play from here", async ({ page }) => { await page.setViewportSize({ width: 1366, height: 1000 }); await page.goto(urls.playHref(P)); await ready(page); await page.locator('[data-play-row="c04"]').press("Enter"); await expect(root(page)).toHaveAttribute("data-play-item", "c04"); await page.locator("body").press("e"); await expect(page.locator('[data-cut-app-bench="c04"] [data-bench-shell="clip"]')).toBeVisible({ timeout: 20_000 }); await page.goBack(); await expect(page.locator("[data-cut-app-play]")).toHaveAttribute("data-cut-app-play", "shown"); await expect(root(page)).toHaveAttribute("data-play-item", "c04"); await page.goForward(); await expect(page.locator('[data-cut-app-bench="c04"] [data-bench-shell="clip"]')).toBeVisible({ timeout: 20_000 }); await page.goBack(); await expect(page.locator("[data-cut-app-play]")).toHaveAttribute("data-cut-app-play", "shown"); // A reload of the bench's address is the bench's own page; Walk → Play from there. await page.goto(urls.clipBenchHref(P, "c03")); const here = page.locator("[data-play-from-here]"); await expect(here).toHaveAttribute("href", urls.playHref(P, { clip: "c03" })); await page.screenshot({ path: test.info().outputPath("app-walk-play-from-here.png") }); await here.click(); await expect(page).toHaveURL(/\/play\?(cut=1&)?clip=c03/); await expect(root(page)).toHaveAttribute("data-play-item", "c03", { timeout: 20_000 }); }); test("a window save refused for the stamp's second offers the fix: Move the stamp, in one write, the trim kept", async ({ page }) => { await page.setViewportSize({ width: 1366, height: 1000 }); // c02 is 3.5–5.5 with its stamp (k1) at 4.5. expect(manifest().timeline.find((e) => e.id === "c02")!.claim!.at).toBe(4.5); await page.goto(urls.clipBenchHref(P, "c02")); await expect(page.locator('[data-bench="c02"]')).toHaveCount(1); // The start to 4.6 (past the stamp), by the keys: } is +0.5 s, ] +0.05 s. await page.locator("body").press("Shift+BracketRight"); await page.locator("body").press("Shift+BracketRight"); await page.locator("body").press("BracketRight"); await page.locator("body").press("BracketRight"); await page.locator("[data-save-window]").click(); const fix = page.locator('[data-bench-fix="mark"]'); await expect(fix).toContainText("The stamp at 4.50 would be outside 4.60–5.50"); await expect(page.locator("[data-bench-note]")).toContainText("claim.at 4.5"); await expect(page.locator('[data-bench-fix-move="first"]')).toContainText("Move the stamp to 4.60 (first second)"); await expect(page.locator("[data-bench-fix-clear]")).toContainText("Clear the stamp's second"); await page.screenshot({ path: test.info().outputPath("bench-stamp-fix.png") }); await page.locator('[data-bench-fix-move="first"]').click(); await expect(fix).toHaveCount(0); await expect.poll(() => manifest().timeline.find((e) => e.id === "c02")!.start).toBe(4.6); expect(manifest().timeline.find((e) => e.id === "c02")!.claim!.at).toBe(4.6); });