import { test, expect, type Page } from "@playwright/test"; import { existsSync, rmSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { WARM_TIMEOUT, warm } from "./warm"; import { makeOmega } from "./fixtures/delete-fixture.mjs"; import * as urls from "./urls"; import { openPanel } from "./panels"; // --------------------------------------------------------------------------- // Deleting (release 27 follow-up): every delete shows its PLAN — what goes, // with sizes, what is kept, what refuses — and acts only on "Confirm delete". // The fixture's own (e2e/fixtures/delete-fixture.mjs), so no other spec's // article or project is touched: // // omega a draft, written here (articles.spec.ts counts the // store's rows): i1 (a parent), i2 (the current // article), i3 (a copy of i1, with a project) — i3 // goes, then the whole article // psi an article in the making — it goes // reports/delete-fixture a project with takes keep (the project's own // manifest: refused) and drop — drop goes, then the // project // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const FIXTURE = path.join(HERE, "..", ".e2e-song"); const ARTICLES = path.join(FIXTURE, "articles"); const PROJECTS = path.join(FIXTURE, "gen-projects"); const PROJECT = path.join(FIXTURE, "reports", "delete-fixture"); const dropOmega = () => { rmSync(path.join(ARTICLES, "omega"), { recursive: true, force: true }); rmSync(path.join(PROJECTS, "omega"), { recursive: true, force: true }); }; test.beforeAll(async ({ playwright }) => { test.setTimeout(WARM_TIMEOUT); dropOmega(); makeOmega({ articles: ARTICLES, projects: PROJECTS }); await warm(playwright, [ urls.articleHref({ site: "articles", id: "omega" }, { tab: "iterations" }), urls.articleHref({ site: "articles", id: "psi" }), "/articles", "/browse/reports/delete-fixture", "/browse/reports/delete-fixture/takes", "/work", ]); }); test.afterAll(dropOmega); const card = (page: Page, n: number) => page.locator(`[data-iteration='${n}']`); test("an iteration: the current one and a parent are refused with the reason; a leaf goes with its project; then the draft", async ({ page }) => { await page.goto(urls.articleHref({ site: "articles", id: "omega" }, { tab: "iterations" })); await expect(page.getByRole("region", { name: "iterations", exact: true })).toHaveAttribute("data-iterations", "3"); // The current article: refused, and nothing to confirm. await card(page, 2).getByRole("button", { name: "Delete i2" }).click(); const current = page.getByRole("region", { name: "delete i2" }); await expect(current.getByRole("list", { name: "refused" })).toContainText("i2 is the current article"); await expect(current.getByRole("button", { name: "Confirm delete" })).toBeDisabled(); await expect(current.getByRole("checkbox", { name: "delete anyway" })).toHaveCount(0); await current.getByRole("button", { name: "Keep it" }).click(); await expect(current).toHaveCount(0); // A parent: the iterations that name it are said. await card(page, 1).getByRole("button", { name: "Delete i1" }).click(); const parent = page.getByRole("region", { name: "delete i1" }); await expect(parent.getByRole("list", { name: "refused" })).toContainText("i2 revises it; i3 is a copy of it"); await expect(parent.getByRole("button", { name: "Confirm delete" })).toBeDisabled(); await parent.getByRole("button", { name: "Keep it" }).click(); // A leaf: the plan names its directory and its project, then it goes. await card(page, 3).getByRole("button", { name: "Delete i3" }).click(); const leaf = page.getByRole("region", { name: "delete i3" }); const goes = leaf.getByRole("list", { name: "what goes" }); await expect(goes).toContainText("reports/omega/iterations/3/"); await expect(goes).toContainText("gen-projects/omega/i3/"); await expect(leaf).toHaveAttribute("data-delete-blocked", "no"); expect(existsSync(path.join(ARTICLES, "omega", "iterations", "3")), "the plan removes nothing").toBe(true); await leaf.getByRole("button", { name: "Confirm delete" }).click(); await expect(page.getByRole("region", { name: "iterations", exact: true }).getByRole("status")).toContainText("i3 deleted"); await expect(card(page, 3)).toHaveCount(0); await expect(page.getByRole("region", { name: "iterations", exact: true })).toHaveAttribute("data-iterations", "2"); expect(existsSync(path.join(ARTICLES, "omega", "iterations", "3"))).toBe(false); expect(existsSync(path.join(PROJECTS, "omega", "i3"))).toBe(false); expect(existsSync(path.join(PROJECTS, "omega", "i1", "video.manifest.json"))).toBe(true); expect(existsSync(path.join(ARTICLES, "omega", "report.json"))).toBe(true); // Then the draft itself: its directory, its iterations and their projects. // Delete is in the piece head's ⋯ menu (P4a-2). await page.getByRole("button", { name: "More" }).click(); await page.getByRole("button", { name: "Delete article" }).click(); const all = page.getByRole("region", { name: "delete the article omega" }); await expect(all.getByRole("list", { name: "what goes" })).toContainText("reports/omega/"); await expect(all.getByRole("list", { name: "what goes" })).toContainText("gen-projects/omega/i1/"); await all.getByRole("button", { name: "Confirm delete" }).click(); // /articles?deleted= rides its redirect to Work (kind=article). await expect(page).toHaveURL(/\/work\?.*deleted=omega/); await expect(page.locator("[data-deleted='omega']")).toContainText("Deleted omega"); await expect(page.locator("[data-piece='a:articles/omega']")).toHaveCount(0); expect(existsSync(path.join(ARTICLES, "omega"))).toBe(false); expect(existsSync(path.join(PROJECTS, "omega")), "the emptied projects folder goes too").toBe(false); }); test("an article in the making is deleted from its page, and Work says so", async ({ page }) => { await page.goto(urls.articleHref({ site: "articles", id: "psi" })); await expect(page.locator("[data-article-meta] [data-status]")).toHaveAttribute("data-status", "pending"); // Delete is in the piece head's ⋯ menu (P4a-2). await page.getByRole("button", { name: "More" }).click(); await page.getByRole("button", { name: "Delete article" }).click(); const plan = page.getByRole("region", { name: "delete the article psi" }); await expect(plan.getByRole("list", { name: "what goes" })).toContainText("reports/psi/"); await plan.getByRole("button", { name: "Confirm delete" }).click(); await expect(page).toHaveURL(/\/work\?.*deleted=psi/); await expect(page.locator("[data-deleted='psi']")).toContainText("Deleted psi"); await expect(page.locator("[data-piece='a:articles/psi']")).toHaveCount(0); expect(existsSync(path.join(ARTICLES, "psi"))).toBe(false); }); test("a take the project's manifest is, is refused until forced; another take and then the project go", async ({ page }) => { await page.goto("/browse/reports/delete-fixture/takes"); // Delete take is in the take card's Advanced (lane/ui-simplify). await openPanel(page, "advanced", "take-card"); const keep = page.locator("[data-take='keep']"); await keep.getByRole("button", { name: "Delete take keep" }).click(); const refused = page.getByRole("region", { name: "delete take keep" }); await expect(refused.getByRole("list", { name: "refused" })).toContainText("the deliverable is built from it"); await expect(refused.getByRole("button", { name: "Confirm delete" })).toBeDisabled(); await expect(refused.getByRole("checkbox", { name: "delete anyway" })).toBeVisible(); await refused.getByRole("button", { name: "Keep it" }).click(); await page.locator("[data-take='drop']").getByRole("button", { name: "Delete take drop" }).click(); const drop = page.getByRole("region", { name: "delete take drop" }); await expect(drop.getByRole("list", { name: "what goes" })).toContainText("reports/delete-fixture/takes/drop/"); await drop.getByRole("button", { name: "Confirm delete" }).click(); await expect(page.locator("[data-take='drop']")).toHaveCount(0); await expect(keep).toBeVisible(); expect(existsSync(path.join(PROJECT, "takes", "drop"))).toBe(false); expect(existsSync(path.join(PROJECT, "takes", "keep", "take.json"))).toBe(true); await page.goto(urls.projectHref("reports/delete-fixture", { tab: "overview" })); // Delete is in the piece head's ⋯ menu (P4a-1). await page.getByRole("button", { name: "More" }).click(); await page.getByRole("button", { name: "Delete project" }).click(); const plan = page.getByRole("region", { name: "delete the project reports/delete-fixture" }); await expect(plan.getByRole("list", { name: "what goes" })).toContainText("reports/delete-fixture"); await plan.getByRole("button", { name: "Confirm delete" }).click(); await expect(page).toHaveURL(/\/work\?deleted=reports%2Fdelete-fixture/); await expect(page.locator("[data-deleted='reports/delete-fixture']")).toContainText("Deleted reports/delete-fixture"); await expect(page.locator("[data-piece='p:reports/delete-fixture']")).toHaveCount(0); expect(existsSync(PROJECT)).toBe(false); });