Repository Public
1import { readFileSync } from "node:fs";2import AxeBuilder from "@axe-core/playwright";3import { expect, test, type Page } from "@playwright/test";4import { SLIDES } from "../playwright.config";5import { NOTE_SENTINELS, SLIDE_WORD } from "../tests/fixtures/deck-fixture";6import { expectNoAccountPrompt, setTheme } from "./helpers";78/**9 * The slide viewer, on a site where two sessions have their slides online (and nothing else), and a third10 * has slides imported but not published. Decks are built by the global setup from hand-made PDFs.11 */12const BASE = SLIDES.base, S01 = "/seances/01-ia-ia-generative-et-llm";13const state = JSON.parse(readFileSync("e2e/.tmp/slides/state.json", "utf8")) as { ready: boolean; dirs: { S01: string; S02: string; S03: string } };14test.skip(!state.ready, "poppler (pdfinfo, pdftotext, pdftocairo) est absent : les diapositives d'essai n'ont pas pu être construites");1516const deck = (p: Page) => p.getByTestId("slide-deck");17const counter = (p: Page) => p.getByTestId("deck-counter");18const loaded = async (p: Page) => expect.poll(() => p.getByTestId("deck-image").evaluate((i: HTMLImageElement) => i.complete && i.naturalWidth > 0)).toBe(true);19const project = () => test.info().project.name;2021test("états honnêtes : diapositives en ligne, tout le reste à venir, et rien n’est compté comme publié", async ({ page, context, request }) => {22 await page.goto(BASE + "/");23 await expect(page.getByTestId("count-slides")).toHaveText("2 sur 24");24 await expect(page.getByTestId("count-published")).toHaveText("0 sur 24");25 await expect(page.getByTestId("count-capsules")).toHaveText("0");26 await expect(page.locator("main")).toContainText("les diapositives de 2 séances se consultent déjà en ligne");27 expect(await (await request.get(`${BASE}/api/health`)).json()).toEqual({ status: "ok", mode: "production", sessions: 24, published: 0 });28 await page.goto(BASE + "/programme");29 await expect(page.locator('li[data-session="S01"]')).toContainText("Diapositives en ligne");30 await expect(page.locator('li[data-session="S03"]')).toContainText("À venir"); // imported, not published31 await page.goto(BASE + S01);32 await expect(page.locator("article")).toHaveAttribute("data-access", "open");33 await expect(page.getByTestId("session-offer")).toHaveText(/Diapositives en ligne.*Vidéos à venir.*Quiz à venir.*Laboratoire à venir/);34 await expect(page.getByTestId("slides-section")).toContainText("Le fichier PDF n’est pas offert en téléchargement"); // no licence: no download35 await expect(page.getByTestId("deck-pdf")).toHaveCount(0);36 await expect(page.locator("[data-question], [data-figure], #laboratoire, #glossaire, #scenario, video")).toHaveCount(0); // slides only: no quiz, lab, glossary, script37 await expect(page.locator('a[href*="/telecharger/"], a[download]')).toHaveCount(0);38 await expectNoAccountPrompt(page);39 expect(await context.cookies()).toEqual([]);40});4142test("visionneuse : clavier, champ « aller à », plan, vue d’ensemble, version texte, lien direct", async ({ page, context }) => {43 test.skip(project() !== "chromium", "parcours complet au clavier : Chromium");44 await context.grantPermissions(["clipboard-read", "clipboard-write"]);45 await page.goto(BASE + S01);46 await expect(counter(page)).toHaveText("1 sur 10");47 await loaded(page);48 await page.getByTestId("deck-next").focus();49 await page.keyboard.press("ArrowRight");50 await expect(counter(page)).toHaveText("2 sur 10");51 await expect(page.getByTestId("deck-image")).toHaveAttribute("alt", "Diapositive 2 sur 10 : Trois machines, un même mot");52 await expect(page.getByTestId("deck-status")).toHaveText("Diapositive 2 sur 10 : Trois machines, un même mot"); // announced to screen readers53 await expect(deck(page)).toContainText("S01-D02");54 await expect(page).toHaveURL(/#diapositive-2$/);55 await page.keyboard.press("End"); await expect(counter(page)).toHaveText("10 sur 10");56 await expect(page.getByTestId("deck-next")).toBeDisabled();57 await page.keyboard.press("ArrowRight"); await expect(counter(page)).toHaveText("10 sur 10"); // stays on the last slide58 await page.keyboard.press("Home"); await expect(counter(page)).toHaveText("1 sur 10");59 await page.keyboard.press("ArrowLeft"); await expect(counter(page)).toHaveText("1 sur 10");60 await page.keyboard.press("7");61 await expect(page.getByTestId("deck-note")).toContainText("Aller à la diapositive 7");62 await page.keyboard.press("Enter"); await expect(counter(page)).toHaveText("7 sur 10");63 await page.keyboard.press("9"); await page.keyboard.press("9"); await page.keyboard.press("Enter"); await expect(counter(page)).toHaveText("10 sur 10"); // out of range: clamped64 await page.getByTestId("deck-goto").fill("4"); await page.getByTestId("deck-goto").press("Enter");65 await expect(counter(page)).toHaveText("4 sur 10");66 await page.getByTestId("deck-outline").selectOption({ label: "2. Conclure" });67 await expect(counter(page)).toHaveText("6 sur 10");6869 // The text alternative: always there for assistive technology, shown on demand; with the figure's description.70 await page.getByTestId("deck-goto").fill("4"); await page.getByTestId("deck-goto").press("Enter");71 const text = page.getByTestId("deck-text");72 await expect(text).toContainText("Une figure occupe cette diapositive.");73 await expect(text).toContainText("Trois rectangles emboîtés, décrits pour qui ne voit pas la figure.");74 expect(await page.getByTestId("deck-image").getAttribute("aria-describedby")).toBe(await text.getAttribute("id"));75 expect(await text.evaluate((e) => e.getBoundingClientRect().width)).toBeLessThanOrEqual(1); // visually hidden…76 await page.getByTestId("deck-text-toggle").click();77 expect(await text.evaluate((e) => e.getBoundingClientRect().width)).toBeGreaterThan(200); // …until asked for78 await expect(text).not.toContainText("UQO"); // the footer strip is not part of the text7980 // Overview grid, then a direct link to the slide.81 await page.getByTestId("deck-overview").click();82 await expect(page.getByTestId("deck-grid").locator("button")).toHaveCount(10);83 await page.getByTestId("deck-grid").locator("button").nth(4).click();84 await expect(counter(page)).toHaveText("5 sur 10");85 await expect(page.getByTestId("deck-grid")).toBeHidden();86 await page.getByTestId("deck-copy").click();87 await expect(page.getByTestId("deck-note")).toContainText("Lien vers cette diapositive copié");88 expect(await page.evaluate(() => navigator.clipboard.readText())).toBe(`${BASE}${S01}#S01-D04`);89 // Presentation mode.90 await page.getByTestId("deck-full").click();91 await expect(deck(page)).toHaveAttribute("data-full", "1");92 await page.keyboard.press("ArrowRight"); await expect(counter(page)).toHaveText("6 sur 10");93 await page.getByTestId("deck-full").click();94 await expect(deck(page)).not.toHaveAttribute("data-full", "1");95});9697test("lien direct, reprise locale, effacement des données locales", async ({ page }) => {98 test.skip(project() !== "chromium", "Chromium");99 await page.goto(`${BASE}${S01}#diapositive-4`);100 await expect(counter(page)).toHaveText("4 sur 10");101 await expect.poll(() => deck(page).evaluate((e) => { const r = e.getBoundingClientRect(); return r.top >= -5 && r.top < window.innerHeight * 0.6; })).toBe(true); // the viewer was brought into view102 await page.goto(`${BASE}${S01}#S01-D04`); await page.reload(); // by slide identifier103 await expect(counter(page)).toHaveText("5 sur 10");104 await page.goto(`${BASE}${S01}#diapositive-99`); await page.reload();105 await expect(counter(page)).toHaveText(/^\d+ sur 10$/); // an address that names no slide is ignored106 // Resume: the last slide viewed comes back on a visit without a fragment.107 await page.getByTestId("deck-goto").fill("7"); await page.getByTestId("deck-goto").press("Enter");108 await expect(counter(page)).toHaveText("7 sur 10");109 await page.goto(BASE + "/programme"); await page.goto(BASE + S01);110 await expect(counter(page)).toHaveText("7 sur 10");111 await expect(page.getByTestId("deck-note")).toContainText("Reprise à la diapositive 7");112 await page.getByRole("button", { name: "Revenir au début" }).click();113 await expect(counter(page)).toHaveText("1 sur 10");114 await page.getByTestId("deck-next").click(); await page.getByTestId("deck-next").click();115 // « Effacer mes données locales » covers it.116 await page.goto(BASE + "/confidentialite");117 await page.getByTestId("clear-data").click();118 await page.getByTestId("clear-confirm").click();119 await expect(page.getByTestId("data-message")).toHaveText("Vos données locales ont été effacées.");120 await page.goto(BASE + S01);121 await expect(counter(page)).toHaveText("1 sur 10");122 await expect(page.getByTestId("deck-note")).toHaveCount(0);123});124125test("thème : les diapositives suivent le site, et se règlent à part", async ({ page }) => {126 await setTheme(page, "dark");127 await page.goto(BASE + S01);128 await expect(deck(page)).toHaveAttribute("data-theme-variant", "dark");129 await expect(page.getByTestId("deck-image")).toHaveAttribute("src", new RegExp(`/diapositives/${state.dirs.S01}/dark/001\\.svg$`));130 await loaded(page); // the vector slide really renders in this engine (Chromium, WebKit)131 await page.getByTestId("deck-theme").click(); // site is dark → the toggle goes to light first132 await expect(deck(page)).toHaveAttribute("data-theme-variant", "light");133 await expect(page.getByTestId("deck-image")).toHaveAttribute("src", /\/light\/001\.svg$/);134 await loaded(page);135 await expect(page.getByTestId("deck-theme")).toHaveAttribute("title", "Thème des diapositives : clair");136 await page.getByTestId("deck-theme").click(); // back to following the site137 await expect(page.getByTestId("deck-theme")).toHaveAttribute("title", "Thème des diapositives : comme le site");138 await expect(deck(page)).toHaveAttribute("data-theme-variant", "dark");139 if (project() !== "mobile") { // the site's own toggle: the deck follows140 await page.getByTestId("theme-toggle").click(); await page.getByTestId("theme-toggle").click(); // dark → system… until the page is light141 const site = await page.locator("html").getAttribute("data-theme");142 await expect(deck(page)).toHaveAttribute("data-theme-variant", site!);143 }144});145146test("recherche : un mot d’une diapositive mène à cette diapositive", async ({ page }) => {147 test.skip(project() === "webkit", "Chromium et mobile");148 await page.goto(`${BASE}/recherche?q=${SLIDE_WORD}`);149 const hit = page.locator(`a[href="${S01}#diapositive-5"]`).first();150 await expect(hit).toBeVisible();151 await expect(hit).toContainText("Un animal minuscule");152 await hit.click();153 await expect(counter(page)).toHaveText("5 sur 10");154 await expect(page.getByTestId("deck-text")).toContainText(SLIDE_WORD);155});156157test("fuites : diapositives non publiées introuvables ; notes de l’enseignant nulle part", async ({ request, page }) => {158 test.skip(project() !== "chromium", "Chromium");159 const get = (path: string) => request.get(BASE + path, { maxRedirects: 0 });160 const ok = await get(`/diapositives/${state.dirs.S01}/dark/001.svg`);161 expect(ok.status()).toBe(200);162 expect(ok.headers()["content-type"]).toBe("image/svg+xml");163 expect(ok.headers()["content-security-policy"]).toContain("sandbox");164 expect((await get(`/diapositives/${state.dirs.S01}/thumbs/light/010.webp`)).headers()["content-type"]).toBe("image/webp");165 for (const path of [166 `/diapositives/${state.dirs.S03}/dark/001.svg`, `/diapositives/${state.dirs.S03}/thumbs/dark/001.webp`, // imported, never published167 `/diapositives/S01/000000000000/dark/001.svg`, `/diapositives/${state.dirs.S01}/deck.json`, `/diapositives/${state.dirs.S01}/dark/011.svg`,168 `/diapositives/${state.dirs.S01}/..%2f..%2f..%2fatlas.db`, `/diapositives/S01`, `/diapositives/${state.dirs.S01.replace("S01", "S02")}/dark/001.svg`,169 `/admin/apercu/diapositives/${state.dirs.S03}/dark/001.svg`, "/admin/api/sessions/S03/sections/slides", "/contenu/S01/quiz.json", "/telecharger/S01/diapositives",170 ]) expect((await get(path)).status(), path).toBeGreaterThanOrEqual(401);171 const index = await (await get("/recherche/index.json")).text(), docs = (JSON.parse(index) as { docs: { type: string; session?: string }[] }).docs;172 expect(docs.filter((d) => d.type === "diapositive" && d.session === "S03")).toEqual([]);173 expect(docs.filter((d) => d.type === "diapositive").length).toBe(12); // 6 per published deck174 expect(docs.some((d) => ["glossaire", "ressource", "transcription"].includes(d.type))).toBe(false); // slides only: nothing else was published175 await page.goto(BASE + "/programme");176 await page.locator('li[data-session="S03"] a').first().click();177 await expect(page.locator("article")).toHaveAttribute("data-access", "upcoming");178 await expect(page.getByTestId("slide-deck")).toHaveCount(0);179 const sitemap = await (await get("/sitemap.xml")).text();180 expect(sitemap.match(/<loc>/g)).toHaveLength(11 + 24);181 expect(sitemap).not.toContain("diapositives");182 // The instructor's notes exist in the source repository of this test; no trace of them may be served.183 const served = [index, await (await get(S01)).text(), await (await get(`${S01}/regarder`)).text(), await (await get("/")).text(), await ok.text()].join("\n");184 for (const note of NOTE_SENTINELS) expect(served, note).not.toContain(note.slice(0, 18));185 expect(served).not.toContain("Piège dans une note");186});187188test("accessibilité (axe) : visionneuse fermée, puis vue d’ensemble et version texte ouvertes, dans les deux thèmes", async ({ page }) => {189 test.skip(project() !== "chromium", "Chromium");190 const audit = async (label: string) => {191 const r = await new AxeBuilder({ page }).withTags(["wcag2a", "wcag2aa", "wcag21a", "wcag21aa", "wcag22aa", "best-practice"]).analyze();192 return r.violations.map((v) => `[${label}] ${v.id} (${v.impact}) — ${v.help} :: ${v.nodes.slice(0, 2).map((n) => n.target.join(" ")).join(" | ")}`);193 };194 const found: string[] = [];195 for (const theme of ["light", "dark"] as const) {196 await setTheme(page, theme);197 await page.goto(`${BASE}${S01}#diapositive-4`, { waitUntil: "networkidle" });198 found.push(...await audit(`visionneuse ${theme}`));199 await page.getByTestId("deck-overview").click(); await page.getByTestId("deck-text-toggle").click();200 found.push(...await audit(`vue d'ensemble et texte ${theme}`));201 await page.evaluate(() => localStorage.clear());202 }203 expect(found, found.join("\n")).toEqual([]);204});205206test("mobile 375 px : pas de débordement, cibles tactiles, balayage", async ({ page }) => {207 test.skip(project() !== "mobile", "profil tactile 375 px");208 await page.goto(BASE + S01, { waitUntil: "networkidle" });209 await loaded(page);210 expect(await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth)).toBeLessThanOrEqual(0);211 for (const id of ["deck-prev", "deck-next", "deck-overview", "deck-text-toggle", "deck-theme", "deck-copy", "deck-full"]) {212 const box = (await page.getByTestId(id).boundingBox())!;213 expect(Math.min(box.width, box.height), id).toBeGreaterThanOrEqual(44);214 }215 const swipe = (from: number, to: number) => page.getByTestId("deck-image").evaluate((el, [a, b]) => {216 const stage = el.parentElement!, r = stage.getBoundingClientRect(), y = r.top + r.height / 2;217 const t = (x: number) => new Touch({ identifier: 1, target: stage, clientX: r.left + r.width * x, clientY: y });218 stage.dispatchEvent(new TouchEvent("touchstart", { touches: [t(a!)], changedTouches: [t(a!)], bubbles: true }));219 stage.dispatchEvent(new TouchEvent("touchend", { touches: [], changedTouches: [t(b!)], bubbles: true }));220 }, [from, to]);221 await swipe(0.8, 0.2); await expect(counter(page)).toHaveText("2 sur 10"); // swipe left: next222 await swipe(0.2, 0.8); await expect(counter(page)).toHaveText("1 sur 10"); // swipe right: previous223 await page.getByTestId("deck-next").tap(); await expect(counter(page)).toHaveText("2 sur 10");224 await page.getByTestId("deck-overview").tap();225 expect(await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth)).toBeLessThanOrEqual(0);226});227