import { test, expect, type Page } from "@playwright/test"; import { copyFileSync, existsSync, readFileSync, rmSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // Claim groups on the Cut tab and on Play's reel strip (lane L4, // lib/report/claimGroups.mjs): // // cut-groups-fixture the deck on; §0 c01 c02 c03 | §1 "Two" c04 … c08; // g1 c01 c02, g2 c04 c05, g3 c06 c07 (c03, c08 in // none). WRITES its manifest and revisions/; every test // starts from the fixture's. // // The group bars inside the section bars, the claim edited in place, a group // bar dragged onto a row (the whole group moves), a group dropped into // another's middle refused in words, a clip dragged alone into a group's // middle joining it, promote (a level-2 marker at its first clip), ungroup, // Undo, and the strip's lighter group seams. // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const DIR = path.join(HERE, "..", ".e2e-song", "reports", "cut-groups-fixture"); const MANIFEST = path.join(DIR, "video.manifest.json"); const PROJECT = "reports/cut-groups-fixture"; type Group = { id: string; section: number; claim: string; ids: string[] }; type Marker = { after: string; label?: string; level?: number }; const read = () => JSON.parse(readFileSync(MANIFEST, "utf8")) as { timeline: { id: string }[]; groups?: Group[]; render: { chrome: { deck: { markers?: Marker[] } } } }; const order = () => read().timeline.map((e) => e.id).join(" "); const groups = () => (read().groups ?? []).map((g) => `${g.id}@${g.section}:${g.ids.join(",")}`).join(" "); const list = (page: Page) => page.locator("[data-testid=timeline-list] > li").evaluateAll((els) => els.map((e) => e.getAttribute("data-entry") ?? (e.hasAttribute("data-group-bar") ? `g:${e.getAttribute("data-group-bar")}` : `§${e.getAttribute("data-section-bar")}`)), ); 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 }); }); async function open(page: Page) { await page.goto(urls.section(PROJECT, "timeline")); await settled(page); } /** The list has its token and no write is in flight. */ async function settled(page: Page) { await expect(page.getByTestId("timeline-undo")).toBeEnabled({ timeout: 20_000 }); await page.waitForLoadState("networkidle"); } const POLL = { timeout: 20_000 }; test("the Cut tab draws each group's bar inside its section, its clips under it", async ({ page }) => { await page.setViewportSize({ width: 1366, height: 1000 }); await open(page); await expect.poll(() => list(page)).toEqual(["§0", "g:g1", "c01", "c02", "c03", "§1", "g:g2", "c04", "c05", "g:g3", "c06", "c07", "c08"]); const g2 = page.locator("li[data-group-bar='g2']"); await expect(g2).toContainText("The second claim, said twice"); await expect(g2).toContainText("2 clips"); await expect(g2).toHaveAttribute("data-group-section", "1"); await expect(page.locator("li[data-entry='c04'][data-kind]")).toHaveAttribute("data-group", "g2"); await expect(page.locator("li[data-entry='c03'][data-kind]")).not.toHaveAttribute("data-group", /./); // The bar is inside its section: indented past the section bar's edge, its clips past the bar's. const x = async (sel: string) => (await page.locator(sel).boundingBox())!.x; expect(await x("li[data-group-bar='g2']")).toBeGreaterThan(await x("li[data-section-bar='1']")); expect(await x("li[data-entry='c04'][data-kind]")).toBeGreaterThan(await x("li[data-group-bar='g2']")); await page.locator("li[data-section-bar='1']").scrollIntoViewIfNeeded(); await page.screenshot({ path: test.info().outputPath("cut-groups-bars.png"), fullPage: true }); }); test("a claim is edited in place: Enter saves it, Escape leaves it", async ({ page }) => { await open(page); await page.locator("[data-group-claim='g3']").click(); const input = page.locator("[data-group-claim-input='g3']"); await input.fill("A third, reworded"); await input.press("Escape"); await expect(page.locator("[data-group-claim='g3']")).toHaveText("A third"); await page.locator("[data-group-claim='g3']").click(); await input.fill("A third, reworded"); await input.press("Enter"); await expect.poll(() => read().groups?.find((g) => g.id === "g3")?.claim, POLL).toBe("A third, reworded"); await expect(page.locator("[data-group-claim='g3']")).toHaveText("A third, reworded"); }); test("a group bar dragged onto a row moves the whole group before it; into another group's middle is refused; Undo", async ({ page }) => { // Tall enough that nothing scrolls between the press and the drop (a scroll mid-drag picks up another handle). await page.setViewportSize({ width: 1366, height: 2200 }); await open(page); await page.locator("[data-group-handle='g3']").dragTo(page.locator("li[data-entry='c04'][data-kind]")); await expect.poll(order, POLL).toBe("c01 c02 c03 c06 c07 c04 c05 c08"); expect(groups()).toBe("g1@0:c01,c02 g2@1:c04,c05 g3@1:c06,c07"); // The boundary stays where it was: g3 is in §1, before g2. expect(read().render.chrome.deck.markers?.map((m) => m.after)).toEqual(["c03"]); await expect.poll(() => list(page), POLL).toEqual(["§0", "g:g1", "c01", "c02", "c03", "§1", "g:g3", "c06", "c07", "g:g2", "c04", "c05", "c08"]); await settled(page); const before = readFileSync(MANIFEST, "utf8"); await page.locator("[data-group-handle='g1']").dragTo(page.locator("li[data-entry='c05'][data-kind]")); await expect(page.getByTestId("timeline-error")).toContainText("g2 (\"The second claim, said twice\")'s clips are not together"); expect(readFileSync(MANIFEST, "utf8")).toBe(before); await page.getByTestId("timeline-undo").click(); await expect.poll(order, POLL).toBe("c01 c02 c03 c04 c05 c06 c07 c08"); }); test("a clip dragged alone into the middle of a group joins it; out of its run, it leaves", async ({ page }) => { await open(page); await page.locator("[data-drag-handle='c08']").dragTo(page.locator("li[data-entry='c05'][data-kind]")); await expect.poll(order, POLL).toBe("c01 c02 c03 c04 c08 c05 c06 c07"); await expect.poll(groups, POLL).toBe("g1@0:c01,c02 g2@1:c04,c08,c05 g3@1:c06,c07"); await expect(page.locator("li[data-entry='c08'][data-kind]")).toHaveAttribute("data-group", "g2"); await expect(page.locator("li[data-group-bar='g2']")).toContainText("3 clips"); await settled(page); // c06 onto c03's row: out of g3's run (detached), at g1's edge (it joins nothing). await page.locator("[data-drag-handle='c06']").dragTo(page.locator("li[data-entry='c03'][data-kind]")); await expect.poll(order, POLL).toBe("c01 c02 c06 c03 c04 c08 c05 c07"); await expect.poll(groups, POLL).toBe("g1@0:c01,c02 g2@1:c04,c08,c05 g3@1:c07"); await expect(page.locator("li[data-entry='c06'][data-kind]")).not.toHaveAttribute("data-group", /./); }); test("promote: the group opens a subsection titled with its claim; ungroup leaves its clips where they are", async ({ page }) => { await open(page); await page.locator("[data-group-promote='g3']").click(); await expect(page.locator("[data-group-promote-label='g3']")).toHaveValue("A third"); await page.locator("[data-group-promote-go='g3']").click(); await expect.poll(() => read().render.chrome.deck.markers, POLL).toEqual([ { after: "c03", label: "Two", color: "#ff5a5a" }, { after: "c05", label: "A third", level: 2 }, ]); await expect(page.locator("[data-group-subsection='g3']")).toBeVisible(); await settled(page); await expect(page.locator("li[data-section-bar='2']")).toHaveAttribute("data-section-level", "2"); // A claim over a marker's 24 characters cannot be the title: the button waits for a shorter one. await page.locator("[data-group-promote='g2']").click(); await expect(page.locator("[data-group-promote-go='g2']")).toBeDisabled(); await page.locator("[data-group-promote-label='g2']").fill("Said twice"); await expect(page.locator("[data-group-promote-go='g2']")).toBeEnabled(); await page.keyboard.press("Escape"); await page.locator("[data-group-ungroup='g1']").click(); await expect.poll(groups, POLL).toBe("g2@1:c04,c05 g3@2:c06,c07"); expect(order()).toBe("c01 c02 c03 c04 c05 c06 c07 c08"); await expect(page.locator("li[data-group-bar='g1']")).toHaveCount(0); }); test("Play's reel strip draws a group's seam lighter than a section's", async ({ page }) => { await page.setViewportSize({ width: 1366, height: 1000 }); await page.goto(urls.playHref(PROJECT)); await expect(page.locator("[data-play-cut]")).toHaveAttribute("data-play-state", "paused", { timeout: 30_000 }); // §1 opens at c04 (a section's seam); g3 at c06 (a group's); g1 opens the cut and g2 a section: no seam of their own. await expect(page.locator("[data-strip-seam='c04']")).toHaveCount(1); await expect(page.locator("[data-strip-group-seam]")).toHaveCount(1); const seam = page.locator("[data-strip-group-seam='c06']"); await expect(seam).toHaveAttribute("data-strip-group", "g3"); const look = (sel: string) => page.locator(sel).evaluate((el) => { const s = getComputedStyle(el); return { opacity: Number(s.opacity), height: el.getBoundingClientRect().height }; }); const sec = await look("[data-strip-seam='c04']"); const grp = await look("[data-strip-group-seam='c06']"); expect(grp.opacity).toBeLessThan(sec.opacity); expect(grp.height).toBeLessThan(sec.height); await page.locator("[data-play-strip]").screenshot({ path: test.info().outputPath("play-group-seams.png") }); });