SPB Git

Repository Public

public.spec.ts 5.3 KB 101 lines typescript

1import { expect, test, type Page } from "@playwright/test";23/** Public site, anonymous. Runs in desktop Chromium (all widths) and in WebKit with an iPhone profile. */4const WIDTHS = [320, 375, 390, 430, 768, 1024, 1440];5const noOverflow = async (p: Page, what: string) => expect(await p.evaluate(() => document.documentElement.scrollWidth - window.innerWidth), what).toBeLessThanOrEqual(1);6const MOE = "/s/melange-d-experts-et-routage-top-k";7let moe = MOE;89test.beforeAll(async ({ request }) => {10  const r = await request.get("/api/public/sheets?locale=fr&limit=50");11  const items = (await r.json()).items as { slug: string; title: string }[];12  expect(items.length).toBeGreaterThanOrEqual(3);13  moe = "/s/" + (items.find((i) => /expert/i.test(i.slug)) ?? items[0]).slug;14});1516test("no page overflows horizontally at any supported width", async ({ page, browserName, isMobile }) => {17  const widths = isMobile ? [page.viewportSize()!.width] : WIDTHS;18  for (const width of widths) {19    if (!isMobile) await page.setViewportSize({ width, height: 900 });20    for (const path of ["/", moe, "/topics", "/search?q=volatilit%C3%A9", "/about", "/nothing-here"]) {21      await page.goto(path);22      await expect(page.locator("h1").first()).toBeVisible();23      await noOverflow(page, `${path} at ${width}px (${browserName})`);24    }25  }26});2728test("a published sheet reads well: title, author, diagram, equations, sources", async ({ page, browserName, isMobile }) => {29  const errors: string[] = [];30  page.on("pageerror", (e) => errors.push(e.message));31  await page.goto(moe);32  await expect(page.locator(".sheet h1")).toHaveCount(1);33  await expect(page.getByRole("link", { name: "Simon-Pierre Boucher" }).first()).toBeVisible();34  await expect(page.locator(".sheet svg[role=img]").first()).toBeVisible();35  expect(await page.locator(".sheet .katex").count()).toBeGreaterThan(2);36  await expect(page.locator(".sheet").getByText(/Exemple de démonstration/)).toBeVisible();37  expect(await page.locator('.sheet [id^="src-"]').count()).toBeGreaterThan(2);38  expect(await page.locator('script[type="application/ld+json"]').count()).toBe(1);39  await page.screenshot({ path: `e2e/screenshots/public-sheet-${browserName}-${isMobile ? "phone" : "desktop"}.png`, fullPage: true });40  expect(errors).toEqual([]);41});4243test("interactive blocks respond to touch and keyboard", async ({ page }) => {44  await page.goto(moe);45  // Simulation: moving a slider changes the picture.46  const sim = page.locator(".sh-simulation").first();47  await sim.scrollIntoViewIfNeeded();48  const before = await sim.innerText();49  const slider = sim.locator('input[type="range"]').first();50  await slider.focus();51  await page.keyboard.press("ArrowLeft"); await page.keyboard.press("ArrowLeft");   // the first slider is the step scrubber, shown at its last step52  await expect.poll(async () => (await sim.innerText()) !== before).toBe(true);53  expect((await slider.boundingBox())!.height).toBeGreaterThanOrEqual(24);54  // Quiz: choosing an answer reveals the explanation.55  const quiz = page.locator(".sh-quiz").first();56  await quiz.scrollIntoViewIfNeeded();57  await quiz.getByRole("button").first().click();58  await expect(quiz.locator('[aria-live], [role="status"]').first()).toBeVisible();59  // Diagram walkthrough: next step.60  const diagram = page.locator(".sh-diagram").first();61  await diagram.scrollIntoViewIfNeeded();62  const next = diagram.getByRole("button", { name: /Suivant|Étape suivante/ }).first();63  if (await next.count()) { await next.click(); await expect(diagram.locator("[aria-live]").first()).not.toBeEmpty(); }64});6566test("the content is readable without JavaScript", async ({ browser, browserName }) => {67  const ctx = await browser.newContext({ javaScriptEnabled: false, locale: "fr-CA" });68  const p = await ctx.newPage();69  await p.goto(moe);70  await expect(p.locator(".sheet h1")).toBeVisible();71  await expect(p.locator(".sheet svg[role=img]").first()).toBeVisible();72  expect(await p.locator(".sheet .katex").count()).toBeGreaterThan(2);73  expect((await p.locator("article.sheet").innerText()).length, browserName).toBeGreaterThan(2000);74  await ctx.close();75});7677test("search, topics, language switch and reduced motion", async ({ page }) => {78  await page.goto("/");79  await page.getByRole("searchbox").fill("experts");80  await page.keyboard.press("Enter");81  await expect(page).toHaveURL(/\/search\?q=experts/);82  await expect(page.locator(`a[href="${moe}"]`).first()).toBeVisible();83  await page.goto("/topics");84  await page.locator('a[href^="/topics/"]').first().click();85  await expect(page.locator('a[href^="/s/"]').first()).toBeVisible();86  await page.goto("/");87  await page.getByRole("button", { name: "Switch to English" }).click();88  await expect(page.locator("html")).toHaveAttribute("lang", "en");89  await expect(page.getByRole("heading", { level: 1 })).toContainText("One idea");90  await page.emulateMedia({ reducedMotion: "reduce" });91  await page.goto(moe);92  await expect(page.locator(".sheet h1")).toBeVisible();93});9495test("the home page looks right", async ({ page, browserName, isMobile }) => {96  await page.goto("/");97  await expect(page.getByText("by Simon-Pierre Boucher").first()).toBeVisible();98  await expect(page.locator("article").first()).toBeVisible();99  await page.screenshot({ path: `e2e/screenshots/public-home-${browserName}-${isMobile ? "phone" : "desktop"}.png`, fullPage: true });100});101
Files main
Menu

Theme