import { test, expect } from "@playwright/test"; import { mkdir, writeFile } from "node:fs/promises"; import { join } from "node:path"; import { pathExists, resetData, testPaths, writeSite } from "./helpers"; // Danger → Delete on /sites, plan first (release 28 M9, through H5's // publish/siteDelete.ts): Delete shows what goes (sites//, its publish // state and bundle, compose's staging), what stays and what refuses; nothing // is removed until Confirm. A site with a deploy target is refused unless // forced, and force has its own confirmation. Temp sites in the fixture // corpus only. const sitesDir = () => join(testPaths().transcriptsDir, "sites"); test("Delete shows the plan; Cancel removes nothing; Confirm removes the site and its build state", async ({ page }) => { await resetData("empty"); await writeSite("scratch", { siteTitle: "Scratch Site" }); // Its build state, as a publish leaves it. const builds = join(testPaths().transcriptsDir, ".export-builds", "scratch"); await mkdir(join(builds, "out"), { recursive: true }); await writeFile(join(builds, "out", "index.html"), "

scratch

"); await writeFile(join(builds, "built.json"), "{}"); await page.goto("/sites"); const row = page.getByRole("listitem").filter({ hasText: "Scratch Site" }); await row.getByRole("button", { name: /^delete$/i }).click(); const plan = page.getByRole("region", { name: "delete site scratch" }); await expect(plan).toBeVisible(); await expect(plan.locator("[data-plan-summary]")).toContainText("Delete site scratch: 2 paths"); await expect(plan.locator("[data-remove='sites/scratch/']")).toBeVisible(); await expect(plan.locator("[data-remove='export/.export-builds/scratch/']")).toContainText("2 files"); await expect(plan.getByRole("list", { name: "kept" })).toContainText("every channel's data"); await expect(plan.locator("[data-refusal]")).toHaveCount(0); await plan.getByRole("button", { name: "Cancel" }).click(); await expect(plan).toHaveCount(0); expect(await pathExists(join(sitesDir(), "scratch", "site.json"))).toBe(true); await row.getByRole("button", { name: /^delete$/i }).click(); await page.getByRole("region", { name: "delete site scratch" }).getByRole("button", { name: "Confirm delete" }).click(); await expect(page.getByRole("link", { name: /Scratch Site/ })).toHaveCount(0); expect(await pathExists(join(sitesDir(), "scratch"))).toBe(false); expect(await pathExists(builds)).toBe(false); }); test("a site with a deploy target is refused; force, behind its own confirmation, deletes it", async ({ page }) => { await resetData("empty"); await writeSite("deployed", { siteTitle: "Deployed Site", cloudflareProject: "deployed-pages" }); await page.goto("/sites"); const row = page.getByRole("listitem").filter({ hasText: "Deployed Site" }); await row.getByRole("button", { name: /^delete$/i }).click(); const plan = page.getByRole("region", { name: "delete site deployed" }); await expect(plan.locator("[data-refusal='forceable']")).toContainText('it deploys to the Cloudflare Pages project "deployed-pages" (force answers it)'); await expect(plan.getByRole("list", { name: "kept" })).toContainText('the Pages project "deployed-pages"'); await expect(plan.getByRole("button", { name: "Confirm delete" })).toHaveCount(0); const force = plan.getByRole("button", { name: "Delete with force" }); await expect(force).toBeDisabled(); await plan.getByRole("checkbox", { name: /I understand/ }).check(); await force.click(); await expect(page.getByRole("link", { name: /Deployed Site/ })).toHaveCount(0); expect(await pathExists(join(sitesDir(), "deployed"))).toBe(false); });