import { test, expect } from "@playwright/test"; import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; import { openPanel } from "./panels"; // --------------------------------------------------------------------------- // Take housekeeping in the takes list (UI notes 2026-10-30, item 19): // // take-housekeeping-fixture draft-9, draft-10 (labelled "draft 9: …", the // Ember mistake), draft-11, draft-12 RENDERING (its // build lock names a live pid, built from draft-11). // WRITES take.json labels, verdicts.json, revisions/. // // Relabel, Mark superseded (folded away, shown dimmed on request), Not // superseded -- and a running render respected: draft-12 is not relabelled, // neither it nor its base is deleted. // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const DIR = path.join(HERE, "..", ".e2e-song", "reports", "take-housekeeping-fixture"); const PROJECT = "reports/take-housekeeping-fixture"; const takeFile = (id: string) => path.join(DIR, "takes", id, "take.json"); const label = (id: string) => JSON.parse(readFileSync(takeFile(id), "utf8")).label as string; const verdicts = () => (existsSync(path.join(DIR, "takes", "verdicts.json")) ? JSON.parse(readFileSync(path.join(DIR, "takes", "verdicts.json"), "utf8")) : {}); const PRISTINE = new Map(); test.beforeAll(() => { for (const id of ["draft-9", "draft-10", "draft-11", "draft-12"]) PRISTINE.set(id, readFileSync(takeFile(id), "utf8")); }); test.beforeEach(() => { for (const [id, text] of PRISTINE) { writeFileSync(takeFile(id), text); rmSync(path.join(DIR, "takes", id, "revisions"), { recursive: true, force: true }); } rmSync(path.join(DIR, "takes", "verdicts.json"), { force: true }); }); test("relabel a take; a take that is rendering is not relabelled", async ({ page }) => { await page.goto(urls.takesHref(PROJECT)); const card = page.locator("[data-take='draft-10']"); await expect(card.locator("[data-take-label]")).toContainText("draft 9: re-walked (wrong label)"); await card.locator('[data-action="relabel"]').click(); await card.locator("[data-take-relabel]").fill("draft 10: re-walked"); await card.locator("[data-take-relabel]").press("Enter"); await expect.poll(() => label("draft-10")).toBe("draft 10: re-walked"); await expect(card.locator("[data-take-label]")).toContainText("draft 10: re-walked"); expect(existsSync(path.join(DIR, "takes", "draft-10", "revisions"))).toBe(true); const busy = page.locator("[data-take='draft-12']"); await expect(busy.locator("[data-take-held]")).toHaveText("rendering now"); await expect(page.locator("[data-take='draft-11'] [data-take-held]")).toHaveText("a render is made from it"); await busy.locator('[data-action="relabel"]').click(); await busy.locator("[data-take-relabel]").fill("draft 12: renamed"); await busy.locator('[data-action="relabel-save"]').click(); await expect(busy).toContainText("is not relabelled: it is rendering now (pid 1"); expect(label("draft-12")).toBe("draft 12: rendering"); }); test("mark a take superseded: folded away, shown dimmed on request, and back", async ({ page }) => { await page.goto(urls.takesHref(PROJECT)); const card = page.locator("[data-take='draft-9']"); await openPanel(page, "advanced", "take-card"); await card.locator("[data-take-superseded-by='draft-9']").selectOption("draft-11"); await card.locator('[data-action="supersede"]').click(); await expect.poll(() => verdicts()["draft-9"]?.superseded?.by).toBe("draft-11"); await expect(page.locator("[data-take='draft-9']")).toHaveCount(0); await expect(page.locator("[data-superseded-count]")).toContainText("1 superseded take folded away"); await page.locator('[data-action="show-superseded"]').click(); const shown = page.locator("[data-take='draft-9']"); await expect(shown).toHaveAttribute("data-superseded", "draft-11"); await expect(shown.locator("[data-take-superseded]")).toHaveText("superseded by draft-11"); await openPanel(page, "advanced", "take-card"); await shown.locator('[data-action="unsupersede"]').click(); await expect.poll(() => verdicts()["draft-9"]).toBeUndefined(); await expect(page.locator("[data-take='draft-9']")).not.toHaveAttribute("data-superseded", /.*/); }); test("delete refuses a take that is rendering, and the take it is rendered from", async ({ page }) => { await page.goto(urls.takesHref(PROJECT)); await openPanel(page, "advanced", "take-card"); await page.locator("[data-take='draft-12']").getByRole("button", { name: "Delete take draft-12" }).click(); const plan = page.getByRole("region", { name: "delete take draft-12" }); await expect(plan).toHaveAttribute("data-delete-blocked", "yes"); await expect(plan.getByRole("list", { name: "refused" })).toContainText("take draft-12: it is rendering now"); await openPanel(page, "advanced", "take-card"); await page.locator("[data-take='draft-11']").getByRole("button", { name: "Delete take draft-11" }).click(); await expect(page.getByRole("region", { name: "delete take draft-11" }).getByRole("list", { name: "refused" })).toContainText("take draft-12 is being rendered from it"); expect(existsSync(takeFile("draft-12"))).toBe(true); });