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"; // --------------------------------------------------------------------------- // THE BENCH SHELL (plans/umtool-redesign.md, P4b; canvas "Clip bench"): one // frame for the clip, claim, narration, takes and drafts-review benches -- // the top bar ← the piece · the bench · N of M · ‹ prev / next › · keys // the verdict bar ONE question, its consequence, the actions by result // the reader the source's cues, the cited one lit, the cite thread // -- fitting 1366×768, no rail, no page scroll. // // Fixtures (fixtures/bench-shell-fixture.mjs): bench-shell-fixture (READ-ONLY: // s01 ends mid-sentence, s02 is the rest of the sentence), media-review-fixture // (three fields to review, written by the review test alone); bench-fixture's // ledger for the claim bench (read here, never written); takes-fixture. // --------------------------------------------------------------------------- const SHELL = "reports/bench-shell-fixture"; const REVIEW = "reports/media-review-fixture"; const BENCH = "reports/bench-fixture"; const EXTEND = "reports/bench-extend-fixture"; const FIXTURE = path.join(path.dirname(fileURLToPath(import.meta.url)), "..", ".e2e-song"); const endOf = (id: string) => (JSON.parse(readFileSync(path.join(FIXTURE, "reports", "bench-extend-fixture", "video.manifest.json"), "utf8")) as { timeline: { id: string; end: number }[] }).timeline.find( (e) => e.id === id, )!.end; /** The page fits the laptop: no horizontal scroll, no vertical page scroll. */ async function fits(page: Page) { const { w, h } = await page.evaluate(() => ({ w: document.documentElement.scrollWidth, h: document.documentElement.scrollHeight, })); expect(w).toBeLessThanOrEqual(1366); expect(h).toBeLessThanOrEqual(768); } test.beforeEach(async ({ page }) => { await page.setViewportSize({ width: 1366, height: 768 }); }); test("the clip bench: the top bar, the one question with its consequence, the reader with the cited cue lit", async ({ page }) => { await page.goto(urls.clipBenchHref(SHELL, "s01")); const top = page.locator("[data-bench-top]"); // The head: home, the piece (its Cut), the bench, where you are, the walk, the keys. await expect(top).toHaveAttribute("data-app-header", "bench"); await expect(top.getByRole("link", { name: "umtool home" })).toHaveAttribute("href", "/"); await expect(top.locator("[data-bench-back]")).toHaveAttribute("href", urls.projectHref(SHELL, { tab: "cut" })); await expect(top.locator("[data-bench-kind]")).toHaveText("Clip bench"); await expect(top.locator("[data-bench-pos]")).toHaveText("1 of 2"); await expect(top.locator("[data-clip-nav=prev]")).toHaveCount(0); await expect(top.locator("[data-clip-nav=next]")).toHaveText(/s02/); await expect(top.locator("[data-bench-keys]")).toContainText("confirm"); // No rail on a bench. await expect(page.locator(".app-rail")).toHaveCount(0); // ONE question: s01 ends mid-sentence, so the bar asks to extend it -- and // says what that would cover before you choose. const bar = page.locator("[data-verdict-bar]"); await expect(bar.locator("[data-verdict-question]")).toContainText("Extend s01 to the end of the sentence?"); await expect(bar.locator("[data-verdict-consequence]")).toHaveText("It would end at 0:09.00 (+3.0 s), covering all of s02."); const extend = bar.locator("[data-verdict-extend]"); await expect(extend).toHaveText("Extend to 0:09.00"); await expect(extend).toHaveClass(/bg-signal/); // The walk's own answers stay, as outlines while the extension is the question. await expect(bar.locator("[data-verdict-yes]")).not.toHaveClass(/bg-signal/); await expect(bar.locator("[data-verdict-keep]")).toHaveText("Keep the cut here"); // The reader: the source on the reader surface, the cited cue (3 s) lit, Copy citation. const reader = page.getByRole("complementary", { name: "Reader" }); await expect(reader).toBeVisible(); await expect(reader.locator("[data-transcript] [data-tcue][data-lit]")).toHaveAttribute("data-tcue", "3"); await expect(reader.locator("[data-tcue='3']")).toHaveAttribute("data-cited", "1"); await expect(reader.locator("[data-copy-citation]")).toBeVisible(); await expect(reader).toContainText("cites 0:03"); // The answer column still holds the last field on screen. const box = await page.locator("[data-attrib-field=correction]").boundingBox(); expect(box!.y + box!.height).toBeLessThanOrEqual(768); await fits(page); }); test("the clip bench's keys walk the cut: n and p", async ({ page }) => { await page.goto(urls.clipBenchHref(SHELL, "s01")); // Live once the bench's own keys answer: `x` opens Reject ▾'s reasons (Escape closes them). const menu = page.locator("[data-reject-menu]"); await expect(async () => { await page.locator("body").press("x"); await expect(menu).toBeVisible({ timeout: 500 }); }).toPass({ timeout: 10_000 }); await page.locator("body").press("Escape"); await page.locator("body").press("n"); await expect(page.locator("[data-bench=s02]")).toBeVisible(); await expect(page.locator("[data-bench-pos]")).toHaveText("2 of 2"); // s02 ends the sentence and is locked: the bar asks the walk's question. await expect(page.locator("[data-verdict-question]")).toHaveText("Keep s02 in the cut?"); await expect(page.locator("[data-verdict-yes]")).toHaveClass(/bg-signal/); await page.locator("body").press("p"); await expect(page.locator("[data-bench=s01]")).toBeVisible(); }); test("Extend saves the sentence's end at once, and Reset puts the window back", async ({ page }) => { await page.goto(urls.clipBenchHref(EXTEND, "s01")); const bar = page.locator("[data-verdict-bar]"); await bar.locator("[data-verdict-extend]").click(); await expect.poll(() => endOf("s01")).toBe(9); // The clip now ends the sentence: the bar asks the walk's question. await expect(bar.locator("[data-verdict-question]")).toHaveText("Keep s01 in the cut?"); await expect(page.locator("[data-bench-note]")).toContainText("R undoes it"); // Reset (the button, as R) undoes the saved extension. await page.locator("[data-reset]").click(); await expect.poll(() => endOf("s01")).toBe(6); await expect(bar.locator("[data-verdict-question]")).toHaveText("Extend s01 to the end of the sentence?"); await expect(page.locator("[data-reset]")).toBeDisabled(); }); test("the claim bench: its context on the reader, the cited cue lit, j/k from anywhere, Save ruling in the verdict bar", async ({ page }) => { await page.goto(urls.claimBenchHref(BENCH, "k01")); await expect(page.locator("[data-bench-top] [data-bench-kind]")).toHaveText("Claim bench"); await expect(page.locator("[data-bench-pos]")).toHaveText("1 of 3"); const ctx = page.getByTestId("claim-context"); const lit = ctx.locator("[data-lit-line][data-lit]"); await expect(lit).toHaveAttribute("data-cited", "1"); await expect(page.locator("[data-verdict-question]")).toHaveText("Save the ruling on k01?"); await expect(page.getByTestId("claim-save")).toHaveText("Save ruling"); // j moves the lit cue, from anywhere on the page that is not a field. const first = await lit.textContent(); await page.locator("body").press("j"); await expect(lit).not.toHaveText(first ?? ""); await fits(page); }); test("the drafts review is a bench: j/k light a field, the bar asks about it, a approves, r goes to the note", async ({ page }) => { await page.goto(urls.reviewHref(REVIEW, { view: "list" })); await expect(page.locator("[data-bench-top] [data-bench-kind]")).toHaveText("Drafts review"); // Media folded into Deliver (L7b): the drafts' own tab. await expect(page.locator("[data-bench-back]")).toHaveAttribute("href", urls.projectHref(REVIEW, { tab: "deliver" })); const rows = page.locator("[data-draft-row]"); await expect(rows).toHaveCount(3); const bar = page.locator("[data-verdict-bar]"); // The first field is lit: m01's on-screen text, the clip it is drawn over on the reader. await expect(bar.locator("[data-verdict-question]")).toHaveText("Approve the drafted on-screen text of m01?"); await expect(bar.locator("[data-verdict-consequence]")).toHaveText("A final build refuses it until it is approved."); const reader = page.getByRole("complementary", { name: "Reader" }); await expect(reader.locator("[data-lit-line][data-lit]")).toBeVisible(); // Its provenance: the second attempt kept, the first's broken rule said. await expect(page.locator("[data-draft-row='onscreen/m01/onscreen'] [data-draft-prov]")).toContainText("attempt 2 of 2 chosen"); await expect(page.locator("[data-draft-row='onscreen/m01/onscreen'] [data-draft-prov]")).toContainText("title over 60 characters"); // Live once the list has hydrated; then j, a. await expect(page.getByRole("group", { name: "Drafted fields" })).toHaveAttribute("data-hydrated", ""); await page.locator("body").press("j"); await expect(bar).toHaveAttribute("data-verdict-for", "onscreen/m02/onscreen"); await page.locator("body").press("a"); await expect(page.locator("[data-draft-row='onscreen/m02/onscreen']")).toHaveAttribute("data-state", "approved"); await expect(bar.locator("[data-verdict-question]")).toHaveText("The on-screen text of m02 is approved."); // The narration card: no clip under it -- the reader says so; r puts the cursor in its note. await page.locator("body").press("j"); await expect(bar).toHaveAttribute("data-verdict-for", "narrate/k01/narration"); await expect(reader).toContainText("No source window for this field"); await page.locator("body").press("r"); await expect(page.locator("[data-draft-row='narrate/k01/narration'] [data-draft-note]")).toBeFocused(); await fits(page); }); test("narration and takes wear the same shell: the top bar back to the piece, and one question", async ({ page }) => { await page.goto(urls.narrationHref("reports/narration-review-fixture")); await expect(page.locator("[data-bench-shell=narration] [data-bench-kind]")).toHaveText("Narration"); await expect(page.locator("[data-verdict-question]")).toContainText("narration of"); await fits(page); await page.goto(urls.takesHref("reports/takes-fixture")); await expect(page.locator("[data-bench-shell=takes] [data-bench-kind]")).toHaveText("Takes"); await expect(page.locator("[data-verdict-question]")).toHaveText("Listen to a take to judge it: like, maybe or no."); await expect(page.locator("[data-bench-keys]")).toContainText("listen"); });