import { test, expect, type Page } from "@playwright/test"; import { existsSync, readFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; import { openPanel } from "./panels"; // --------------------------------------------------------------------------- // The montage clip deck (release 34 N1): every instance ruled by ear. The // earlier rulings in the seed's edits.json are imported once; "Doubtful first" // opens on the voice match's unlikely clip; a swipe keeps, ← cuts and z undoes // it, ↓ is not him, ↑ read aloud, e keeps with a wider phrase; the rulings are // montage-rulings.json, keyed by the moment, and survive a reload; the end // card's next render leaves out the ruled-out clips and numbers the kept. And // it fits a phone. Fixture: e2e/fixtures/clip-deck-fixture.mjs. // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const FIXTURE = path.join(HERE, "..", ".e2e-song"); const PROJECT = "reports/clip-deck-fixture"; const DIR = path.join(FIXTURE, "reports", "clip-deck-fixture"); const key = (at: string) => `testchan/vid1@${at}`; type Ruling = { verdict: string; reason: string; match?: string; at: string }; const rulings = (): Record => { const f = path.join(DIR, "montage-rulings.json"); if (!existsSync(f)) return {}; return (JSON.parse(readFileSync(f, "utf8")) as { rulings: Record }).rulings; }; const verdictOf = (at: string) => rulings()[key(at)]?.verdict ?? null; /** Drag the top card by (dx, dy) with the mouse: a swipe. */ async function swipe(page: Page, dx: number, dy: number) { const box = (await page.locator("[data-card-top] [data-card-phrase]").boundingBox())!; const x = box.x + box.width / 2; const y = box.y + box.height / 2; await page.mouse.move(x, y); await page.mouse.down(); for (let i = 1; i <= 8; i += 1) await page.mouse.move(x + (dx * i) / 8, y + (dy * i) / 8); await page.mouse.up(); } test("the clip deck: import, doubtful first, swipe keep, cut + undo, not him, read aloud, a wider phrase; persisted; the next render", async ({ page, request }) => { test.setTimeout(120_000); await page.setViewportSize({ width: 1366, height: 900 }); // The Cut tab says the montage has clips to rule and links the deck. await page.goto(urls.section(PROJECT, "cut")); await openPanel(page, "options", "cut"); await openPanel(page, "advanced", "cut"); const link = page.locator("[data-clip-deck-link]"); await expect(link).toHaveAttribute("data-clip-deck-link", "6"); await expect(link).toHaveAttribute("href", urls.clipDeckHref(PROJECT)); await link.click(); await expect(page).toHaveURL(new RegExp(`${urls.clipDeckHref(PROJECT).replace(/\//g, "\\/")}$`)); const card = page.locator("[data-card-top]"); await expect(card).toHaveAttribute("data-card", "s01"); await expect(card.locator("[data-card-phrase]")).toHaveText("slow news day"); await expect(card.locator("[data-phrase]")).toHaveText("slow news day"); await expect(card.locator("[data-card-source]")).toContainText("1 May 2020 · youtube · testchan · vid1"); await expect(card.locator("[data-card-voice]")).toHaveText("voice likely · 0.86"); await expect(page.locator("[data-voice-match]")).toContainText("2 clips scored · titanet-small"); // Video first: the project's cached window. await expect(card.locator("[data-play]")).toHaveAttribute("data-play", "window", { timeout: 15_000 }); await expect(card.locator("video[data-player]")).toHaveAttribute("src", /\/api\/report\/raw\?.*file=vid1_0\.00-9\.00\.mp4/); // The seed's two earlier rulings, offered once. await expect(page.locator("[data-import-offer]")).toContainText("edits.json has 2 earlier rulings · 1 left out · 1 phrase widened"); await page.locator("[data-import-rulings]").click(); await expect(page.locator("[data-imported]")).toHaveText("Imported 2 earlier rulings."); await expect(page.locator("[data-import-offer]")).toHaveCount(0); expect(rulings()[key("1.50")]).toMatchObject({ verdict: "not-him", reason: "another speaker" }); expect(rulings()[key("2.50")]).toMatchObject({ verdict: "keep", match: "it must be a slow news day" }); await expect(page.locator("[data-deck-ruled]")).toHaveText("2 of 6 ruled"); // Doubtful first: the voice match's unlikely, then the voice check in a note. await page.locator('[data-deck-show="doubtful"]').click(); await expect(card).toHaveAttribute("data-card", "s06"); await expect(card.locator("[data-card-voice]")).toHaveText("voice unlikely · 0.21"); await expect(page.locator(`[data-card-under="s04"]`)).toHaveCount(1); await page.locator('[data-deck-show="unruled"]').click(); await expect(card).toHaveAttribute("data-card", "s01"); await expect(page.locator("[data-deck-count]")).toContainText("1 / 4 · 1 kept · 0 cut · 1 not him · 0 read aloud"); // A swipe right keeps s01. await page.locator("[data-deck-start]").click(); await swipe(page, 420, 0); await expect.poll(() => verdictOf("0.50")).toBe("keep"); // s04: ← cuts, with a reason chip; z undoes it (the file has no ruling again); ↓ not him. await expect(card).toHaveAttribute("data-card", "s04"); await expect(card.locator("[data-card-note]")).toHaveText("voice check: co-host show"); await page.locator('[data-reason="co-host"]').click(); await page.keyboard.press("ArrowLeft"); await expect.poll(() => rulings()[key("3.50")]).toMatchObject({ verdict: "cut", reason: "co-host" }); await page.keyboard.press("z"); await expect.poll(() => verdictOf("3.50")).toBeNull(); await expect(card).toHaveAttribute("data-card", "s04"); await page.keyboard.press("ArrowDown"); await expect.poll(() => verdictOf("3.50")).toBe("not-him"); // s05: ↑ read aloud. await expect(card).toHaveAttribute("data-card", "s05"); await page.keyboard.press("ArrowUp"); await expect.poll(() => verdictOf("4.50")).toBe("read-aloud"); // s06: e edits the phrase; Enter keeps it, cut to the wider phrase. await expect(card).toHaveAttribute("data-card", "s06"); await page.keyboard.press("e"); const input = card.locator("[data-card-match]"); await expect(input).toHaveValue("slow news day"); await input.fill("a slow news day number 6"); await input.press("Enter"); await expect.poll(() => rulings()[key("5.50")]).toMatchObject({ verdict: "keep", match: "a slow news day number 6" }); // The end: the counts, the left out, and the next render -- the kept, numbered. const end = page.locator("[data-deck-summary]"); await expect(end).toContainText("3 kept · 0 cut · 2 not him · 1 read aloud"); await expect(end.locator("[data-left-out]")).toHaveCount(3); await expect(end.locator("[data-plan-kept]")).toHaveAttribute("data-plan-kept", "s01 s03 s06"); await expect(end.locator("[data-render-plan]")).toContainText("3 clips, numbered 1–3"); // No take yet: the Takes page makes one. await expect(end.locator("[data-takes-choose]")).toHaveAttribute("href", urls.takesHref(PROJECT)); // The route says the same: the very rules a build applies. const plan = (await (await request.get(`/api/report/montage-rulings?project=${encodeURIComponent(PROJECT)}`)).json()) as { plan: { kept: { id: string; n: number; of: number; match: string }[]; left: { id: string; verdict: string }[] }; }; expect(plan.plan.kept.map((k) => [k.id, k.n, k.of])).toEqual([["s01", 1, 3], ["s03", 2, 3], ["s06", 3, 3]]); expect(plan.plan.kept[2].match).toBe("a slow news day number 6"); expect(plan.plan.left.map((l) => [l.id, l.verdict])).toEqual([["s02", "not-him"], ["s04", "not-him"], ["s05", "read-aloud"]]); // Reload (the address keeps the filter, ?show=unruled): every ruling is the file's, nothing is left to rule. await page.reload(); await expect(page.locator("[data-deck-ruled]")).toHaveText("6 of 6 ruled"); await expect(page.locator("[data-deck-open]")).toContainText("every clip is ruled"); // The deck's own address opens on all six, each wearing its ruling. await page.goto(urls.clipDeckHref(PROJECT)); await expect(page.locator('[data-deck-show="all"]')).toHaveAttribute("aria-pressed", "true"); await expect(card).toHaveAttribute("data-card", "s01"); await expect(card.locator("[data-card-ruling]")).toHaveText("kept"); await expect(page.locator("[data-import-offer]")).toHaveCount(0); expect(Object.keys(rulings()).sort()).toEqual(["0.50", "1.50", "2.50", "3.50", "4.50", "5.50"].map(key).sort()); // The Cut tab counts them ruled. await page.goto(urls.section(PROJECT, "cut")); await openPanel(page, "options", "cut"); await openPanel(page, "advanced", "cut"); await expect(page.locator("[data-clip-deck-link]")).toHaveText("Clips — 6 ruled"); }); test("the clip deck at phone width: one column, the bar under the thumb, no sideways scroll", async ({ page }) => { await page.setViewportSize({ width: 390, height: 844 }); await page.goto(urls.clipDeckHref(PROJECT, { show: "all" })); await expect(page.locator("[data-card-top]")).toBeVisible(); const bar = page.locator('nav[aria-label="Rule"]'); await expect(bar).toBeVisible(); for (const a of ["undo", "cut", "not-him", "read-aloud", "keep"]) await expect(bar.locator(`[data-deck-action="${a}"]`)).toBeVisible(); const box = (await bar.boundingBox())!; expect(box.y + box.height).toBeLessThanOrEqual(844 + 1); const wide = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth); expect(wide).toBeLessThanOrEqual(0); if (process.env.P6B_SHOTS) await page.screenshot({ path: path.join(process.env.P6B_SHOTS, "clip-deck-390x844.png"), fullPage: true }); });