Repository Public
1import { expect, test, type Page } from "@playwright/test";2import { PREVIEW, S01, expectNoAccountPrompt } from "./helpers";34/**5 * The anonymous learner journey, on the preview build (S01 in preview + the synthetic test capsule):6 * home → programme → session → play → captions → transcript seek → chapters → bookmark → notes →7 * refresh and resume → quiz → completion → clear local data. Never an account prompt, a cookie or a8 * third-party request along the way.9 */10const video = (page: Page) => page.getByTestId("video");11const time = (page: Page) => video(page).evaluate((v: HTMLVideoElement) => v.currentTime);12const ready = (page: Page) => expect(page.getByTestId("player")).toHaveAttribute("data-status", "pret", { timeout: 20_000 });1314test("parcours anonyme complet, sans compte", async ({ page, context, browserName }) => {15 test.setTimeout(120_000);16 const foreign: string[] = [];17 page.on("request", (r) => { const u = r.url(); if (!u.startsWith(PREVIEW) && !u.startsWith("data:") && !u.startsWith("blob:")) foreign.push(u); });18 const noAccountPrompt = () => expectNoAccountPrompt(page);1920 // Home21 await page.goto(PREVIEW + "/");22 await expect(page.getByTestId("preview-banner")).toContainText("Aperçu — contenu non publié");23 await expect(page.getByRole("heading", { level: 1 })).toContainText("Comprendre l’IA");24 await expect(page.getByTestId("cta-start")).toHaveText(/Commencer gratuitement/);25 await expect(page.getByTestId("cta-start")).toHaveAttribute("href", S01);26 await expect(page.getByTestId("count-published")).toHaveText("0 sur 24"); // preview material is not counted as published27 await noAccountPrompt();2829 // Programme30 await page.getByRole("navigation", { name: "Navigation principale", exact: true }).getByRole("link", { name: "Programme" }).click();31 await expect(page).toHaveURL(/\/programme$/);32 await expect(page.getByTestId("catalog-count")).toHaveText("24 séances affichées sur 24");33 await noAccountPrompt();34 await page.locator('[data-session="S01"]').getByRole("link").click();3536 // Session hub37 await expect(page).toHaveURL(new RegExp(`${S01}$`));38 await expect(page.locator("article")).toHaveAttribute("data-access", "open");39 await expect(page.getByText("Aperçu — contenu non publié").first()).toBeVisible();40 await expect(page.locator('[data-capsule="test-technique"]')).toContainText("Vidéo de test technique — pas un contenu du cours");41 await expect(page.locator("[data-figure]")).toHaveCount(5);42 await noAccountPrompt();43 await page.getByTestId("start-watching").click();4445 // Player: play the synthetic capsule46 await expect(page).toHaveURL(/\/regarder/);47 await ready(page);48 await expect(page.getByTestId("player")).toHaveAttribute("data-engine", browserName === "webkit" ? "hls-natif" : "hls.js");49 await page.getByTestId("big-play").click();50 await expect.poll(() => time(page), { timeout: 15_000 }).toBeGreaterThan(1);51 expect(await video(page).evaluate((v: HTMLVideoElement) => v.videoWidth)).toBeGreaterThan(0);5253 // Captions (WebVTT), on by default, can be switched off and on54 await expect(page.getByTestId("caption")).toContainText(/vidéo de test technique|ne fait pas partie du cours/);55 await page.getByTestId("captions-toggle").click();56 await expect(page.getByTestId("caption")).toHaveCount(0);57 await page.getByTestId("captions-toggle").click();58 await expect(page.getByTestId("captions-toggle")).toHaveAttribute("aria-pressed", "true");5960 // Transcript: search, click a segment, the video seeks there and the segment is marked current61 await page.getByTestId("transcript-search").fill("changement 550");62 await expect(page.getByTestId("transcript-count")).toHaveText("1 passage trouvé");63 await expect(page.getByTestId("transcript-segment").locator("mark")).toHaveText(["Changement", "550"]);64 await page.getByTestId("transcript-segment").click();65 await expect.poll(() => time(page)).toBeGreaterThanOrEqual(30);66 expect(await time(page)).toBeLessThan(40);67 await page.getByTestId("transcript-search").fill("");68 await expect(page.locator('[data-testid="transcript-segment"][aria-current="true"]')).toContainText("550 hertz");6970 // Chapters71 await page.getByRole("tab", { name: /Chapitres/ }).click();72 await page.getByTestId("chapter").nth(2).click();73 await expect.poll(() => time(page)).toBeGreaterThanOrEqual(60);74 await expect(page.getByTestId("current-chapter")).toHaveText("Tonalité de 660 Hz");75 await expect(page.getByTestId("chapter").nth(2)).toHaveAttribute("aria-current", "true");7677 // Bookmark and notes, stored locally78 await page.getByTestId("bookmark-now").click();79 await page.getByRole("tab", { name: /Signets/ }).click();80 await expect(page.getByTestId("bookmark")).toHaveCount(1);81 await page.getByRole("tab", { name: /Notes/ }).click();82 await page.getByTestId("notes-area").fill("Ma note de test : la tonalité change à chaque chapitre.");83 await expect(page.getByTestId("notes-status")).toContainText("enregistrées dans votre navigateur");84 await page.getByTestId("play-toggle").click(); // pause: the position is saved85 await expect.poll(() => video(page).evaluate((v: HTMLVideoElement) => v.paused)).toBe(true);86 const paused = await time(page);87 expect(paused).toBeGreaterThanOrEqual(60);88 await noAccountPrompt();8990 // Refresh: resume where we were, notes and bookmark still there91 await page.reload();92 await ready(page);93 await expect(page.getByTestId("resume-notice")).toContainText("Reprise à 1:0");94 expect(Math.abs((await time(page)) - paused)).toBeLessThan(4);95 await page.getByRole("tab", { name: /Notes/ }).click();96 await expect(page.getByTestId("notes-area")).toHaveValue(/Ma note de test/);97 await page.getByRole("tab", { name: /Signets/ }).click();98 await expect(page.getByTestId("bookmark")).toHaveCount(1);99100 // Deep link near the end, then watch past 90 %: the capsule becomes complete101 await page.goto(`${PREVIEW}${S01}/regarder?capsule=test-technique&t=1m50s`);102 await ready(page);103 await expect.poll(() => time(page)).toBeGreaterThanOrEqual(110);104 await page.getByTestId("play-toggle").click();105 await expect.poll(() => time(page), { timeout: 15_000 }).toBeGreaterThan(112);106 await page.getByTestId("play-toggle").click();107108 // Quiz: answer one question, read the explanation, finish, see the result109 await page.goto(PREVIEW + S01 + "#quiz");110 const q1 = page.locator('[data-question="S01-Q01"]');111 await q1.getByText("mais pas de l'apprentissage automatique").click();112 await q1.getByRole("button", { name: "Vérifier ma réponse" }).click();113 await expect(q1.getByTestId("feedback")).toContainText("Bonne réponse");114 await expect(q1.getByTestId("feedback")).toContainText("Explication.");115 await page.getByTestId("quiz-finish").click();116 await expect(page.getByTestId("quiz-result")).toBeVisible();117 await expect(page.getByTestId("quiz-score")).toHaveText("1");118 await expect(page.getByTestId("quiz-result")).toContainText("sur 11");119 await noAccountPrompt();120121 // Refresh: the attempt and the completion are remembered122 await page.reload();123 await expect(page.getByTestId("quiz-history")).toContainText("Mes tentatives précédentes (1)");124 await expect(page.getByTestId("session-progress-text")).toHaveText("Séance terminée.");125 await page.goto(PREVIEW + "/programme");126 await expect(page.locator('[data-session="S01"]').getByTestId("progress-done")).toBeVisible();127128 // No cookie was ever set, nothing was requested from another origin129 expect(await context.cookies()).toEqual([]);130 expect(foreign).toEqual([]);131132 // Clear local data133 await page.goto(PREVIEW + "/confidentialite#mes-donnees");134 await expect(page.locator('[data-count="Vidéos commencées"]')).toHaveText("1");135 await expect(page.locator('[data-count="Tentatives de quiz"]')).toHaveText("1");136 await page.getByTestId("clear-data").click();137 await page.getByTestId("clear-confirm").click();138 await expect(page.getByTestId("data-message")).toHaveText("Vos données locales ont été effacées.");139 await expect(page.getByTestId("data-empty")).toBeVisible();140 expect(await page.evaluate(() => Object.keys(localStorage).filter((k) => k.startsWith("atlas")))).toEqual([]);141142 // After clearing: no resume, no progress143 await page.goto(`${PREVIEW}${S01}/regarder`);144 await ready(page);145 await expect(page.getByTestId("resume-notice")).toHaveCount(0);146 expect(await time(page)).toBeLessThan(1);147 await page.goto(PREVIEW + "/programme");148 await expect(page.locator('[data-session="S01"]').getByTestId("progress-done")).toHaveCount(0);149});150