import path from "node:path"; import { test, expect } from "@playwright/test"; import { FIXTURE_ARCHIVE_URL, FIXTURE_ARTICLES_NAME, FIXTURE_ARTICLE_ID, FIXTURE_LINKED_MOMENT, clearFixtureArticles, writeFixtureArticles, } from "./fixture-articles"; // The homepage's articles (release 26 A3): the nav's Articles, /articles/ and // an article, its moments — one opening in the listed archive that publishes // its channel, one in none — and the home page's Latest Articles. The fixture // (e2e/fixture-articles.ts) is written for this file and removed after it; the // empty index is checked with it gone. const DIR = () => path.resolve(test.info().project.testDir, FIXTURE_ARTICLES_NAME); test.describe.configure({ mode: "serial" }); test("with none, /articles/ is an honest empty index and the home page names no article", async ({ page }) => { clearFixtureArticles(DIR()); const res = await page.goto("/articles/"); expect(res?.status()).toBe(200); await expect(page.getByText("No articles", { exact: true })).toBeVisible(); await page.goto("/"); await expect(page.locator("[data-latest-articles]")).toHaveCount(0); }); test.describe("with articles", () => { test.beforeAll(() => writeFixtureArticles(DIR())); test.afterAll(() => clearFixtureArticles(DIR())); test("the nav's Articles opens the index; an article reads under /articles/", async ({ page }) => { await page.goto("/"); await page.getByRole("navigation", { name: "Main", exact: true }).getByRole("link", { name: "Articles" }).click(); await expect(page).toHaveURL(/\/articles\/$/); const card = page.locator("[data-report-index] a").first(); await expect(card).toHaveAttribute("href", `/articles/${FIXTURE_ARTICLE_ID}/`); await card.click(); await expect(page).toHaveURL(new RegExp(`/articles/${FIXTURE_ARTICLE_ID}/$`)); await expect(page.getByRole("heading", { level: 1 })).toContainText("Checking an example article"); // Its downloads and history hang off the same base. await expect(page.locator(`a[href="/articles/${FIXTURE_ARTICLE_ID}/citations.json"]`).first()).toBeAttached(); }); test("a moment opens in the listed archive that publishes its channel, or in none", async ({ page }) => { await page.goto(`/m/${FIXTURE_LINKED_MOMENT}/`); await expect(page.getByRole("link", { name: "Open in the archive" })).toHaveAttribute( "href", new RegExp(`^${FIXTURE_ARCHIVE_URL.replace(/\./g, "\\.")}/\\?v=`), ); const res = await page.goto("/m/demo-podcast/ep-042/610.50-628.00/"); expect(res?.status()).toBe(200); await expect(page.getByText("Like I said before, spring twenty nineteen.", { exact: false }).first()).toBeVisible(); await expect(page.getByRole("link", { name: "Open in the archive" })).toHaveCount(0); }); test("the home page shows the latest articles and links them all", async ({ page }) => { await page.goto("/"); const latest = page.locator("[data-latest-articles]"); await expect(latest.getByRole("heading", { name: "Latest Articles" })).toBeVisible(); await expect(latest.locator(`a[href="/articles/${FIXTURE_ARTICLE_ID}/"]`)).toBeVisible(); await expect(latest.getByRole("link", { name: "All articles" })).toHaveAttribute("href", "/articles/"); }); });