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 walk on a phone (the phone design brief, "The walk" and "Proof"), and // Play the cut's Edit this clip → Back to the cut round trip on the desk and // on a phone. // // phone-walk-fixture (WRITABLE, make-fixture.mjs): p01 3.00-6.00 and p02 // 12.00-15.00 on vid1, whose sentences end at 3, 9, 12, 15 and 21 -- so p01's // `sentence ›` takes its end to 9.00 and `‹ sentence` its start to 0.00. // play-edit-fixture is play-cut-fixture's cut under its own name, because the // round trip writes an edge and play-cut.spec reads the clock. // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const FIXTURE = path.join(HERE, "..", ".e2e-song"); const WALK = "reports/phone-walk-fixture"; const PLAY = "reports/play-edit-fixture"; const PHONE = { width: 390, height: 844 }; const SMALL = { width: 360, height: 740 }; type Entry = { id: string; start: number; end: number; verdict?: string; correction?: string }; const entryOf = (project: string, id: string): Entry => { const m = JSON.parse(readFileSync(path.join(FIXTURE, ...project.split("/"), "video.manifest.json"), "utf8")) as { timeline: Entry[] }; return m.timeline.find((e) => e.id === id)!; }; const sel = (page: Page) => page.locator("[data-edge-strip]").getAttribute("data-sel"); /** The walk is hydrated: the strip is drawn and its buttons answer. */ const walkReady = async (page: Page, clip: string) => { await expect(page.locator(`[data-bench="${clip}"]`)).toHaveCount(1); await expect(page.locator("[data-edge-strip]")).toBeVisible(); await expect(page.locator('[data-edge-step="end-on"]')).toBeEnabled(); }; /** * What is pinned on screen, in px: the union of every sticky or fixed box's * visible part. A box inside another counted one is not counted twice, and a * box translated off the top counts only for what is still on screen. */ const pinnedPx = (page: Page) => page.evaluate(() => { const vh = window.innerHeight; const spans: [number, number][] = []; const pinned = [...document.querySelectorAll("body *")].filter((el) => { const cs = getComputedStyle(el); if (cs.position !== "sticky" && cs.position !== "fixed") return false; if (cs.display === "none" || cs.visibility === "hidden") return false; const r = el.getBoundingClientRect(); return r.height > 2 && r.width > 2; }); for (const el of pinned) { if (pinned.some((o) => o !== el && o.contains(el))) continue; // A sticky box only pins once it is stuck; one still in flow is just page. const cs = getComputedStyle(el); const r = el.getBoundingClientRect(); if (cs.position === "sticky" && r.top > parseFloat(cs.top || "0") + 1) continue; const a = Math.max(0, r.top); const b = Math.min(vh, r.bottom); if (b > a) spans.push([a, b]); } spans.sort((x, y) => x[0] - y[0]); let total = 0; let end = -1; for (const [a, b] of spans) { if (a > end) { total += b - a; end = b; } else if (b > end) { total += b - end; end = b; } } return Math.round(total); }); const noSideways = async (page: Page) => expect(await page.evaluate(() => document.documentElement.scrollWidth - window.innerWidth)).toBeLessThanOrEqual(0); test.beforeEach(() => { test.setTimeout(120_000); }); test("the walk at 390: the picture pinned, a strip after 600 px, the dock under the thumb", async ({ page }) => { await page.setViewportSize(PHONE); await page.goto(urls.clipBenchHref(WALK, "p01")); await walkReady(page, "p01"); // The desk's head and verdict bar are not drawn; the walk's own are. await expect(page.locator("[data-bench-top]")).toBeHidden(); await expect(page.locator("[data-verdict-bar]")).toBeHidden(); await expect(page.locator("[data-walk-bar]")).toBeVisible(); await expect(page.locator("[data-walk-pos]")).toHaveText("1/2"); const dock = page.locator("[data-walk-dock]"); await expect(dock).toBeVisible(); const d = (await dock.boundingBox())!; expect(d.y + d.height).toBeLessThanOrEqual(PHONE.height + 1); for (const b of ["[data-walk-note]", "[data-walk-play]", "[data-walk-confirm]"]) { expect((await dock.locator(b).boundingBox())!.height).toBeGreaterThanOrEqual(44); } // At rest: the place bar, the 16:9 picture (390 wide) and the dock. const video = page.locator("[data-testid=clip-video]"); expect(Math.round((await video.boundingBox())!.height)).toBeGreaterThanOrEqual(215); console.log(`walk 390x844: pinned at rest = ${await pinnedPx(page)} px`); await page.screenshot({ path: test.info().outputPath("walk-390-top.png") }); // 600 px down: the quote is under the picture, so the picture is a 120 px // strip; the place bar has gone (it comes back on the way up). await page.evaluate(() => window.scrollTo(0, 600)); await expect(page.locator("[data-walk-pin]")).toHaveAttribute("data-compact", ""); await expect(page.locator("[data-walk-pin]")).toHaveAttribute("data-bar", "hidden"); await expect.poll(async () => Math.round((await video.boundingBox())!.height)).toBe(120); await expect(page.locator("[data-walk-strip-side]")).toContainText("p01"); // Pinned while reading: the strip and the dock -- the picture is the // exception the brief makes, and only at its smallest. await expect.poll(() => pinnedPx(page)).toBeLessThanOrEqual(120 + 72 + 4); console.log(`walk 390x844: pinned after 600 px = ${await pinnedPx(page)} px`); await page.screenshot({ path: test.info().outputPath("walk-390-scrolled.png") }); await page.evaluate(() => window.scrollBy(0, -200)); await expect(page.locator("[data-walk-pin]")).toHaveAttribute("data-bar", "shown"); await noSideways(page); }); test("sentence buttons move an edge to the next boundary; a drag snaps; Snap | Free is remembered", async ({ page }) => { await page.setViewportSize(PHONE); await page.goto(urls.clipBenchHref(WALK, "p01")); await walkReady(page, "p01"); expect(await sel(page)).toBe("3.00-6.00"); // The boundaries are drawn: vid1's sentences in the 0-9 cache. for (const t of ["0", "3", "9"]) await expect(page.locator(`[data-boundary="${t}"]`)).toHaveCount(1); await expect(page.locator('[data-boundary="6"]')).toHaveCount(0); // `sentence ›` on the end: the run-on 3-6 cue's sentence ends at 9. await page.locator('[data-edge-step="end-on"]').click(); await expect.poll(() => sel(page)).toBe("3.00-9.00"); await expect(page.locator("[data-edge-words-end]")).toHaveText("of that it finishes here.|"); // `‹ sentence` on the start: the sentence before starts at 0. await page.locator('[data-edge-step="start-back"]').click(); await expect.poll(() => sel(page)).toBe("0.00-9.00"); // There is no sentence before 0, nor an end past 9 inside the cache... past // it the next end (12) is OFFERED as a fetch, never clamped to. await expect(page.locator('[data-edge-step="start-back"]')).toBeDisabled(); await page.locator('[data-edge-step="end-on"]').click(); await expect(page.locator('[data-edge-offer="end"]')).toContainText("past what is fetched"); await expect(page.locator('[data-edge-fetch="end"]')).toHaveText(/Fetch to 0:12/); expect(await sel(page)).toBe("0.00-9.00"); // Unsaved, and said so under the strip; Reset puts it back. await expect(page.locator("[data-walk-status]")).toContainText("Unsaved"); await page.locator("[data-walk-reset]").first().click(); await expect.poll(() => sel(page)).toBe("3.00-6.00"); // A drag: the end tab from 6.0 to 8.7 lands ON 9 (within 0.6 s). From the // top of the page: scrolled, the strip goes under the pinned picture. await page.evaluate(() => window.scrollTo(0, 0)); await expect(page.locator("[data-walk-pin]")).not.toHaveAttribute("data-compact", ""); const wave = (await page.locator("[data-edge-wave]").boundingBox())!; const xAt = (t: number) => wave.x + (t / 9) * wave.width; // the cache is 0.00-9.00 const tab = page.locator('[data-edge-tab="end"]'); const tb = (await tab.boundingBox())!; const grabX = tb.x + tb.width / 2; const grabY = tb.y + tb.height - 8; const dx = grabX - xAt(6); await page.mouse.move(grabX, grabY); await page.mouse.down(); await page.mouse.move(xAt(7.6) + dx, grabY, { steps: 4 }); await page.mouse.move(xAt(8.7) + dx, grabY, { steps: 4 }); await page.mouse.up(); await expect.poll(() => sel(page)).toBe("3.00-9.00"); // Free: the same kind of drag stands where it is let go. await page.locator('[data-edge-snap="free"]').click(); await expect(page.locator("[data-edge-strip]")).toHaveAttribute("data-snap", "off"); const tb2 = (await tab.boundingBox())!; const grab2 = tb2.x + tb2.width / 2; const dx2 = grab2 - xAt(9); await page.mouse.move(grab2, grabY); await page.mouse.down(); await page.mouse.move(xAt(7.5) + dx2, grabY, { steps: 6 }); await page.mouse.up(); await expect.poll(async () => Number(String(await sel(page)).split("-")[1])).toBeGreaterThan(7.3); expect(Number(String(await sel(page)).split("-")[1])).toBeLessThan(7.7); // Remembered per browser, like the playback speed. await page.reload(); await walkReady(page, "p01"); await expect(page.locator('[data-edge-snap="free"]')).toHaveAttribute("aria-pressed", "true"); // Nothing was written: edges are drafts until Confirm or Save. const e = entryOf(WALK, "p01"); expect([e.start, e.end]).toEqual([3, 6]); }); test("Confirm advances with the moved edges and offers Undo; Undo puts both back", async ({ page }) => { await page.setViewportSize(PHONE); await page.goto(urls.clipBenchHref(WALK, "p01")); await walkReady(page, "p01"); await page.locator('[data-edge-step="end-on"]').click(); await expect.poll(() => sel(page)).toBe("3.00-9.00"); await page.locator("[data-walk-confirm]").click(); await expect(page).toHaveURL(new RegExp(`/clip/p02$`), { timeout: 20_000 }); const toast = page.locator("[data-walk-toast]"); await expect(toast).toContainText("Confirmed p01 — next: p02"); let e = entryOf(WALK, "p01"); expect(e.verdict).toBe("confirmed"); expect(e.end).toBe(9); await page.screenshot({ path: test.info().outputPath("walk-390-toast.png") }); await toast.locator("[data-walk-undo]").click(); await expect(page).toHaveURL(new RegExp(`/clip/p01$`), { timeout: 20_000 }); await walkReady(page, "p01"); await expect(page.locator("[data-walk-verdict]")).toHaveAttribute("data-walk-verdict", "unreviewed"); e = entryOf(WALK, "p01"); expect(e.verdict).toBeUndefined(); expect([e.start, e.end]).toEqual([3, 6]); }); test("Reject… is a sheet: the reasons, then doesn't match with its note, kept in place, marks the clip incorrect and stays", async ({ page, request }) => { await page.setViewportSize(PHONE); await page.goto(urls.clipBenchHref(WALK, "p02")); await walkReady(page, "p02"); await page.locator("[data-walk-note]").click(); const sheet = page.locator("[data-walk-sheet]"); await expect(sheet.locator("[data-reject-menu]")).toBeVisible(); await sheet.locator('[data-reject-reason="not-matching"]').click(); const field = sheet.locator("[data-reject-note]"); await expect(field).toBeFocused(); await field.fill("the speaker is the co-host"); await sheet.locator("[data-reject-keep]").click(); await expect(sheet.locator('[data-reject-done="p02"]')).toContainText("Rejected p02 (doesn't match), still in the cut."); await sheet.locator("[data-walk-sheet-close]").click(); await expect(page.locator("[data-walk-sheet]")).toHaveCount(0); await expect(page.locator("[data-walk-verdict]")).toHaveAttribute("data-walk-verdict", "incorrect"); await expect.poll(() => entryOf(WALK, "p02").verdict).toBe("incorrect"); expect(entryOf(WALK, "p02").correction).toBe("the speaker is the co-host"); await expect(page).toHaveURL(new RegExp(`/clip/p02$`)); // Put it back for whatever runs next. const { token } = (await (await request.get(`/api/report/clip?project=${encodeURIComponent(WALK)}&clip=p02`)).json()) as { token: string }; const r = await request.put("/api/report/window", { data: { project: WALK, clip: "p02", token, correction: "", verdict: "" } }); expect(r.ok()).toBe(true); }); test("no sideways scroll at 360: the walk (every section open), Play the cut, the decks", async ({ page }) => { await page.setViewportSize(SMALL); await page.goto(urls.clipBenchHref(WALK, "p01")); await walkReady(page, "p01"); await noSideways(page); for (const sec of await page.locator("[data-walk-sec]").all()) await sec.click(); await expect(page.locator('[data-walk-sec][aria-expanded="false"]')).toHaveCount(0); await noSideways(page); await page.screenshot({ path: test.info().outputPath("walk-360-open.png"), fullPage: true }); await page.goto(urls.playHref("reports/play-cut-fixture")); await expect(page.locator("[data-play-cut]")).toHaveAttribute("data-play-state", "paused"); await expect(page.locator("[data-play-dock]")).toBeVisible(); await noSideways(page); await page.evaluate(() => window.scrollTo(0, 500)); await expect(page.locator("[data-play-player-pin]")).toHaveAttribute("data-compact", ""); await noSideways(page); await page.goto(urls.clipDeckHref("reports/clip-deck-fixture", { show: "all" })); await expect(page.locator("[data-card-top]")).toBeVisible(); await noSideways(page); await page.goto(urls.reviewHref("reports/review-player-fixture")); await expect(page.locator("[data-deck]").first()).toBeVisible(); await noSideways(page); }); test("Play → Edit this clip → move an edge → Back: the new bounds are what plays (desk)", async ({ page }) => { await page.setViewportSize({ width: 1366, height: 900 }); await page.goto(urls.playHref(PLAY)); const root = page.locator("[data-play-cut]"); await expect(root).toHaveAttribute("data-play-state", "paused"); // c02 (3.5-5.5), from its first shown second. await page.locator('[data-play-row="c02"]').press("Enter"); await expect(root).toHaveAttribute("data-play-item", "c02"); await expect(root).toHaveAttribute("data-play-source", "3.5-5.5"); await page.locator("[data-play-edit]").click(); await expect(page).toHaveURL(/\/clip\/c02\?from=play/, { timeout: 20_000 }); const back = page.locator("[data-back-to-play]"); await expect(back).toHaveText("‹ Back to the cut"); // `{` is the start a half second earlier (the button is portalled in by an // effect, so the keys are live once it shows); Back saves it first, and says so. await page.locator("body").press("Shift+BracketLeft"); await expect(back).toHaveText("Save and back to the cut"); await back.click(); await expect(page).toHaveURL(/\/play\?(cut=1&)?clip=c02/, { timeout: 20_000 }); await expect(root).toHaveAttribute("data-play-item", "c02"); expect(entryOf(PLAY, "c02").start).toBe(3); await expect(root).toHaveAttribute("data-play-source", "3-5.5"); // Placed by clip id: on c02's first shown second of the re-read cut. await page.locator("[data-play-toggle]").click(); await expect(root).toHaveAttribute("data-play-item", "c02"); await page.keyboard.press("k"); // A saved version or a take (`short`: c04 then c01) is played read-only: E asks to open it in the draft // first (L3: every edit lands in the draft); Cancel goes back to Play of it, nothing written. // play-take-edit.spec.ts follows the open through to the draft's bench. const before = readFileSync(path.join(FIXTURE, ...PLAY.split("/"), "video.manifest.json"), "utf8"); await page.goto(urls.playHref(PLAY, { take: "short" })); await expect(root).toHaveAttribute("data-play-item", "c04"); // E (the key is live once hydrated, which the first render cannot show). await expect(async () => { await page.keyboard.press("e"); await expect(page).toHaveURL(/\/takes\/short\/open\?clip=c04&from=play/, { timeout: 1500 }); }).toPass({ timeout: 15_000 }); await expect(page.locator('[data-open-draft="short"]')).toContainText("Open short in draft?"); await page.locator("[data-open-draft-cancel]").click(); await expect(page).toHaveURL(/\/play\?take=short/, { timeout: 20_000 }); await expect(root).toHaveAttribute("data-play-cut", "short"); expect(readFileSync(path.join(FIXTURE, ...PLAY.split("/"), "video.manifest.json"), "utf8")).toBe(before); }); test("Play → Edit this clip → move an edge → Back: the new bounds are what plays (phone)", async ({ page }) => { await page.setViewportSize(PHONE); await page.goto(urls.playHref(PLAY)); const root = page.locator("[data-play-cut]"); await expect(root).toHaveAttribute("data-play-state", "paused"); await expect(root).toHaveAttribute("data-play-item", "c01"); const before = entryOf(PLAY, "c01"); await expect(root).toHaveAttribute("data-play-source", `${before.start}-${before.end}`); await page.locator("[data-play-dock-edit]").click(); await expect(page).toHaveURL(/\/clip\/c01\?from=play/, { timeout: 20_000 }); await walkReady(page, "c01"); // c01 ends on a sentence at 3; the next one ends at 9. await page.locator('[data-edge-step="end-on"]').click(); await expect.poll(() => sel(page)).toBe(`${before.start.toFixed(2)}-9.00`); const back = page.locator("[data-walk-back-play]"); await expect(back).toHaveText("Save, back to the cut"); await back.click(); await expect(page).toHaveURL(/\/play\?(cut=1&)?clip=c01/, { timeout: 20_000 }); await expect(root).toHaveAttribute("data-play-item", "c01"); expect(entryOf(PLAY, "c01").end).toBe(9); await expect(root).toHaveAttribute("data-play-source", `${before.start}-9`); await page.screenshot({ path: test.info().outputPath("play-390-back.png") }); }); test("how it looks at 390: Play the cut and the two decks", async ({ page }) => { await page.setViewportSize(PHONE); await page.goto(urls.playHref("reports/play-cut-fixture")); await expect(page.locator("[data-play-cut]")).toHaveAttribute("data-play-state", "paused"); await page.screenshot({ path: test.info().outputPath("play-390-top.png") }); await page.evaluate(() => window.scrollTo(0, 500)); await expect(page.locator("[data-play-player-pin]")).toHaveAttribute("data-compact", ""); await page.screenshot({ path: test.info().outputPath("play-390-scrolled.png") }); await page.goto(urls.clipDeckHref("reports/clip-deck-fixture", { show: "all" })); await expect(page.locator("[data-card-top]")).toBeVisible(); await page.screenshot({ path: test.info().outputPath("deck-390.png") }); await page.goto(urls.reviewHref("reports/review-player-fixture")); await expect(page.locator("[data-deck]").first()).toBeVisible(); await page.screenshot({ path: test.info().outputPath("audition-390.png") }); });