import { test, expect, type Page } from "@playwright/test"; import { execFileSync } from "node:child_process"; import { copyFileSync, existsSync, readFileSync, rmSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // The candidates inbox on the Cut tab (UI notes item 14, lib/report/candidates.mjs): // // candidates-fixture the deck on: §0 c01 c02 | §1 "As a streamer" c03 c04 | // §2 "Looks" c05 c06, g1 c03 c04; sweep.md beside it in the // /sweep shape. WRITES its manifest, revisions/ and // candidates.json; every test starts from the fixture's. // // A sweep imported from a terminal (`umtool candidates
import`), its rows on // the panel with the verdict and the place each proposes; Play in the page from // a cached window; Insert into section (its end, the marker after the new clip); // Insert into group (after the group's last clip, one of its clips); Not this // (recorded, hidden, kept); nothing in the cut until a press. // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const FIXTURE = path.join(HERE, "..", ".e2e-song"); const DIR = path.join(FIXTURE, "reports", "candidates-fixture"); const MANIFEST = path.join(DIR, "video.manifest.json"); const STORE = path.join(DIR, "candidates.json"); const PROJECT = "reports/candidates-fixture"; const SHOTS = process.env.U4_SHOTS ?? null; type Manifest = { timeline: { id: string; quote?: string; video?: string }[]; groups?: { id: string; ids: string[] }[]; render: { chrome: { deck: { markers?: { after: string }[] } } } }; const read = () => JSON.parse(readFileSync(MANIFEST, "utf8")) as Manifest; const order = () => read().timeline.map((e) => e.id).join(" "); const store = () => JSON.parse(readFileSync(STORE, "utf8")) as { candidates: { id: string; video: string; status: string; inserted?: { clip: string }; dismissed?: { at: string } }[] }; function importSweep() { return execFileSync("node", ["bin/umtool.mjs", "candidates", PROJECT, "import", path.join(DIR, "sweep.md")], { cwd: path.join(HERE, ".."), encoding: "utf8", env: { ...process.env, REPORTS_DIR: FIXTURE, CHANNELS_DIR: path.join(FIXTURE, "channels"), UMTOOL_CACHE_DIR: path.join(FIXTURE, "cache"), UMTOOL_MEDIA_DIR: "" }, }); } test.beforeAll(() => { if (!existsSync(`${MANIFEST}.pristine`)) copyFileSync(MANIFEST, `${MANIFEST}.pristine`); }); test.beforeEach(() => { test.setTimeout(90_000); copyFileSync(`${MANIFEST}.pristine`, MANIFEST); rmSync(path.join(DIR, "revisions"), { recursive: true, force: true }); rmSync(STORE, { force: true }); }); async function open(page: Page) { await page.goto(urls.section(PROJECT, "timeline")); await expect(page.getByTestId("candidates")).toBeVisible({ timeout: 20_000 }); } /** The Cut tab, with no candidates file yet: no panel, one line in the timeline's heading. */ async function openEmpty(page: Page) { await page.goto(urls.section(PROJECT, "timeline")); await expect(page.locator("[data-candidates-empty]")).toBeVisible({ timeout: 20_000 }); await expect(page.getByTestId("candidates")).toHaveCount(0); } const row = (page: Page, video: string) => page.locator(`[data-candidate-video='${video}']`); const idOf = (video: string) => store().candidates.find((c) => c.video === video)!.id; test("empty, the panel says how proposals come in; an import lands them proposed, the cut untouched", async ({ page }) => { await openEmpty(page); await expect(page.locator("[data-candidates-empty]")).toContainText(`umtool candidates ${PROJECT} import`); const before = order(); const out = importSweep(); expect(out).toMatch(/4 added/); // A re-import changes nothing it holds. expect(importSweep()).toMatch(/0 added, 4 already there/); expect(order()).toBe(before); await open(page); await expect(page.getByTestId("candidates")).toHaveAttribute("data-candidates-proposed", "4"); // The Top 5's first leads the list. await expect(page.locator("[data-candidate]").first()).toHaveAttribute("data-candidate-video", "v1234567"); await expect(row(page, "v1234567")).toContainText("#1 overall"); await expect(row(page, "vid2")).toContainText("strengthens c04"); await expect(row(page, "vid2").locator("[data-candidate-place]")).toContainText("§1 (As a streamer) · group g1 (c04's group (g1))"); await expect(row(page, "W4pgGUq5ygQ").locator("[data-candidate-place]")).toContainText("§2 (Looks)"); await expect(row(page, "W4pgGUq5ygQ")).toContainText("“I respect that looks sell.”"); // A new claim names no clip: its place is the deck section of the heading it stands under. await expect(row(page, "v1234567").locator("[data-candidate-place]")).toContainText("§1 (As a streamer) (the sweep's heading)"); // The proposed place is preselected. await expect(page.locator(`[data-candidate-section='${idOf("W4pgGUq5ygQ")}']`)).toHaveValue("2"); await expect(page.locator(`[data-candidate-group='${idOf("vid2")}']`)).toHaveValue("g1"); if (SHOTS) { await page.setViewportSize({ width: 1366, height: 1100 }); await page.getByTestId("candidates").scrollIntoViewIfNeeded(); await page.getByTestId("candidates").screenshot({ path: path.join(SHOTS, "14-candidates-imported.png") }); } }); test("Play: a cached window plays the cited second here; one with none opens the archive at it", async ({ page }) => { importSweep(); await open(page); const id = idOf("vid2"); await page.locator(`button[data-candidate-play='${id}']`).click(); const player = page.locator(`[data-candidate-player='${id}']`); await expect(player).toBeVisible(); await expect.poll(() => player.evaluate((v: HTMLVideoElement) => v.currentTime), { timeout: 15_000 }).toBeGreaterThanOrEqual(2.9); const far = page.locator(`a[data-candidate-play='${idOf("W4pgGUq5ygQ")}']`); await expect(far).toHaveAttribute("href", "https://archive.example/?v=testchan%2FW4pgGUq5ygQ&t=284"); await expect(far).toHaveAttribute("target", "_blank"); }); test("Insert into section: at its end, the next marker after the new clip; Insert into group: after its last clip, one of its clips", async ({ page }) => { importSweep(); await open(page); const looks = idOf("W4pgGUq5ygQ"); await page.locator(`[data-candidate-insert-section='${looks}']`).click(); await expect(row(page, "W4pgGUq5ygQ")).toHaveCount(0); await expect.poll(order).toBe("c01 c02 c03 c04 c05 c06 W4pgGUq5ygQ-284"); const e = read().timeline.at(-1)!; expect(e.quote).toBe("I respect that looks sell."); expect(store().candidates.find((c) => c.id === looks)!.inserted!.clip).toBe("W4pgGUq5ygQ-284"); // The Cut tab's list has it, in §2. await expect(page.locator("li[data-entry='W4pgGUq5ygQ-284'] [data-row-section]")).toHaveAttribute("data-row-section", "2"); // A section that is not the last: §0's marker moves after the new clip. const voice = idOf("v1234567"); await page.locator(`[data-candidate-section='${voice}']`).selectOption("0"); await page.locator(`[data-candidate-insert-section='${voice}']`).click(); await expect.poll(order).toBe("c01 c02 v1234567-3766 c03 c04 c05 c06 W4pgGUq5ygQ-284"); expect(read().render.chrome.deck.markers![0].after).toBe("v1234567-3766"); const grp = idOf("vid2"); // An undo point is named by its second (lib/report/snapshots.mjs): two writes inside one second // share one. A person's presses are seconds apart; the spec's are not, so it waits one out. await page.waitForTimeout(1100); await page.locator(`[data-candidate-insert-group='${grp}']`).click(); await expect.poll(() => store().candidates.find((c) => c.id === grp)!.status).toBe("inserted"); // Its id is the recording and its start: the window starts where the sentence does (vid2's cues). const gid = store().candidates.find((c) => c.id === grp)!.inserted!.clip; expect(gid).toMatch(/^vid2-\d+$/); await expect.poll(order).toBe(`c01 c02 v1234567-3766 c03 c04 ${gid} c05 c06 W4pgGUq5ygQ-284`); expect(read().groups!.find((g) => g.id === "g1")!.ids).toEqual(["c03", "c04", gid]); expect(read().render.chrome.deck.markers![1].after).toBe(gid); await expect(page.locator(`li[data-entry='${gid}'][data-kind]`)).toHaveAttribute("data-group", "g1"); // Each insert an undo point. await page.getByTestId("timeline-undo").click(); await expect.poll(order).toBe("c01 c02 v1234567-3766 c03 c04 c05 c06 W4pgGUq5ygQ-284"); // Undone, the candidate waits again and says what it was. await expect(row(page, "vid2").locator("[data-candidate-left]")).toHaveAttribute("data-candidate-left", gid); await expect(row(page, "vid2")).toHaveAttribute("data-candidate-status", "proposed"); if (SHOTS) { await page.reload(); await page.locator("[data-candidates-show-done]").click(); await page.setViewportSize({ width: 1366, height: 1300 }); await page.screenshot({ path: path.join(SHOTS, "14-candidates-inserted.png"), fullPage: true }); } }); test("Not this: recorded and hidden, never deleted; shown again with the done rows", async ({ page }) => { importSweep(); await open(page); const id = idOf("XCERAAfIePY"); const before = order(); await page.locator(`[data-candidate-dismiss='${id}']`).click(); await expect(row(page, "XCERAAfIePY")).toHaveCount(0); await expect(page.getByTestId("candidates")).toHaveAttribute("data-candidates-proposed", "3"); const r = store().candidates.find((c) => c.id === id)!; expect(r.status).toBe("dismissed"); expect(r.dismissed!.at).toBeTruthy(); expect(store().candidates).toHaveLength(4); expect(order()).toBe(before); // Importing the sweep again does not bring it back. importSweep(); await page.reload(); await expect(page.getByTestId("candidates")).toHaveAttribute("data-candidates-proposed", "3"); await page.locator("[data-candidates-show-done]").click(); await expect(row(page, "XCERAAfIePY")).toHaveAttribute("data-candidate-status", "dismissed"); await expect(row(page, "XCERAAfIePY")).toContainText("not this"); });