import { test, expect } from "@playwright/test"; import { mkdir, readFile, writeFile } from "node:fs/promises"; import { join } from "node:path"; import { resetData, testPaths } from "./helpers"; // The Articles tab (release 26 A6): /sites/articles lists the article store // (transcripts/reports/), and its buttons write reports/index.json and an // article's `audience` through the article registry. Invented fixture ids // only. const reportsDir = () => join(testPaths().transcriptsDir, "reports"); const article = (id: string, over: Record = {}) => ({ format: "archilyzer-report", version: 1, id, kind: "sweep", title: `Fixture article ${id}`, sections: [{ id: "s1", title: "One", body: "Plain words." }], ...over, }); async function putArticle(id: string, over: Record = {}) { await mkdir(join(reportsDir(), id), { recursive: true }); await writeFile(join(reportsDir(), id, "report.json"), JSON.stringify(article(id, over), null, 2)); } const readIndex = async () => JSON.parse(await readFile(join(reportsDir(), "index.json"), "utf8").catch(() => '{"published":[]}')) as { published: string[]; }; const readArticle = async (id: string) => JSON.parse(await readFile(join(reportsDir(), id, "report.json"), "utf8")) as { audience?: string }; test("publish, reorder, make public and unpublish articles; one with problems cannot be published", async ({ page }) => { await resetData("empty"); await putArticle("fixture-one"); await putArticle("fixture-two"); await putArticle("fixture-broken", { summary: "see [x](cite:nobody)" }); await page.goto("/sites"); await page.getByRole("link", { name: "Articles", exact: true }).click(); await expect(page).toHaveURL(/\/sites\/articles$/); await expect(page.getByRole("heading", { name: "Articles", level: 1 })).toBeVisible(); const row = (id: string) => page.locator(`[data-testid="article-row"][data-article="${id}"]`); await expect(page.getByTestId("article-row")).toHaveCount(3); await expect(row("fixture-broken").getByRole("button", { name: "Publish article fixture-broken" })).toBeDisabled(); await row("fixture-one").getByRole("button", { name: "Publish article fixture-one" }).click(); await expect(row("fixture-one").getByRole("button", { name: "Unpublish article fixture-one" })).toBeVisible(); await row("fixture-two").getByRole("button", { name: "Publish article fixture-two" }).click(); await expect(row("fixture-two").getByRole("button", { name: "Unpublish article fixture-two" })).toBeVisible(); await expect.poll(readIndex).toEqual({ published: ["fixture-one", "fixture-two"] }); await row("fixture-two").getByRole("button", { name: "Move article fixture-two up" }).click(); await expect.poll(readIndex).toEqual({ published: ["fixture-two", "fixture-one"] }); // Private by default; going public is explicit and lands in report.json. await expect(row("fixture-one")).toHaveAttribute("data-audience", "private"); await row("fixture-one").getByRole("button", { name: "Make article fixture-one public" }).click(); await expect(row("fixture-one")).toHaveAttribute("data-audience", "public"); await expect.poll(async () => (await readArticle("fixture-one")).audience).toBe("public"); await expect(page.getByText("2 published (1 public), 1 draft")).toBeVisible(); await row("fixture-two").getByRole("button", { name: "Unpublish article fixture-two" }).click(); await expect.poll(readIndex).toEqual({ published: ["fixture-one"] }); await expect(page.locator('[data-testid="article-export"]')).toHaveCount(1); });