import { test, expect } from "@playwright/test"; import { readFileSync, rmSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { WARM_TIMEOUT, warm } from "./warm"; // --------------------------------------------------------------------------- // /articles (release 26): the homepage's article store, ARTICLES_DIR -- its // list (Work's articles since P3: /articles redirects to /work?kind=article), // an article's page, its evidence, and its notes beside its report.json. // // delta published, public, cites sitechan/sv1 (plays from a clip window) // epsilon a draft // WRITES articles/delta/notes.json (e2e/fixtures/sites-fixture.mjs) // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const NOTES = path.join(HERE, "..", ".e2e-song", "articles", "delta", "notes.json"); test.beforeAll(async ({ playwright }) => { test.setTimeout(WARM_TIMEOUT); await warm(playwright, [ "/work?kind=article&site=articles", "/articles/delta", "/articles/delta/evidence", "/api/notes?article=articles/delta", "/api/sites/evidence?site=articles&report=delta&cite=c1", ]); }); test.beforeEach(() => rmSync(NOTES, { force: true })); test.afterAll(() => rmSync(NOTES, { force: true })); test("/articles is Work's store articles (site facet `articles`), each with its status and audience", async ({ page }) => { const res = await page.goto("/articles"); expect(res?.status()).toBe(200); await expect(page).toHaveURL(/\/work\?kind=article&site=articles$/); await expect(page.locator("[data-app-rail] [data-place=work]")).toHaveAttribute("aria-current", "page"); // Only the store's articles: no site's report is listed. expect(await page.locator("[data-lit-line][data-piece]").evaluateAll((els) => els.every((e) => e.getAttribute("data-piece")!.startsWith("a:articles/")))).toBe(true); // The store has no site page of its own. await expect(page.locator("[data-site-page]")).toHaveCount(0); const delta = page.locator("[data-piece='a:articles/delta']"); await expect(delta).toHaveAttribute("data-status", "published"); await expect(delta).toHaveAttribute("data-audience", "public"); const epsilon = page.locator("[data-piece='a:articles/epsilon']"); await expect(epsilon).toHaveAttribute("data-status", "draft"); await expect(epsilon).toHaveAttribute("data-audience", "private"); // The old list's keys still filter, and say so as a chip you can take off. await page.goto("/articles?audience=public"); await expect(page).toHaveURL(/audience=public/); await expect(page.locator("[data-extra=audience]")).toBeVisible(); await expect(page.locator("[data-piece^='a:articles/']")).toHaveCount(1); await expect(page.locator("[data-piece='a:articles/delta']")).toBeVisible(); }); test("an article's page reads, its evidence plays, and a note lands beside its report.json", async ({ page, request }) => { await page.goto("/articles"); await page.getByRole("link", { name: "Delta: an article of the homepage" }).click(); await expect(page).toHaveURL(/\/articles\/delta$/); await expect(page.locator("[data-article-meta] [data-status]")).toHaveAttribute("data-status", "published"); const ev = await request.get("/api/sites/evidence?site=articles&report=delta&cite=c1"); expect(ev.status()).toBe(200); const body = (await ev.json()) as { play?: { url: string } }; expect(body.play?.url).toBeTruthy(); await page.goto("/articles/delta/evidence"); await expect(page.getByRole("link", { name: "delta", exact: true })).toHaveAttribute("href", "/articles/delta"); const read = await request.get("/api/notes?article=articles/delta"); expect(read.status()).toBe(200); const { token } = (await read.json()) as { token: string }; const w = await request.post("/api/notes?article=articles/delta", { data: { token, op: { op: "add", text: "Check the date.", anchor: { kind: "whole" } } }, }); expect(w.status()).toBe(200); const doc = JSON.parse(readFileSync(NOTES, "utf8")); expect(doc.subject).toEqual({ kind: "article", site: "articles", report: "delta" }); expect(doc.notes[0]).toMatchObject({ status: "open", author: "operator", text: "Check the date." }); await page.goto("/articles?notes=open"); await expect(page.locator("[data-piece='a:articles/delta']")).toHaveAttribute("data-open-notes", "1"); });