import { test, expect, type APIRequestContext, type Page } from "@playwright/test"; import { mkdirSync, readFileSync, writeFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // Gaps inside a clip (umtool-report-to-video gaps.mjs) and the bench // waveform's zoom (components/projects/bench/GapsZoom.tsx): // // - the waveform zooms (+ / − / Fit, Ctrl + wheel at the pointer, the keys) // and pans (the wheel, the overview strip); close in it draws the measured // silences; at fit it is what it always was // - a span selected on the waveform (Select a gap, or Alt + drag) is cut out // of the clip through the window writer; Undo puts the list back; a click // on a gap's band picks it, its Remove puts it back; a span the build would refuse is refused here // - the bench's playback skips a gap, as the cut will // - Play the cut plays the clip as ONE item of jump cuts: the render's // footage less the gap, one sound node per kept piece, the picture past // the gap at the join, a tick on the reel strip // // Fixture: gaps-fixture (make-fixture.mjs), which this spec WRITES: g01 // gapvid 0.5-8.5 and g02 1.0-3.0, both locked, on the fixture's tone window // (silences 2.9-3.1, 5.9-6.1) cached as gapvid_0.00-9.00.mp4; 15 fps. // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const PROJECT = "reports/gaps-fixture"; const MANIFEST = path.join(HERE, "..", ".e2e-song", "reports", "gaps-fixture", "video.manifest.json"); type Gap = { from: number; to: number }; const clipOf = (id: string) => (JSON.parse(readFileSync(MANIFEST, "utf8")) as { timeline: { id: string; start: number; end: number; gaps?: Gap[] }[] }).timeline.find((e) => e.id === id)!; const token = async (request: APIRequestContext, clip = "g01") => ((await (await request.get(`/api/report/clip?project=${encodeURIComponent(PROJECT)}&clip=${clip}`)).json()) as { token: string }).token; const putWindow = async (request: APIRequestContext, data: Record, clip = "g01") => request.put("/api/report/window", { data: { project: PROJECT, clip, token: await token(request, clip), ...data } }); /** The bench, with its waveform scrolled on screen (the mouse only reaches what is in the viewport). */ const openBench = async (page: Page, clip = "g01") => { await page.goto(urls.clipBenchHref(PROJECT, clip)); await page.locator("[data-wave-box]").scrollIntoViewIfNeeded(); await expect(page.locator("[data-wave-box]")).toBeInViewport(); }; /** The waveform's shown span, [from, to] (data-wave-vis). */ const visOf = async (page: Page) => { const v = (await page.locator("[data-wave-box]").getAttribute("data-wave-vis"))!; const [a, b] = v.split("-").map(Number); return { from: a, to: b }; }; /** A source second's x on the waveform, as shown now. */ const xAt = async (page: Page, t: number) => { const b = (await page.locator("[data-wave-box]").boundingBox())!; const v = await visOf(page); return b.x + ((t - v.from) / (v.to - v.from)) * b.width; }; const tAtX = async (page: Page, x: number) => { const b = (await page.locator("[data-wave-box]").boundingBox())!; const v = await visOf(page); return v.from + ((x - b.x) / b.width) * (v.to - v.from); }; const midY = async (page: Page) => { const b = (await page.locator("[data-wave-box]").boundingBox())!; return b.y + b.height / 2; }; /** Drag on the waveform from source second a to b. */ const dragSpan = async (page: Page, a: number, b: number) => { await page.locator("[data-wave-box]").scrollIntoViewIfNeeded(); const y = await midY(page); await page.mouse.move(await xAt(page, a), y); await page.mouse.down(); await page.mouse.move((await xAt(page, a) + (await xAt(page, b))) / 2, y, { steps: 3 }); await page.mouse.move(await xAt(page, b), y, { steps: 3 }); await page.mouse.up(); }; const spanOf = (s: string | null) => (s ?? "").split("-").map(Number); /** The bench's keyboard is attached on hydration: prove it with `x` (opens Reject ▾'s reasons, writes nothing; Escape closes them). */ const keyboardLive = async (page: Page) => { const menu = page.locator("[data-reject-menu]"); await expect(async () => { await page.locator("body").press("x"); await expect(menu).toBeVisible({ timeout: 500 }); }).toPass({ timeout: 10_000 }); await page.locator("body").press("Escape"); await expect(menu).toHaveCount(0); }; test.beforeEach(async ({ request }) => { test.setTimeout(120_000); // Every test starts from no gaps. const r = await putWindow(request, { gaps: [] }); expect(r.ok(), await r.text()).toBeTruthy(); }); test("the bench waveform zooms at the pointer, pans, and fits back to what it always was", async ({ page }) => { await openBench(page); const zoom = page.locator("[data-wave-zoom]"); await expect(zoom).toHaveAttribute("data-wave-zoom", "fit"); await expect(page.locator("[data-zoom-ruler]")).toHaveCount(0); await expect(page.locator("[data-zoom-overview]")).toHaveCount(0); const whole = await visOf(page); // + zooms in (about the playhead, else the middle): a ruler and the overview appear. await page.locator("[data-zoom-in]").click(); await page.locator("[data-wave-box]").scrollIntoViewIfNeeded(); await expect(zoom).not.toHaveAttribute("data-wave-zoom", "fit"); await expect(page.locator("[data-zoom-ruler]")).toBeVisible(); await expect(page.locator("[data-zoom-overview]")).toBeVisible(); let v = await visOf(page); expect(v.to - v.from).toBeCloseTo((whole.to - whole.from) / 1.6, 2); // Ctrl + wheel at the pointer: the second under it stays under it. const x3 = await xAt(page, 3); await page.mouse.move(x3, await midY(page)); await page.keyboard.down("Control"); await page.mouse.wheel(0, -240); await page.keyboard.up("Control"); await expect.poll(async () => (await visOf(page)).to - (await visOf(page)).from).toBeLessThan(v.to - v.from - 0.5); expect(await tAtX(page, x3)).toBeCloseTo(3, 1); v = await visOf(page); // The wheel alone pans while zoomed. await page.mouse.wheel(0, 120); await expect.poll(async () => (await visOf(page)).from).toBeGreaterThan(v.from + 0.05); const panned = await visOf(page); expect(panned.to - panned.from).toBeCloseTo(v.to - v.from, 2); // The overview: its window is what is shown; dragging it pans back. await page.locator("[data-zoom-overview]").scrollIntoViewIfNeeded(); const win = page.locator("[data-zoom-window]"); const wb = (await win.boundingBox())!; await page.mouse.move(wb.x + wb.width / 2, wb.y + wb.height / 2); await page.mouse.down(); await page.mouse.move(wb.x + wb.width / 2 - 60, wb.y + wb.height / 2, { steps: 4 }); await page.mouse.up(); await expect.poll(async () => (await visOf(page)).from).toBeLessThan(panned.from - 0.1); // Close in, the measured silences are drawn (the cut-points route's: 2.9-3.1 on this window). await page.locator("[data-zoom-fit]").click(); await page.locator("[data-wave-box]").scrollIntoViewIfNeeded(); await expect(zoom).toHaveAttribute("data-wave-zoom", "fit"); await page.mouse.move(await xAt(page, 3), await midY(page)); await page.keyboard.down("Control"); for (let i = 0; i < 3; i += 1) await page.mouse.wheel(0, -300); await page.keyboard.up("Control"); await expect.poll(async () => (await visOf(page)).to - (await visOf(page)).from).toBeLessThan(3); await expect(page.locator("[data-wave-silence]").first()).toBeVisible({ timeout: 30_000 }); const sil = spanOf(await page.locator("[data-wave-silence]").first().getAttribute("data-wave-silence")); expect(sil[0]).toBeGreaterThan(2.8); expect(sil[1]).toBeLessThan(3.2); // Finer ticks: under a second apart. expect(Number(await page.locator("[data-zoom-ruler]").getAttribute("data-zoom-ruler"))).toBeLessThan(1); // The keys: f fits, z zooms in, Z out. await keyboardLive(page); await page.locator("body").press("f"); await expect(zoom).toHaveAttribute("data-wave-zoom", "fit"); await page.locator("body").press("z"); await expect(zoom).not.toHaveAttribute("data-wave-zoom", "fit"); await page.locator("body").press("Shift+Z"); await expect(zoom).toHaveAttribute("data-wave-zoom", "fit"); }); test("a gap: selected on the waveform, cut, undone; Alt + drag and g; a click on its band puts it back; refusals", async ({ page, request }) => { await openBench(page); await expect(page.locator("[data-gaps]")).toHaveAttribute("data-gaps", ""); const before = clipOf("g01"); // Select a gap, drag 3.5 → 5.5 on the waveform. await page.locator("[data-gap-pick]").click(); await expect(page.locator("[data-gap-pick=armed]")).toBeVisible(); await dragSpan(page, 3.5, 5.5); const sel = spanOf(await page.locator("[data-gap-selection]").getAttribute("data-gap-selection")); expect(sel[0]).toBeCloseTo(3.5, 1); expect(sel[1]).toBeCloseTo(5.5, 1); await expect(page.locator("[data-bench-note]")).toContainText("selected"); await page.locator("[data-gap-cut]").click(); await expect.poll(() => clipOf("g01").gaps?.length ?? 0).toBe(1); const g = clipOf("g01").gaps![0]; expect(g.from).toBeCloseTo(3.5, 1); expect(g.to).toBeCloseTo(5.5, 1); // The edges did not move; the band is drawn; the summary says what plays. expect([clipOf("g01").start, clipOf("g01").end]).toEqual([before.start, before.end]); await expect(page.locator("[data-gap-band]")).toHaveCount(1); await expect(page.locator("[data-gaps-summary]")).toContainText(/the cut plays \d\.\d\d s of 8\.00 s, one segment/); await expect(page.locator("[data-rail-gap]")).toHaveCount(1); // Undo writes the list back as it was. await page.locator("[data-gap-undo]").click(); await expect.poll(() => clipOf("g01").gaps).toBeUndefined(); await expect(page.locator("[data-gap-band]")).toHaveCount(0); // Alt + drag selects without arming, and never moves an edge; `g` cuts it. await page.keyboard.down("Alt"); await dragSpan(page, 4, 5); await page.keyboard.up("Alt"); await expect(page.locator("[data-gap-selection]")).toBeVisible(); expect([clipOf("g01").start, clipOf("g01").end]).toEqual([before.start, before.end]); await expect(page.locator("[data-save-window]")).toBeDisabled(); await keyboardLive(page); await page.locator("body").press("g"); await expect.poll(() => clipOf("g01").gaps?.length ?? 0).toBe(1); expect(clipOf("g01").gaps![0].from).toBeCloseTo(4, 1); // A click on the band picks the gap (its settings, lane gap-cue); its Remove puts the seconds back. await page.locator("[data-gap-band]").click(); await expect(page.locator("[data-gap-picked-row]")).toBeVisible(); await page.locator("[data-gap-remove]").click(); await expect.poll(() => clipOf("g01").gaps).toBeUndefined(); // Too close to the clip's start: said, and nothing written. await page.locator("[data-gap-pick]").click(); await dragSpan(page, 0.7, 1.4); await expect(page.locator("[data-bench-note]")).toContainText("cannot be cut"); await page.locator("[data-gap-cut]").click(); await expect(page.locator("[data-bench-note]")).toContainText("keep at least 0.5 s"); expect(clipOf("g01").gaps).toBeUndefined(); // The writer's own refusals, through the route. let r = await putWindow(request, { gapAdd: "0.6-1" }); expect(r.status()).toBe(400); expect(((await r.json()) as { error: string }).error).toMatch(/keep at least 0.5 s/); r = await putWindow(request, { gapAdd: "3.5-5.5" }); expect(r.ok()).toBeTruthy(); r = await putWindow(request, { muteFrom: 4 }); expect(r.status()).toBe(400); expect(((await r.json()) as { error: string }).error).toMatch(/inside the gap 3\.5–5\.5, which never plays/); }); test("the bench plays across a gap the way the cut will: the gap is skipped", async ({ page, request }) => { expect((await putWindow(request, { gapAdd: "3.5-5.5" })).ok()).toBeTruthy(); await page.goto(urls.clipBenchHref(PROJECT, "g01")); const playback = page.locator("[data-playback]"); await expect(playback).toHaveAttribute("data-audio-state", "ready", { timeout: 15_000 }); await expect(page.locator("[data-gap-band]")).toHaveCount(1); await keyboardLive(page); await page.locator("body").press(" "); await expect(playback).toHaveAttribute("data-play-state", "playing", { timeout: 10_000 }); expect(await playback.getAttribute("data-play-engine")).toBe("webaudio"); const a = Number(await playback.getAttribute("data-play-ctx-start")); const b = Number(await playback.getAttribute("data-play-ctx-stop")); // 0.5-8.5 less the 2 s gap: six seconds of sound, not eight. expect(b - a).toBeCloseTo(6, 2); expect(Number(await playback.getAttribute("data-play-to"))).toBeCloseTo(8.5, 2); await page.locator("body").press(" "); }); /** * Play the cut (or `take`) plays g01 -- gap 3.5-5.5 -- as one item of jump cuts: the jump * on the reel strip 3 s in, no frame from inside the gap, two sound nodes abutting at the join. */ const playsJumpCut = async (page: Page, take: string | null = null) => { await page.goto(urls.playHref(PROJECT, { take })); const root = page.locator("[data-play-cut]"); await expect(root).toHaveAttribute("data-play-cut", take ?? ""); await expect(root).toHaveAttribute("data-play-edges", "render", { timeout: 30_000 }); await expect(root).toHaveAttribute("data-play-item", "g01"); // The jump cut on the reel strip, 3 s into the clip. await expect(page.locator("[data-play-gap]")).toHaveAttribute("data-play-gap", "g01@3"); await page.locator("[data-play-toggle]").click(); await expect(root).toHaveAttribute("data-play-sound", "webaudio", { timeout: 15_000 }); // Past the join: the picture is the material after the gap (5.5 on), never 3.5-5.5. Every // frame drawn while g01 plays is said (data-play-drawn): none from inside the gap. const seen: string[] = []; await expect .poll(async () => { const t = Number(await root.getAttribute("data-play-t")); const d = (await page.locator("[data-play-footage]").getAttribute("data-play-drawn")) ?? ""; seen.push(`${t.toFixed(2)}=${d}`); const [id, at] = d.split(":"); return id === "g01" && t > 3.2 ? Number(at) : -1; }, { timeout: 20_000, intervals: [100] }) .toBeGreaterThan(5.5); console.log(`gaps-zoom${take ? ` (take ${take})` : ""}: drawn ${seen.join(" ")}`); const inGap = seen.map((x) => x.split("=")[1]).filter((d) => d.startsWith("g01:")).map((d) => Number(d.split(":")[1])).filter((at) => at > 3.6 && at < 5.4); expect(inGap, "no frame from inside the gap").toEqual([]); // Two sound nodes for g01, abutting at the join (cut second 3), and g02 after its six seconds. const s = await page.evaluate( () => (window as unknown as { __umtoolPlayEngine: { stats: { scheduled: { id: string; from: number; to: number; run: number }[] } } }).__umtoolPlayEngine.stats, ); const mine = s.scheduled.filter((n) => n.id === "g01"); const run = mine[mine.length - 1].run; const pieces = mine.filter((n) => n.run === run).sort((x, y) => x.from - y.from); expect(pieces.length).toBe(2); expect(pieces[0].to).toBeCloseTo(3, 2); expect(pieces[1].from).toBeCloseTo(3, 2); expect(pieces[1].to).toBeCloseTo(6, 2); await page.keyboard.press("k"); }; test("Play the cut plays a gapped clip as one item of jump cuts", async ({ page, request }) => { expect((await putWindow(request, { gapAdd: "3.5-5.5" })).ok()).toBeTruthy(); // The render's cut: the gap on the frame grid, the footage the kept seconds. const got = await (await request.get(`/api/report/cut-points?project=${encodeURIComponent(PROJECT)}`)).json(); const g01 = got.clips.find((c: { id: string }) => c.id === "g01"); expect(g01).toMatchObject({ cutStart: 0.5, cutEnd: 8.5, gaps: [{ from: 3.5, to: 5.5 }], footage: 6 }); await playsJumpCut(page); }); // A TAKE plays its gaps too (operator, 1 Nov 2026: a gapped clip played whole in a take's // Play the cut while the take's render left the gap out). The take is the project's cut // with its patch -- here a retitle and the deck on, as a real take's is -- so the gap // is the project's, written after the take was made, and the take's view must keep it. test("Play the cut on a take plays a gapped clip's kept pieces only", async ({ page, request }) => { expect((await putWindow(request, { gapAdd: "3.5-5.5" })).ok()).toBeTruthy(); const dir = path.join(path.dirname(MANIFEST), "takes", "gapped"); mkdirSync(dir, { recursive: true }); writeFileSync( path.join(dir, "take.json"), `${JSON.stringify({ id: "gapped", group: "takes", order: 1, label: "Gapped", kind: "different", summary: "", preview: "preview.mp4", window: "full", patch: { title: "The Gaps Fixture, a take", render: { chrome: { engine: "hyperframes", layout: "deck", deck: {} } } }, }, null, 2)}\n`, ); // The take's render cut names the gap as the project's does. const got = await (await request.get(`/api/report/cut-points?project=${encodeURIComponent(PROJECT)}&take=gapped`)).json(); expect(got.clips.find((c: { id: string }) => c.id === "g01")).toMatchObject({ cutStart: 0.5, cutEnd: 8.5, gaps: [{ from: 3.5, to: 5.5 }], footage: 6 }); await playsJumpCut(page, "gapped"); }); // --------------------------------------------------------------------------- // The bench's two modes (lane/bench-modes; operator, 6 Nov: "this split // between the clip and the cut is hard to reason around. Can it be a // switchable mode instead and we start in cut mode?"). Cut mode -- every time // the bench opens -- the handles are what plays; dragged past the extent they // grow it, in one write with one undo. Clip mode: the handles are the extent, // the cut a band inside it that comes in with an extent pulled past it. // --------------------------------------------------------------------------- const cutOf = () => { const e = (JSON.parse(readFileSync(MANIFEST, "utf8")) as { timeline: { id: string; start: number; end: number; cutStart?: number; cutEnd?: number }[] }).timeline.find((x) => x.id === "g01")!; return { start: e.start, end: e.end, cutStart: e.cutStart ?? null, cutEnd: e.cutEnd ?? null }; }; const SHOTS = process.env.E2E_CLIP_FIXES_SHOTS ?? null; const shot = async (page: Page, name: string, whole = false) => { if (!SHOTS) return; mkdirSync(SHOTS, { recursive: true }); const box = page.locator("[data-wave-box]"); if (!whole) { await box.screenshot({ path: path.join(SHOTS, `${name}.png`) }); return; } // The mode row, the waveform and its tools: the instrument's whole column. await page.locator("[data-bench-sel]").screenshot({ path: path.join(SHOTS, `${name}.png`) }); }; /** Drag a waveform handle (the one nearer `a`) from source second a to b. */ const dragHandle = async (page: Page, a: number, b: number) => { await page.locator("[data-wave-box]").scrollIntoViewIfNeeded(); const y = await midY(page); await page.mouse.move(await xAt(page, a), y); await page.mouse.down(); await page.mouse.move(await xAt(page, b), y, { steps: 5 }); await page.mouse.up(); }; test("a clip with a cut opens in Cut mode: the handles are what plays, dragged past the extent they grow it in one write with one undo; Clip mode edits the extent with the cut a band inside", async ({ page, request }) => { expect((await putWindow(request, { cutStart: 1, cutEnd: 4 })).ok()).toBeTruthy(); try { await openBench(page); const mode = page.locator("[data-bench-mode]"); await expect(mode).toHaveAttribute("data-bench-mode", "cut"); await expect(page.locator("[data-bench-sel]")).toHaveAttribute("data-bench-sel", "1.00-4.00"); await expect(page.locator("[data-bench-plays]")).toContainText("Plays 0:01.00–0:04.00 · reviewed 0:00.50–0:08.50"); // One set of handles: no second pair for the cut, nothing called "pinned". await expect(page.locator("[data-wave-cut-edge]")).toHaveCount(0); await expect(page.locator("[data-cut-use-whole]")).toBeVisible(); await expect(page.locator("[data-bench-mode]")).not.toContainText("pinned"); await shot(page, "mode-cut", true); // The end handle past the extent's 8.50 to 8.9 (the cache runs to 9): no wall. const puts: string[] = []; page.on("request", (r) => { if (r.method() === "PUT" && r.url().endsWith("/api/report/window")) puts.push(r.url()); }); await dragHandle(page, 4, 8.9); const [, to] = spanOf(await page.locator("[data-bench-sel]").getAttribute("data-bench-sel")); expect(to).toBeGreaterThan(8.6); await expect(page.locator("[data-bench-plays]")).toContainText(`reviewed 0:00.50–`); // Unsaved: the mode cannot switch under it. await expect(page.locator("[data-bench-mode-set=clip]")).toBeDisabled(); await page.locator("[data-save-window]").click(); await expect(page.locator("[data-bench-note]")).toContainText("the reviewed range grew with it"); await expect.poll(() => cutOf().cutEnd).toBeCloseTo(to, 2); expect(cutOf()).toMatchObject({ start: 0.5, cutStart: 1 }); expect(cutOf().end).toBeCloseTo(to, 2); expect(puts.length, "one write").toBe(1); // One undo puts both back. await page.locator("[data-window-undo]").click(); await expect.poll(() => cutOf()).toEqual({ start: 0.5, end: 8.5, cutStart: 1, cutEnd: 4 }); await expect(page.locator("[data-bench-sel]")).toHaveAttribute("data-bench-sel", "1.00-4.00"); // Clip mode: the handles are the extent, the cut a band inside it (no tabs to drag). await page.locator("[data-bench-mode-set=clip]").click(); await expect(mode).toHaveAttribute("data-bench-mode", "clip"); await expect(page.locator("[data-bench-sel]")).toHaveAttribute("data-bench-sel", "0.50-8.50"); await expect(page.locator("[data-bench-plays]")).toContainText("Reviewed 0:00.50–0:08.50 · plays 0:01.00–0:04.00"); await expect(page.locator("[data-wave-cut-edge]")).toHaveCount(2); await expect(page.locator("[data-wave-cut-grip]")).toHaveCount(0); await expect(page.locator("[data-gaps-clip-mode]")).toContainText("gaps are cut in Cut mode"); await shot(page, "mode-clip", true); // The extent's start pulled in past the cut's: the cut comes in with it. await dragHandle(page, 0.5, 2); await page.locator("[data-save-window]").click(); await expect(page.locator("[data-bench-note]")).toContainText("the cut shrank with it"); await expect.poll(() => cutOf().cutStart ?? 0).toBeGreaterThan(1.8); expect(cutOf().cutStart).toBe(cutOf().start); expect(cutOf().cutEnd).toBe(4); // And back to Cut: the handles are the (smaller) cut; Use the whole clip clears it, Undo cut puts it back. await page.locator("[data-bench-mode-set=cut]").click(); await expect(page.locator("[data-bench-sel]")).toHaveAttribute("data-bench-sel", `${cutOf().cutStart!.toFixed(2)}-4.00`); await page.locator("[data-cut-use-whole]").click(); await expect.poll(() => cutOf().cutStart).toBeNull(); await expect(page.locator("[data-bench-sel]")).toHaveAttribute("data-bench-sel", `${cutOf().start.toFixed(2)}-8.50`); await expect(page.locator("[data-cut-use-whole]")).toHaveCount(0); await page.locator("[data-cut-undo]").click(); await expect.poll(() => cutOf().cutEnd).toBe(4); } finally { expect((await putWindow(request, { start: 0.5, end: 8.5, cutStart: "", cutEnd: "", lockCut: false })).ok()).toBeTruthy(); } }); // --------------------------------------------------------------------------- // Every wall a gap stops at is drawn and said (lane/clip-fixes; operator, 6 // Nov: "the gap tool gets blocked at random invisible walls in the clip"): the // no-cut zones (outside the span, the keep bands at its edges and beside each // gap), a tick at each second a gap can't cover, and the writer's whole rule // checked on every move -- the claim marks included, which the bench used to // leave to the writer, which then refused with a sentence the bench had not // said. // --------------------------------------------------------------------------- /** Put a claim mark's second on g01 (`claim: {id, verdict, at}`), straight into the manifest; null takes it off. */ const setStamp = (at: number | null) => { const m = JSON.parse(readFileSync(MANIFEST, "utf8")) as { timeline: Record[] }; const e = m.timeline.find((x) => x.id === "g01")!; if (at == null) delete e.claim; else e.claim = { id: "k9", verdict: "CORROBORATED", at }; writeFileSync(MANIFEST, JSON.stringify(m, null, 2) + "\n"); }; /** An Alt + drag from a to b, held (not released): what the span says WHILE it is dragged. */ const altDragHeld = async (page: Page, a: number, b: number) => { await page.keyboard.down("Alt"); const y = await midY(page); await page.mouse.move(await xAt(page, a), y); await page.mouse.down(); await page.mouse.move(await xAt(page, b), y, { steps: 4 }); }; const altRelease = async (page: Page) => { await page.mouse.up(); await page.keyboard.up("Alt"); }; test("the walls are drawn: no-cut zones and the marks a gap can't cover; a drag into one turns red with the reason before release; a gap over a claim mark is refused with the writer's sentence", async ({ page, request }) => { expect((await putWindow(request, { gapAdd: "3.5-5.5" })).ok()).toBeTruthy(); setStamp(7); try { await openBench(page); // The zones: outside the clip (the view runs 0-9, the clip 0.5-8.5), 0.5 s // at each of its edges, and 0.5 s either side of the gap. const kinds = await page.locator("[data-gap-nocut]").evaluateAll((els) => els.map((e) => `${e.getAttribute("data-gap-nocut")} ${e.getAttribute("data-gap-nocut-at")}`)); expect(kinds).toEqual( expect.arrayContaining(["outside 0.00-0.50", "outside 8.50-9.00", "keep-start 0.50-1.00", "keep-end 8.00-8.50", "keep-gap 3.00-3.50", "keep-gap 5.50-6.00"]), ); await expect(page.locator("[data-gap-nocut='keep-gap']").first()).toHaveAttribute("title", /keep at least 0.5 s between cuts/); await expect(page.locator("[data-gap-span-edge]")).toHaveCount(2); // The mark's second, ticked, with what it means on hover. const tick = page.locator("[data-gap-wall-mark='7']"); await expect(tick).toHaveAttribute("data-gap-wall-mark-kind", "mark"); await expect(tick.locator("span")).toHaveAttribute("title", /a gap can't cover this/); await shot(page, "walls"); // Into the keep band beside the gap: red, and why, while still dragging. await altDragHeld(page, 5.7, 6.6); await expect(page.locator("[data-gap-selection]")).toHaveAttribute("data-gap-selection-state", "refused"); await expect(page.locator("[data-gap-selection-why]")).toContainText("keep at least 0.5 s"); await shot(page, "gap-into-keep-band"); await altRelease(page); await page.locator("body").press("Escape"); // Over the mark's second: refused here, with the writer's own sentence. await altDragHeld(page, 6.6, 7.6); await expect(page.locator("[data-gap-selection]")).toHaveAttribute("data-gap-selection-state", "refused"); await expect(page.locator("[data-gap-selection-why]")).toContainText("the mark k9's second (at 7) lies inside the gap"); await shot(page, "gap-over-mark"); await altRelease(page); const [a, b] = spanOf(await page.locator("[data-gap-selection]").getAttribute("data-gap-selection")); const posts: string[] = []; page.on("request", (r) => { if (r.method() === "PUT" && r.url().endsWith("/api/report/window")) posts.push(r.url()); }); await page.locator("[data-gap-cut]").click(); // The writer, asked the same span, says the same thing (less the clip id it starts with). const r = await putWindow(request, { gapAdd: `${a}-${b}` }); expect(r.status()).toBe(400); const said = ((await r.json()) as { error: string }).error.replace(/^g01: /, ""); expect(said).toContain("the mark k9's second (at 7) lies inside the gap"); await expect(page.locator("[data-bench-note]")).toContainText(`not cut: ${said}`); // Refused before anything was sent. expect(posts).toEqual([]); expect(clipOf("g01").gaps).toEqual([{ from: 3.5, to: 5.5 }]); // Touching the gap: no wall -- it says the two become one. await page.locator("body").press("Escape"); await altDragHeld(page, 5.2, 6.4); await expect(page.locator("[data-gap-selection]")).toHaveAttribute("data-gap-selection-state", "merge"); await expect(page.locator("[data-gap-selection-why]")).toContainText("touches a gap — cutting makes one gap 3.50–"); await altRelease(page); } finally { setStamp(null); } });