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"; const HERE = path.dirname(fileURLToPath(import.meta.url)); // --------------------------------------------------------------------------- // Play the cut draws the story modules (umtool/docs/knobs.md, Modules, "Play // the cut and the live preview"): every module that declares `play` in the // module contract (report-to-video/modules/contract.mjs) comes back from the // full preview as a layer -- its own page, composed for preview -- and is laid // at its region over the footage, seeked on the cut clock. A window module // (the chapter) is up only inside its window, as the build lays it; a // whole-cut module (the pair strip, the status ledger) for the whole cut. // // Fixture: e2e/fixtures/play-cut-fixture.mjs as play-modules-fixture -- the // Play cut with a chapter opening c02 (2 s), a then-and-now pair c01 → c02 // and a status ledger. On the render's clock c02 is shown 2.033-4.967, c04 // from 8.067. // --------------------------------------------------------------------------- const PROJECT = "reports/play-modules-fixture"; const root = (page: Page) => page.locator("[data-play-cut]"); const layer = (page: Page, id: string) => page.locator(`[data-play-layer="${id}"]`); /** The chapter card's opacity inside its own page (the build's pixels, seeked by the parent). */ const chapterOpacity = (page: Page) => page .frameLocator('[data-testid="play-layer-chapter-iframe"]') .locator('.chapter[data-k="ch"]') .evaluate((el) => Number(getComputedStyle(el).opacity)); test.beforeEach(() => { test.setTimeout(120_000); }); test("the chapter card, the pair strip and the status ledger play in Play the cut: the chapter only inside its window", async ({ page }) => { await page.setViewportSize({ width: 1366, height: 1000 }); // A second into c02 -- the chapter opens c02 and is up for its first 2 s. await page.goto(urls.playHref(PROJECT, { clip: "c02", at: 1 })); await expect(root(page)).toHaveAttribute("data-play-edges", "render", { timeout: 30_000 }); await expect(root(page)).toHaveAttribute("data-play-item", "c02"); await expect(page.locator('[data-testid="play-deck"]')).toBeVisible({ timeout: 30_000 }); // The whole-cut modules: laid, their pages ready. for (const id of ["pair", "status"]) { await expect(layer(page, id)).toHaveAttribute("data-play-layer-up", "1"); await expect(page.getByTestId(`play-layer-${id}`)).toHaveAttribute("data-feed-ready", "1", { timeout: 30_000 }); } // The chapter: inside its window, up -- and its card drawn by its own page. const chapter = layer(page, "chapter"); await expect(chapter).toHaveAttribute("data-play-layer-segment", "c02"); await expect(chapter).toHaveAttribute("data-play-layer-up", "1"); await expect(page.getByTestId("play-layer-chapter")).toHaveAttribute("data-feed-ready", "1", { timeout: 30_000 }); await expect.poll(() => chapterOpacity(page), { timeout: 10_000 }).toBeGreaterThan(0.9); await expect(page.frameLocator('[data-testid="play-layer-chapter-iframe"]').locator(".title")).toHaveText("Part two"); // Laid in the build's z order: the pair (52) under the status ledger (55) under the chapter (85). expect(await page.locator("[data-play-layer]").evaluateAll((els) => els.map((e) => e.getAttribute("data-play-layer")))).toEqual(["pair", "status", "chapter"]); await page.screenshot({ path: test.info().outputPath("play-chapter-up.png") }); // Outside it (c04, past c02): no chapter on screen. await page.locator('[data-play-row="c04"]').press("Enter"); await expect(root(page)).toHaveAttribute("data-play-item", "c04"); await expect(page.locator('[data-play-layer="chapter"][data-play-layer-up="1"]')).toHaveCount(0); // ...and before it (c01's first second): still none, the whole-cut layers still laid. await page.locator('[data-play-row="c01"]').press("Enter"); await expect(root(page)).toHaveAttribute("data-play-item", "c01"); await expect(page.locator('[data-play-layer="chapter"][data-play-layer-up="1"]')).toHaveCount(0); await expect(layer(page, "pair")).toHaveAttribute("data-play-layer-up", "1"); await page.screenshot({ path: test.info().outputPath("play-chapter-down.png") }); }); test("a clip ruled incorrect is skipped by default (struck through on the strip, why on hover); the toggle plays it, remembered", async ({ page }) => { await page.setViewportSize({ width: 1366, height: 1000 }); await page.goto(urls.playHref(PROJECT)); await expect(root(page)).toHaveAttribute("data-play-edges", "render", { timeout: 30_000 }); const rows = page.locator("[data-play-row]"); // c03 (ruled incorrect) is not in what plays: its neighbours meet. await expect(rows).toHaveCount(4); expect(await rows.evaluateAll((els) => els.map((e) => e.getAttribute("data-play-row")))).toEqual(["c01", "c02", "k01", "c04"]); const marker = page.locator('[data-play-skipped="c03"]'); // An `incorrect` written before reasons existed reads as "doesn't match", in the new words. await expect(marker).toHaveAttribute("title", "c03 skipped — rejected — doesn't match: Other speaker, not the host"); await expect(marker).toHaveCSS("text-decoration-line", "line-through"); await expect(page.locator("[data-play-rejected]")).toContainText("Skipping 1 rejected clip: c03 (doesn't match)"); // Next from k01 goes straight to c04. await page.locator('[data-play-row="k01"]').press("Enter"); await expect(root(page)).toHaveAttribute("data-play-item", "k01"); await page.keyboard.press("n"); await expect(root(page)).toHaveAttribute("data-play-item", "c04"); await page.screenshot({ path: test.info().outputPath("play-incorrect-skipped.png") }); // Shown for re-review: back in the cut, greyed and struck through, the correction on hover. await page.locator("[data-play-show-rejected]").check(); await expect(rows).toHaveCount(5); const c03 = page.locator('[data-play-row="c03"]'); await expect(c03).toHaveAttribute("data-play-row-rejected", ""); await expect(c03).toHaveAttribute("title", "c03: rejected — doesn't match: Other speaker, not the host"); await expect(page.locator("[data-play-skipped]")).toHaveCount(0); await expect(page.locator("[data-play-rejected]")).toContainText("Playing 1 rejected clip"); // Remembered by this browser. await page.reload(); await expect(root(page)).toHaveAttribute("data-play-edges", "render", { timeout: 30_000 }); await expect(page.locator("[data-play-show-rejected]")).toBeChecked(); await expect(rows).toHaveCount(5); await page.locator("[data-play-show-rejected]").uncheck(); await expect(rows).toHaveCount(4); }); test("Edit this clip, then the browser's Back: Play the cut again, paused at the same second of the same clip", async ({ page }) => { await page.setViewportSize({ width: 1366, height: 1000 }); await page.goto(urls.playHref(PROJECT, { clip: "c02", at: 1 })); await expect(root(page)).toHaveAttribute("data-play-edges", "render", { timeout: 30_000 }); await expect(root(page)).toHaveAttribute("data-play-item", "c02"); const t0 = Number(await root(page).getAttribute("data-play-t")); expect(t0).toBeGreaterThan(2.1); // Play keeps its place in its URL (no history entry of its own). await expect.poll(() => new URL(page.url()).searchParams.get("clip")).toBe("c02"); await page.keyboard.press("e"); await expect(page).toHaveURL(/\/clip\/c02/); await expect(page.locator('[data-bench="c02"]')).toHaveCount(1, { timeout: 30_000 }); await expect(page.locator("[data-back-to-play]")).toBeVisible(); await page.goBack(); await expect(root(page)).toHaveAttribute("data-play-edges", "render", { timeout: 30_000 }); await expect(root(page)).toHaveAttribute("data-play-item", "c02"); await expect(root(page)).toHaveAttribute("data-play-state", "paused"); await expect.poll(async () => Math.abs(Number(await root(page).getAttribute("data-play-t")) - t0)).toBeLessThan(0.1); // The cut did not change: no "the cut changed" note. await expect(page.locator("[data-play-back-toast]")).toHaveCount(0); }); test("Wrong speaker in Play the cut (Reject with its reason preset): asked in the page, the clip leaves the reel on record, Undo puts it back", async ({ page }) => { const WRONG = "reports/play-wrong-fixture"; const dir = path.join(HERE, "..", ".e2e-song", "reports", "play-wrong-fixture"); await page.setViewportSize({ width: 1366, height: 1000 }); await page.goto(urls.playHref(WRONG)); await expect(root(page)).toHaveAttribute("data-play-edges", "render", { timeout: 30_000 }); const rows = page.locator("[data-play-row]"); await expect(rows).toHaveCount(5); await page.locator('[data-play-row="c02"]').press("Enter"); await expect(root(page)).toHaveAttribute("data-play-item", "c02"); await page.locator("[data-wrong-speaker-start]").click(); // It says what will go before anything is written. await expect(page.locator('[data-reject-ask="wrong-speaker"] [data-reject-what]')).toContainText("Reject c02 (playvid 3.50 s–5.50 s) as wrong speaker?"); expect(readFileSync(path.join(dir, "video.manifest.json"), "utf8")).toContain('"id": "c02"'); await page.locator("[data-reject-note]").fill("Other speaker, not the host"); await page.locator("[data-reject-remove]").click(); await expect(page.locator('[data-reject-done="c02"]')).toContainText("Removed c02 from the cut (wrong speaker)."); await expect(rows).toHaveCount(4, { timeout: 15_000 }); await expect(page.locator('[data-play-row="c02"]')).toHaveCount(0); const m = JSON.parse(readFileSync(path.join(dir, "video.manifest.json"), "utf8")) as { timeline: { id: string }[] }; expect(m.timeline.map((e) => e.id)).not.toContain("c02"); const rec = JSON.parse(readFileSync(path.join(dir, "removed.json"), "utf8")) as { removed: Record[] }; expect(rec.removed.at(-1)).toMatchObject({ id: "c02", reason: "wrong-speaker", correction: "Other speaker, not the host", video: "playvid", start: 3.5, end: 5.5 }); await page.screenshot({ path: test.info().outputPath("play-wrong-speaker-removed.png") }); // Undo: back in the reel, where it was. await page.locator("[data-reject-undo]").click(); await expect(page.locator("[data-reject-undone]")).toBeVisible(); await expect(rows).toHaveCount(5, { timeout: 15_000 }); expect(await rows.evaluateAll((els) => els.map((e) => e.getAttribute("data-play-row")))).toEqual(["c01", "c02", "k01", "c03", "c04"]); }); test("Reject ▾ in Play the cut: x then 3 rejects as irrelevant — out of the reel on record, Undo; keep in place skips it, says why, Undo", async ({ page }) => { const REJ = "reports/play-reject-fixture"; const dir = path.join(HERE, "..", ".e2e-song", "reports", "play-reject-fixture"); const manifest = () => JSON.parse(readFileSync(path.join(dir, "video.manifest.json"), "utf8")) as { timeline: Record[] }; await page.setViewportSize({ width: 1366, height: 1000 }); await page.goto(urls.playHref(REJ)); await expect(root(page)).toHaveAttribute("data-play-edges", "render", { timeout: 30_000 }); const rows = page.locator("[data-play-row]"); await expect(rows).toHaveCount(5); await page.locator('[data-play-row="c02"]').press("Enter"); await expect(root(page)).toHaveAttribute("data-play-item", "c02"); // x opens the reasons; "doesn't match" is one of seven, and only its own label says so. await page.keyboard.press("x"); const menu = page.locator("[data-reject-menu]"); await expect(menu).toBeVisible(); expect(await menu.locator("[data-reject-reason]").evaluateAll((els) => els.map((e) => e.getAttribute("data-reject-reason")))).toEqual([ "not-matching", "wrong-speaker", "irrelevant", "repeats", "weak", "privacy", "other", ]); await expect(menu.locator('[data-reject-reason="irrelevant"]')).toHaveText("3irrelevant"); await page.screenshot({ path: test.info().outputPath("play-reject-menu.png") }); // 3: irrelevant. It is asked in the page, and it is not a correction. await page.keyboard.press("3"); const ask = page.locator('[data-reject-ask="irrelevant"]'); await expect(ask.locator("[data-reject-what]")).toContainText("Reject c02 (playvid 3.50 s–5.50 s) as irrelevant?"); await expect(ask.locator("[data-reject-what]")).toContainText("the report is right; nothing here is a correction"); await expect(ask).not.toContainText("doesn't match"); await page.locator("[data-reject-remove]").click(); await expect(page.locator('[data-reject-done="c02"]')).toContainText("Removed c02 from the cut (irrelevant)."); await expect(rows).toHaveCount(4, { timeout: 15_000 }); expect(manifest().timeline.map((e) => e.id)).not.toContain("c02"); const rec = JSON.parse(readFileSync(path.join(dir, "removed.json"), "utf8")) as { removed: Record[] }; expect(rec.removed.at(-1)).toMatchObject({ id: "c02", reason: "irrelevant", correction: null, video: "playvid", start: 3.5, end: 5.5 }); await page.locator("[data-reject-undo]").click(); await expect(page.locator("[data-reject-undone]")).toContainText("the clip is back in the cut"); await expect(rows).toHaveCount(5, { timeout: 15_000 }); expect(manifest().timeline.find((e) => e.id === "c02")?.verdict).toBeUndefined(); // Reject, keep in place: the verdict only. Play skips it and says why; Undo writes the verdict back. await page.locator('[data-play-row="c02"]').press("Enter"); await expect(root(page)).toHaveAttribute("data-play-item", "c02"); await page.locator("[data-reject-open]").click(); await page.locator('[data-reject-reason="weak"]').click(); await page.locator("[data-reject-note]").fill("c01 says it better"); await page.locator("[data-reject-keep]").click(); await expect(page.locator('[data-reject-done="c02"]')).toContainText("Rejected c02 (weak), still in the cut."); await expect.poll(() => manifest().timeline.find((e) => e.id === "c02")).toMatchObject({ verdict: "rejected", reason: "weak", rejectNote: "c01 says it better" }); await expect(rows).toHaveCount(4, { timeout: 15_000 }); await expect(page.locator('[data-play-skipped="c02"]')).toHaveAttribute("title", "c02 skipped — rejected — weak: c01 says it better"); await expect(page.locator("[data-play-rejected]")).toContainText("Skipping 1 rejected clip: c02 (weak)"); await page.screenshot({ path: test.info().outputPath("play-reject-kept.png") }); await page.locator("[data-reject-undo]").click(); await expect(page.locator("[data-reject-undone]")).toContainText("the verdict is as it was"); await expect.poll(() => manifest().timeline.find((e) => e.id === "c02")?.verdict ?? null).toBeNull(); await expect(rows).toHaveCount(5, { timeout: 15_000 }); });