import { expect, test } from "./support/deployed-test"; import { REPO_ROOT, gotoApp, receipt, shot, waitEngineBoot } from "./support/deployed"; import { CHAPTERS } from "./support/chapters"; /** * The shipped documentation surfaces: the generated manual page and the course * landings. These are what a user reads first, so they are part of the deployed * surface even though they exercise no engine. */ test.use({ viewport: { width: 1600, height: 900 } }); test("[manual-page] 手册页呈现 31 章并可搜索", async ({ page }, testInfo) => { await page.goto("/manuals/index.html", { waitUntil: "domcontentloaded", timeout: 20_000 }); const chapters = page.locator(".manual-chapter"); await expect(chapters).toHaveCount(CHAPTERS.length, { timeout: 15_000 }); const navLinks = page.locator(".manual-nav a[data-nav-id]"); expect(await navLinks.count(), "navigation lists every section").toBeGreaterThanOrEqual(CHAPTERS.length); const search = page.getByLabel("搜索手册", { exact: true }); await search.fill("相机"); await expect(page.locator(".manual-search-status")).toContainText("匹配", { timeout: 30_000 }); await expect.poll(async () => page.locator(".manual-nav a[data-nav-id][hidden]").count(), { timeout: 30_000 }).toBeGreaterThan(0); await search.fill(""); const firstImage = await page.locator("figure img").first().evaluate((image) => (image as HTMLImageElement).naturalWidth).catch(() => 0); expect(firstImage, "step images are served").toBeGreaterThan(0); const image = await shot(page, testInfo, "manual-index"); receipt(testInfo, { workflow: "/manuals/index.html -> chapter count, search filter, first figure", chapters: await chapters.count(), firstImageWidth: firstImage, screenshot: image, status: "PASS", }); }); test("[manual-entry] 帮助菜单打开网页版手册", async ({ page, context }, testInfo) => { await gotoApp(page, "web"); await waitEngineBoot(page); await page.getByRole("button", { name: "帮助", exact: true }).click(); const popupPromise = context.waitForEvent("page", { timeout: 15_000 }); await page.getByRole("menuitem", { name: "使用手册(网页版)", exact: true }).click({ timeout: 15_000 }); const popup = await popupPromise; await popup.waitForLoadState("domcontentloaded"); expect(popup.url()).toContain("/manuals/index.html"); await expect(popup.locator(".manual-chapter")).toHaveCount(CHAPTERS.length, { timeout: 15_000 }); const image = await shot(page, testInfo, "manual-from-help"); receipt(testInfo, { workflow: "帮助 → 使用手册(网页版) opens /manuals/index.html with every chapter", url: popup.url(), screenshot: image, status: "PASS", }); }); test("[course-landing] 课程入口可达并可开始学习", async ({ page }, testInfo) => { for (const course of ["pbr", "parts"]) { await page.goto(`/?tutorial=${course}`, { waitUntil: "domcontentloaded", timeout: 20_000 }); const start = page.getByRole("button", { name: /开始学习|继续学习/ }); await expect(start, `${course} landing has a start button`).toBeVisible({ timeout: 15_000 }); } const image = await shot(page, testInfo, "course-landing"); receipt(testInfo, { workflow: "/?tutorial=pbr and /?tutorial=parts landing pages offer 开始学习", screenshot: image, status: "PASS", }); }); test("[manual-source] 手册源文件与线上页一章不多一章不少", async ({ request }, testInfo) => { const response = await request.get("/manuals/index.html"); expect(response.status()).toBe(200); const html = await response.text(); const ids = Array.from(html.matchAll(/id="(ch\d{2})"/g), (match) => match[1]); const unique = [...new Set(ids)]; expect(unique.sort()).toEqual(CHAPTERS.map((chapter) => chapter.id).sort()); receipt(testInfo, { workflow: "compare chapter anchors in the served manual page against manual.json", chapters: unique.length, source: REPO_ROOT, status: "PASS", }); });