import { test, expect } from "@playwright/test"; import { readFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // EDIT ON A VERSION OPENS IT IN THE DRAFT (umtool redesign L3; was: Play's edit on a take with its own // timeline edits that take -- 2 Nov, an edge fixed from Play on `kirsche-7`'s kr1 landed where the // operator did not expect). Every edit lands in the draft now: Edit on a version goes to the Open in // draft page, which saves the draft first and copies the version in; the edge is then saved on the // DRAFT's bench -- the project's manifest changes and the take's take.json does not. // // play-take-edit-fixture (fixtures/take-walk-fixture.mjs, written for this file alone): the master is // one clip, w01 1.00-8.00; the legacy DRAFT take `tight` replaces the timeline (its own timeline) with // t01a, t01b 3.50-6.00 and t01c, all inside the cached vid1 0-9 s window. // --------------------------------------------------------------------------- test.describe.configure({ mode: "serial" }); const P = "reports/play-take-edit-fixture"; const TAKE = "tight"; const DIR = path.join(path.dirname(fileURLToPath(import.meta.url)), "..", ".e2e-song", "reports", "play-take-edit-fixture"); const manifestText = () => readFileSync(path.join(DIR, "video.manifest.json"), "utf8"); const takeText = () => readFileSync(path.join(DIR, "takes", TAKE, "take.json"), "utf8"); const draftClip = (id: string) => (JSON.parse(manifestText()).timeline as { id: string; start: number; end: number }[]).find((e) => e.id === id)!; test.beforeEach(() => { test.setTimeout(120_000); }); test("Play on a version → Edit asks to open it in the draft (the draft saved first) → the DRAFT's bench; the edge lands in the manifest, take.json untouched; Back plays the draft", async ({ page }) => { const takeBefore = takeText(); const masterBefore = manifestText(); expect(JSON.parse(masterBefore).timeline.map((e: { id: string }) => e.id)).toEqual(["w01"]); await page.setViewportSize({ width: 1366, height: 1000 }); await page.goto(urls.playHref(P, { take: TAKE })); const root = page.locator("[data-play-cut]"); await expect(root).toHaveAttribute("data-play-state", "paused", { timeout: 30_000 }); await expect(page.locator(`[data-play-take="${TAKE}"]`)).toContainText("read-only"); await page.locator('[data-play-row="t01b"]').press("Enter"); await expect(root).toHaveAttribute("data-play-item", "t01b"); const edit = page.locator("[data-play-edit]"); await expect(edit).toHaveAttribute("data-play-edit", "open"); await edit.click(); // The question first: the draft (never saved) is saved as v1, then tight is copied in. await expect(page).toHaveURL(new RegExp(`/takes/${TAKE}/open\\?clip=t01b&from=play`)); const ask = page.locator(`[data-open-draft="${TAKE}"]`); await expect(ask).toHaveAttribute("data-open-draft-saves", "v1"); await expect(ask.locator("[data-open-draft-said]")).toContainText("is saved as v1 first"); await page.screenshot({ path: test.info().outputPath("open-in-draft.png") }); expect(manifestText(), "nothing written by asking").toBe(masterBefore); await ask.locator("[data-open-draft-confirm]").click(); // The draft's bench on t01b, from Play: the draft is tight's timeline now, v1 the draft before. await expect(page).toHaveURL(/\/projects\/reports\/play-take-edit-fixture\/clip\/t01b\?from=play/); const bench = page.locator('[data-bench="t01b"]'); await expect(bench).toBeVisible({ timeout: 20_000 }); expect(JSON.parse(manifestText()).timeline.map((e: { id: string }) => e.id)).toEqual(["t01a", "t01b", "t01c"]); expect(readFileSync(path.join(DIR, "takes", "v1", "base.manifest.json"), "utf8")).toBe(masterBefore); expect(takeText(), "the take is byte-identical").toBe(takeBefore); await expect(page.locator("[data-bench-kind]")).toContainText("Clip bench"); // An edge: the end +0.05 s (`.`), saved -- into the draft. const save = page.locator("[data-save-window]"); await expect(async () => { await page.locator("body").press("."); await expect(save).toBeEnabled({ timeout: 500 }); }).toPass({ timeout: 10_000 }); await save.click(); await expect.poll(() => draftClip("t01b").end).toBeGreaterThan(6); expect(draftClip("t01b").start).toBe(3.5); expect(takeText(), "the take is byte-identical").toBe(takeBefore); // Back to the cut: Play of the draft, the same clip; the draft is from tight, one edit. await page.locator("[data-back-to-play]").click(); await expect(page).toHaveURL(/\/play\?(cut=1&)?clip=t01b/); await expect(root).toHaveAttribute("data-play-item", "t01b", { timeout: 20_000 }); await expect(root).toHaveAttribute("data-play-cut", ""); await expect(page.locator("[data-play-draft]")).toContainText(`Draft · from ${TAKE} · 1 edit`); }); test("a take's old bench address from Play asks first: the draft (1 edit since tight) would be saved as v2; Cancel plays the take", async ({ page }) => { const before = manifestText(); await page.goto(urls.takeClipHref(P, TAKE, "t01c", { play: { at: 0.5 } })); const ask = page.locator(`[data-open-draft="${TAKE}"]`); await expect(ask).toHaveAttribute("data-open-draft-saves", "v2"); await expect(ask.locator("[data-open-draft-said]")).toContainText(`Your draft (1 edit since ${TAKE}) is saved as v2 first`); await ask.locator("[data-open-draft-cancel]").click(); await expect(page).toHaveURL(new RegExp(`/play\\?take=${TAKE}`)); expect(manifestText()).toBe(before); }); test("Edit on the draft's own parent with no edits goes straight on (307) to the draft's bench", async ({ page, request }) => { // Saved: the draft is v2 now, no edits since. const r = await request.post("/api/report/takes/save", { data: { project: P } }); expect(await r.json()).toMatchObject({ saved: true, id: "v2" }); const res = await request.get(`/projects/${P}/takes/v2/open?clip=t01c&from=play&at=0.50`, { maxRedirects: 0 }); expect(res.status()).toBe(307); expect(res.headers()["location"]).toMatch(/\/projects\/reports\/play-take-edit-fixture\/clip\/t01c\?from=play&at=0\.50/); await page.goto(urls.playHref(P, { take: "v2" })); const root = page.locator("[data-play-cut]"); await expect(root).toHaveAttribute("data-play-state", "paused", { timeout: 30_000 }); await page.locator('[data-play-row="t01c"]').press("Enter"); // The state the page shows, not a time: t01c is the clip on screen before Edit is pressed. await expect(root).toHaveAttribute("data-play-item", "t01c"); // As under load: the open page's round-trip slower than Play's own URL write after the pause (150 ms), which once // landed on top of the navigation and cancelled it (PlayCut editHere holds it now). await page.route(/\/takes\/v2\/open\?/, async (route) => { await new Promise((r) => setTimeout(r, 800)); await route.continue(); }); await page.locator("[data-play-edit]").click(); await expect(page.locator('[data-bench="t01c"]')).toBeVisible({ timeout: 20_000 }); await expect(page).toHaveURL(/\/projects\/reports\/play-take-edit-fixture\/clip\/t01c\?from=play/); });