SPB Git

Repository Public

production.spec.ts 9.5 KB 138 lines typescript

1import { expect, test } from "@playwright/test";2import { PROD, S01, expectNoAccountPrompt } from "./helpers";34/** What the public would see today: the plan of 24 sessions, all « À venir », and nothing else. */56test("accueil : chiffres réels, aucune promesse", async ({ page, context }) => {7  await page.goto(PROD + "/");8  await expect(page.getByTestId("preview-banner")).toHaveCount(0);9  await expect(page.getByRole("heading", { level: 1 })).toContainText("Comprendre l’IA");10  await expect(page.getByTestId("count-published")).toHaveText("0 sur 24");11  await expect(page.getByTestId("cta-programme")).toBeVisible();12  await expect(page.getByTestId("cta-start")).toHaveCount(0); // nothing to start yet: the button does not pretend13  await expect(page.locator("body")).toContainText("Simon-Pierre Boucher — Professeur, Département des sciences administratives, Université du Québec en Outaouais (UQO)");14  await expect(page.locator("body")).toContainText("Il n'est ni approuvé, ni commandité, ni accrédité par l'UQO");15  await expectNoAccountPrompt(page);16  await expect(page.locator("body")).not.toContainText(/témoignage|étudiants inscrits|certificat/i);17  expect(await page.locator("video").count()).toBe(0);18  expect(await context.cookies()).toEqual([]);19  expect(await page.locator('script[type="application/ld+json"]').allTextContents().then((l) => l.map((x) => JSON.parse(x)["@type"]))).toEqual(["WebSite"]);20});2122test("programme : 24 séances, toutes « À venir », filtrables", async ({ page }) => {23  await page.goto(PROD + "/programme");24  await expect(page.locator("li[data-session]")).toHaveCount(24);25  await expect(page.locator('li[data-session] [data-state="upcoming"]')).toHaveCount(24);26  await expect(page.locator('[data-state="open"]')).toHaveCount(0);27  await page.getByTestId("catalog-search").fill("securite");28  await expect(page.getByTestId("catalog-count")).toContainText("séance");29  await expect(page.locator('li[data-session="S20"]')).toBeVisible();30  await page.getByTestId("catalog-search").fill("");31  await page.getByTestId("catalog-level").selectOption("débutant");32  await expect(page.locator("li[data-session]")).toHaveCount(6);33  await page.getByTestId("catalog-part").selectOption("VI");34  await expect(page.getByTestId("catalog-empty")).toBeVisible();35});3637test("séance à venir : plan public seulement", async ({ page }) => {38  await page.goto(PROD + S01);39  await expect(page.locator("article")).toHaveAttribute("data-access", "upcoming");40  await expect(page.locator("body")).toContainText("Cette séance n’est pas encore publiée.");41  await expect(page.getByRole("heading", { name: "Résultats d’apprentissage" })).toBeVisible();42  for (const absent of ["quiz", "start-watching", "session-progress", "watch-capsule"]) await expect(page.getByTestId(absent)).toHaveCount(0);43  await expect(page.locator("[data-figure], [data-capsule], [data-question]")).toHaveCount(0);44  await expect(page.locator('a[href*="/telecharger/"], a[download]')).toHaveCount(0);45  await page.goto(PROD + S01 + "/regarder");46  await expect(page.locator("body")).toContainText("Cette séance n’est pas encore publiée.");47  expect(await page.locator("video").count()).toBe(0);48  await expect(page.locator('meta[name="robots"]')).toHaveAttribute("content", /noindex/);49});5051test("états vides honnêtes : ressources, laboratoires, glossaire", async ({ page }) => {52  for (const [path, text] of [["/ressources", "Aucun téléchargement n’est offert pour l’instant."], ["/laboratoires", "Les laboratoires paraîtront avec les séances."], ["/glossaire", "Le glossaire se remplira avec les séances."]] as const) {53    await page.goto(PROD + path);54    await expect(page.locator("main")).toContainText(text);55    await expect(page.locator('a[download], a[href*="/telecharger/"]')).toHaveCount(0);56  }57});5859test("rien de non publié n’est accessible", async ({ request }) => {60  for (const path of ["/admin/login", "/api/admin", "/api/health/details", "/admin/apercu/media/S01/test-technique/master.m3u8", "/apercu", "/schemas", "/schemas/tokenisation", "/media/S01/test-technique/master.m3u8", "/media/S01/test-technique/fallback.mp4", "/contenu/S01/figures/S01-F01-taxonomie.svg", "/contenu/S01/quiz.json", "/contenu/S02/figures.json", "/telecharger/S01/diapositives", "/media/..%2f..%2fpackage.json", "/contenu/S01/..%2f..%2f..%2fpublication.json"]) {61    const r = await request.get(PROD + path, { maxRedirects: 0 });62    expect(r.status(), path).toBe(404);63  }64  // Writing methods on the studio's pages reach nothing: without a session they are only sent to the sign-in page.65  for (const method of ["post", "put", "delete"] as const) expect((await request[method](PROD + "/admin", { maxRedirects: 0 })).status(), method).toBeGreaterThanOrEqual(300);66  // Since Phase 4 the studio exists: without a session its pages only lead to the sign-in page, and its API says nothing.67  for (const path of ["/admin", "/admin/seances", "/admin/seances/S01", "/admin/cours", "/admin/journal", "/admin/acces", "/admin/apercu/seances/01-ia-ia-generative-et-llm"]) {68    const r = await request.get(PROD + path, { maxRedirects: 0 });69    expect(r.status(), path).toBe(307);70    expect(r.headers().location, path).toBe("/admin/connexion");71    expect(r.headers()["x-robots-tag"], path).toContain("noindex");72    expect(r.headers()["set-cookie"], path).toBeUndefined();73  }74  for (const path of ["/admin/api/dashboard", "/admin/api/sessions", "/admin/api/audit", "/admin/api/tools/export", "/admin/api/nimporte-quoi"]) expect((await request.get(PROD + path)).status(), path).toBe(401);75});7677test("index de recherche, plan du site et robots : aucun contenu non publié", async ({ request }) => {78  const index = await (await request.get(PROD + "/recherche/index.json")).json() as { docs: { type: string; title: string; text: string; url: string }[] };79  expect([...new Set(index.docs.map((d) => d.type))].sort()).toEqual(["page", "seance"]);80  expect(index.docs.filter((d) => d.type === "seance")).toHaveLength(24);81  const blob = JSON.stringify(index);82  for (const leak of ["test technique", "hertz", "ELIZA", "liste fermée", "mini-modèle", "regarder", "schemas"]) expect(blob, leak).not.toContain(leak);83  const sitemap = await (await request.get(PROD + "/sitemap.xml")).text();84  expect(sitemap.match(/<loc>/g)).toHaveLength(11 + 24);85  expect(sitemap).toContain("https://atlas.spboucher.ai/programme");86  const locs = [...sitemap.matchAll(/<loc>([^<]+)<\/loc>/g)].map((m) => m[1]!);87  expect(locs.filter((l) => /regarder|admin|apercu|schemas|telecharger|media|contenu/.test(l))).toEqual([]);88  const robots = await (await request.get(PROD + "/robots.txt")).text();89  expect(robots).toContain("Disallow: /admin");90  expect(robots).toContain("Sitemap: https://atlas.spboucher.ai/sitemap.xml");91});9293test("page 404 réelle, redirections permanentes, santé", async ({ page, request }) => {94  const res = await page.goto(PROD + "/cette-page-n-existe-pas");95  expect(res!.status()).toBe(404);96  await expect(page.getByTestId("not-found")).toContainText("Cette page n’est pas sur la carte.");97  await expectNoAccountPrompt(page);98  for (const alias of ["/seances/what-is-an-llm", "/seances/s01", "/seances/what-is-an-llm/regarder"]) {99    const r = await request.get(PROD + alias, { maxRedirects: 0 });100    expect(r.status(), alias).toBe(308);101    expect(r.headers().location).toContain(S01);102  }103  expect(await (await request.get(PROD + "/api/health")).json()).toEqual({ status: "ok", mode: "production", sessions: 24, published: 0 });104});105106test("en-têtes de sécurité et métadonnées", async ({ page, request }) => {107  const r = await request.get(PROD + "/");108  const h = r.headers();109  expect(h["content-security-policy"]).toContain("default-src 'self'");110  expect(h["content-security-policy"]).toContain("frame-ancestors 'none'");111  expect(h["content-security-policy"]).not.toMatch(/https?:\/\//); // no third-party origin anywhere112  expect(h["x-content-type-options"]).toBe("nosniff");113  expect(h["x-frame-options"]).toBe("DENY");114  expect(h["referrer-policy"]).toBe("strict-origin-when-cross-origin");115  expect(h["strict-transport-security"]).toContain("max-age=");116  expect(h["x-powered-by"]).toBeUndefined();117  expect(h["x-robots-tag"]).toBeUndefined();118  expect(h["set-cookie"]).toBeUndefined();119  await page.goto(PROD + "/programme");120  await expect(page.locator("html")).toHaveAttribute("lang", "fr-CA");121  await expect(page.locator('link[rel="canonical"]')).toHaveAttribute("href", "https://atlas.spboucher.ai/programme");122  await expect(page.locator('meta[property="og:locale"]')).toHaveAttribute("content", "fr_CA");123  await expect(page.locator('meta[property="og:image"]')).toHaveAttribute("content", /opengraph-image/);124  await expect(page).toHaveTitle("Programme — ATLAS IA");125});126127test("aucune ressource chargée depuis un autre site ; aucun débordement horizontal", async ({ page }) => {128  const foreign: string[] = [];129  page.on("request", (r) => { const u = r.url(); if (!u.startsWith(PROD) && !u.startsWith("data:") && !u.startsWith("blob:")) foreign.push(u); });130  for (const path of ["/", "/programme", S01, "/parcours", "/laboratoires", "/ressources", "/glossaire", "/recherche?q=agent", "/a-propos", "/accessibilite", "/confidentialite", "/conditions", "/introuvable"]) {131    await page.goto(PROD + path, { waitUntil: "networkidle" });132    const overflow = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth);133    expect(overflow, `débordement horizontal sur ${path}`).toBeLessThanOrEqual(0);134    await expectNoAccountPrompt(page);135  }136  expect(foreign).toEqual([]);137});138
Files main
Menu

Theme