import path from "node:path"; import { test, expect } from "@playwright/test"; import { FIXTURE_HISTORY, FIXTURE_SOURCE_NAME, clearFixtureSource, writeFixtureSource, } from "./fixture-source"; // The /source/ page's History block (release 15 slice SG), in both states, // from a FIXTURE publish (e2e/fixture-source.ts): the dev server reads the // page's manifest from E2E_SOURCE_PUBLIC_DIR while it holds one // (playwright.config.ts, app/lib/source.ts). Each test writes it and removes // it, so every other spec reads public/. The history PAGES themselves — what // stagit rendered and the publish rewrote — are source.spec.ts's, over the // checkout's real publish. const FIXTURE = path.resolve(process.cwd(), "e2e", FIXTURE_SOURCE_NAME); test.describe.configure({ mode: "serial" }); test.afterEach(() => clearFixtureSource(FIXTURE)); test("with a history in the manifest: the History block names the commits and the head, and links the log, the refs and the feed", async ({ page }) => { writeFixtureSource(FIXTURE, { history: true }); await page.goto("/source/"); await expect(page.getByTestId("source-mirror-head")).toHaveText(FIXTURE_HISTORY.head); const block = page.getByTestId("source-history"); await expect(block).toBeVisible(); await expect(block).toContainText("Every commit of main with its diff, as static pages: 1,234 commits, the newest"); await expect(page.getByTestId("source-history-commits")).toHaveText("1,234"); await expect(page.getByTestId("source-history-total")).toHaveCount(0); // The head, short, linking to its own commit page. await expect(page.getByTestId("source-history-head")).toHaveText(FIXTURE_HISTORY.head.slice(0, 12)); await expect(page.getByTestId("source-history-head")).toHaveAttribute("href", `/source/git/commit/${FIXTURE_HISTORY.head}.html`); await expect(page.getByTestId("source-history-log")).toHaveAttribute("href", "/source/git/log.html"); await expect(page.getByTestId("source-history-refs")).toHaveAttribute("href", "/source/git/refs.html"); await expect(page.getByTestId("source-history-atom")).toHaveAttribute("href", "/source/git/atom.xml"); await expect(page.getByTestId("source-history-log")).toHaveText("Log"); await expect(page.getByTestId("source-history-atom")).toHaveText("Atom feed"); }); test("past the cap: the History block says the latest N of M commits", async ({ page }) => { writeFixtureSource(FIXTURE, { history: true, total: 12_345 }); await page.goto("/source/"); const block = page.getByTestId("source-history"); await expect(block).toContainText("The newest commits of main with their diffs, as static pages: the latest 1,234 of 12,345 commits, the newest"); await expect(page.getByTestId("source-history-commits")).toHaveText("1,234"); await expect(page.getByTestId("source-history-total")).toHaveText("12,345"); await expect(page.getByTestId("source-history-log")).toHaveAttribute("href", "/source/git/log.html"); }); test("without a history in the manifest: no History block, and the rest of the page as before", async ({ page }) => { writeFixtureSource(FIXTURE, { history: false }); await page.goto("/source/"); await expect(page.getByTestId("source-clone")).toBeVisible(); await expect(page.getByTestId("source-tree-link")).toBeVisible(); await expect(page.getByTestId("source-history")).toHaveCount(0); await expect(page.getByRole("link", { name: "Atom feed" })).toHaveCount(0); });