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"; // --------------------------------------------------------------------------- // Sections edited as sections on the Cut tab (UI notes 2026-10-30, item 1): // // cut-sections-fixture the deck on; §0 c01 c02 | §1 "Two" c03 c04 | // §2 "Three" c05 c06; draft-1.patch.json carries the // same markers. WRITES its manifest, the patch and // revisions/; every test starts from the fixture's. // // The section bars, "move to section…", "new section here" with a colour, a // boundary dragged onto a clip, ticked clips moved together, a boundary // removed -- each keeping the take patch's markers in step -- and Undo. // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const DIR = path.join(HERE, "..", ".e2e-song", "reports", "cut-sections-fixture"); const MANIFEST = path.join(DIR, "video.manifest.json"); const PATCH = path.join(DIR, "draft-1.patch.json"); const PROJECT = "reports/cut-sections-fixture"; type Marker = { after: string; label?: string; color?: string }; const read = (file: string) => JSON.parse(readFileSync(file, "utf8")); const order = () => (read(MANIFEST).timeline as { id: string }[]).map((e) => e.id); const afters = () => ((read(MANIFEST).render.chrome.deck.markers ?? []) as Marker[]).map((m) => m.after); const patchAfters = () => ((read(PATCH).render.chrome.deck.markers ?? []) as Marker[]).map((m) => m.after); test.beforeAll(() => { for (const f of [MANIFEST, PATCH]) if (!existsSync(`${f}.pristine`)) copyFileSync(f, `${f}.pristine`); }); test.beforeEach(() => { for (const f of [MANIFEST, PATCH]) copyFileSync(`${f}.pristine`, f); rmSync(path.join(DIR, "revisions"), { recursive: true, force: true }); }); async function open(page: Page) { await page.goto(urls.section(PROJECT, "timeline")); await expect(page.getByTestId("timeline-undo")).toBeEnabled(); await page.waitForLoadState("networkidle"); } test("the Cut tab draws a bar where each section opens", async ({ page }) => { await open(page); const bars = page.locator("li[data-section-bar]"); await expect(bars).toHaveCount(3); await expect(bars.nth(1)).toContainText("§1"); await expect(bars.nth(1)).toContainText("Two"); await expect(bars.nth(1)).toContainText("2 clips"); // In the list order: the bar for §1 right after c02's row. const seq = await page.locator("[data-testid=timeline-list] > li").evaluateAll((els) => els.map((e) => e.getAttribute("data-entry") ?? `§${e.getAttribute("data-section-bar")}`)); expect(seq).toEqual(["§0", "c01", "c02", "§1", "c03", "c04", "§2", "c05", "c06"]); }); test("move to section…: the clip lands at the section's end, the markers and the patch follow", async ({ page }) => { await open(page); await page.locator("[data-row-menu='c01']").click(); await page.locator("[data-row-action='to-section']").click(); await page.getByTestId("to-section-select-c01").selectOption("2"); await expect.poll(order).toEqual(["c02", "c03", "c04", "c05", "c06", "c01"]); expect(afters()).toEqual(["c02", "c04"]); expect(patchAfters()).toEqual(["c02", "c04"]); // The page has redrawn the cut (a row re-keyed by its new place loses an open menu). await expect(page.locator("[data-testid=timeline-list] > li").last()).toHaveAttribute("data-entry", "c01"); // c04 to §0: the "Three" boundary moves to c03, in the manifest and the patch. await page.locator("[data-row-menu='c04']").click(); await page.locator("[data-row-action='to-section']").click(); await page.getByTestId("to-section-select-c04").selectOption("0"); await expect.poll(order).toEqual(["c02", "c04", "c03", "c05", "c06", "c01"]); expect(afters()).toEqual(["c04", "c03"]); await expect.poll(patchAfters).toEqual(["c04", "c03"]); // Undo takes back one move at a time (one undo stack, L3: in the app every op is its own undo point). await page.getByTestId("timeline-undo").click(); await expect.poll(order).toEqual(["c02", "c03", "c04", "c05", "c06", "c01"]); await page.getByTestId("timeline-undo").click(); await expect.poll(order).toEqual(["c01", "c02", "c03", "c04", "c05", "c06"]); }); test("a section left with no clip is refused in words, nothing written", async ({ page }) => { await open(page); const before = readFileSync(MANIFEST, "utf8"); await page.locator("[data-select-clip='c03']").check(); await page.locator("[data-select-clip='c04']").check(); await expect(page.getByTestId("timeline-bulk")).toContainText("2 selected"); await page.getByTestId("timeline-bulk-section").selectOption("0"); await page.getByTestId("timeline-bulk-move").click(); await expect(page.getByTestId("timeline-error")).toContainText("§1 (Two) would have no clip left"); expect(readFileSync(MANIFEST, "utf8")).toBe(before); // Two ticked clips that leave one behind move together. await page.locator("[data-select-clip='c04']").uncheck(); await page.locator("[data-select-clip='c06']").check(); await page.getByTestId("timeline-bulk-section").selectOption("0"); await page.getByTestId("timeline-bulk-move").click(); await expect.poll(order).toEqual(["c01", "c02", "c03", "c06", "c04", "c05"]); expect(afters()).toEqual(["c06", "c04"]); }); test("new section here, with a label and a colour; edit and remove a boundary", async ({ page }) => { await open(page); await page.locator("[data-row-menu='c05']").click(); await page.locator("[data-row-action='new-section']").click(); await page.getByTestId("new-section-label-c05").fill("Four"); await page.getByTestId("new-section-color-c05").fill("#3366ff"); await page.getByTestId("new-section-add-c05").click(); await expect.poll(() => read(MANIFEST).render.chrome.deck.markers.length).toBe(3); expect(read(MANIFEST).render.chrome.deck.markers[2]).toEqual({ after: "c05", label: "Four", color: "#3366ff" }); expect(read(PATCH).render.chrome.deck.markers[2]).toEqual({ after: "c05", label: "Four", color: "#3366ff" }); await expect(page.locator("li[data-section-bar]")).toHaveCount(4); // Edit relabels it. await page.locator("[data-section-edit='2']").click(); await page.getByTestId("new-section-label-m2").fill("Four, again"); await page.getByTestId("new-section-add-m2").click(); await expect.poll(() => read(MANIFEST).render.chrome.deck.markers[2].label).toBe("Four, again"); // Remove boundary: §1 joins §0. await page.locator("[data-section-remove='0']").click(); await expect.poll(afters).toEqual(["c04", "c05"]); expect(patchAfters()).toEqual(["c04", "c05"]); }); test("a section bar dragged onto a clip moves the boundary; a clip dropped on a bar opens that section", async ({ page }) => { await open(page); // The "Three" boundary (marker 1, after c04) dragged onto c03. await page.locator("[data-bar-handle='1']").dragTo(page.locator("li[data-entry='c03'][data-kind]")); await expect.poll(afters).toEqual(["c02", "c03"]); expect(patchAfters()).toEqual(["c02", "c03"]); // The page has redrawn the bars where the file now has them (a drag on the old rows would land nowhere). await expect .poll(() => page.locator("[data-testid=timeline-list] > li").evaluateAll((els) => els.map((e) => e.getAttribute("data-entry") ?? `§${e.getAttribute("data-section-bar")}`))) .toEqual(["§0", "c01", "c02", "§1", "c03", "§2", "c04", "c05", "c06"]); await page.waitForLoadState("networkidle"); // Not past its neighbour: onto c01 is refused in words. await page.locator("[data-bar-handle='1']").dragTo(page.locator("li[data-entry='c01'][data-kind]")); await expect(page.getByTestId("timeline-error")).toContainText("would cross or touch"); // c06 dropped on §1's bar: the start of §1. await page.locator("[data-drag-handle='c06']").dragTo(page.locator("li[data-section-bar='1']")); await expect.poll(order).toEqual(["c01", "c02", "c06", "c03", "c04", "c05"]); expect(afters()).toEqual(["c02", "c03"]); });