import { expect, test } from "./support/deployed-test"; import { FIXTURES, gotoApp, openProject, opfsProjectIds, receipt, shot, waitEngineBoot, waitForObjects } from "./support/deployed"; /** * Manual part A (ch01–ch05): first load, opening a project, saving to OPFS, * recent projects and recovery. Every assertion is a user-visible end state — * object count, status bar text, OPFS contents — never "the button was clicked". */ test.use({ viewport: { width: 1600, height: 900 } }); test("[ch01] @smoke 打开练习工程、编辑后保存到 OPFS", async ({ page }, testInfo) => { await gotoApp(page, "web"); const engineStatus = await openProject(page, FIXTURES.studio, { objects: 6, active: /PBR Studio Ground/ }); await waitForObjects(page, 6); /* A visible edit first, so the save has something to persist. */ await page.getByRole("button", { name: "添加立方体", exact: true }).click(); await waitForObjects(page, 7); await page.getByLabel("保存项目").click(); await expect(page.getByTestId("dirty-status")).toHaveText("已保存", { timeout: 20_000 }); const projects = await opfsProjectIds(page); expect(projects.length, "the project must be written to OPFS").toBeGreaterThan(0); const image = await shot(page, testInfo, "saved"); receipt(testInfo, { workflow: "open studio.blend -> add cube (6->7 objects) -> 保存项目 -> 已保存 -> OPFS projects", engineStatus, projects, screenshot: image, status: "PASS", }); }); test("[ch02] 工作区标签齐全且状态栏反映引擎状态", async ({ page }, testInfo) => { await gotoApp(page, "web"); await waitEngineBoot(page); const expected = ["Layout", "Modeling", "Sculpting", "UV Editing", "Texture Paint", "Shading", "Animation", "Rendering", "Compositing", "Geometry Nodes", "Scripting"]; const tabs = page.locator('nav[aria-label="工作区"] button'); const labels = (await tabs.allInnerTexts()).map((text) => text.trim()); for (const name of expected) expect(labels, `workspace tab ${name}`).toContain(name); /* This chapter is about the shell, not a project: the engine is expected to * sit on the built-in General template here, so SceneIR is not required. */ await expect(page.getByTestId("engine-status")).not.toContainText(/starting/i); const engineStatus = (await page.getByTestId("engine-status").innerText()).trim(); expect(engineStatus, "status bar reports an engine state").toMatch(/Engine|SceneIR/i); const statusBar = (await page.locator(".status-bar").innerText()).replace(/\s+/g, " ").trim(); expect(statusBar).toMatch(/Engine|SceneIR|objects/i); const image = await shot(page, testInfo, "workspaces"); receipt(testInfo, { workflow: "11 workspace tabs present; status bar reports engine", labels, engineStatus, statusBar, screenshot: image, status: "PASS", }); }); test("[ch03] 新建工程与最近项目可重开", async ({ page }, testInfo) => { await gotoApp(page, "web"); await waitEngineBoot(page); await openProject(page, FIXTURES.studio, { objects: 6, active: /PBR Studio Ground/ }); await waitForObjects(page, 6); await page.getByLabel("保存项目").click(); await expect(page.getByTestId("dirty-status")).toHaveText("已保存", { timeout: 20_000 }); /* 文件 → 新建 → 常规 opens a confirmation dialog; the project is replaced * only after 新建常规工程 is pressed. */ await page.getByRole("button", { name: "文件", exact: true }).click(); await page.getByRole("menuitem", { name: "新建", exact: true }).click({ timeout: 15_000 }); await page.getByRole("menuitem", { name: "常规", exact: true }).click({ timeout: 15_000 }); const newDialog = page.getByRole("dialog", { name: "新建工程" }); await expect(newDialog).toBeVisible({ timeout: 15_000 }); await newDialog.getByRole("button", { name: "新建常规工程", exact: true }).click(); await waitForObjects(page, 3); /* The saved project is listed and reopens with its six objects. */ const recent = page.getByTestId("recent-projects"); await expect(recent.locator("option").first()).toBeAttached({ timeout: 20_000 }); await recent.selectOption({ index: 1 }); const discard = page.getByRole("button", { name: "不保存,继续", exact: true }); if (await discard.count() && await discard.isVisible()) await discard.click(); await expect.poll(async () => (await page.getByTestId("scene-stats").innerText()).match(/Objects (\d+)/)?.[1], { timeout: 20_000 }).toBe("6"); const image = await shot(page, testInfo, "reopen-recent"); receipt(testInfo, { workflow: "save studio -> 文件→新建→常规 (Objects 3) -> 最近项目 -> reopen (Objects 6)", screenshot: image, status: "PASS", }); }); test("[ch04] 刷新后从最近项目恢复已保存工程", async ({ page }, testInfo) => { await gotoApp(page, "web"); await waitEngineBoot(page); await openProject(page, FIXTURES.studio, { objects: 6, active: /PBR Studio Ground/ }); await waitForObjects(page, 6); await page.getByRole("button", { name: "添加立方体", exact: true }).click(); await waitForObjects(page, 7); await page.getByLabel("保存项目").click(); await expect(page.getByTestId("dirty-status")).toHaveText("已保存", { timeout: 20_000 }); const projects = await opfsProjectIds(page); await page.reload({ waitUntil: "domcontentloaded" }); await waitEngineBoot(page); const recent = page.getByTestId("recent-projects"); await expect(recent.locator("option").first()).toBeAttached({ timeout: 20_000 }); await recent.selectOption({ index: 1 }); const discard = page.getByRole("button", { name: "不保存,继续", exact: true }); if (await discard.count() && await discard.isVisible()) await discard.click(); await expect.poll(async () => (await page.getByTestId("scene-stats").innerText()).match(/Objects (\d+)/)?.[1], { timeout: 20_000 }).toBe("7"); const image = await shot(page, testInfo, "reloaded-recent"); receipt(testInfo, { workflow: "save 7-object scene -> reload -> 最近项目 -> Objects 7", projects, screenshot: image, status: "PASS", }); }); test("[ch05] 撤销重做与诊断报告导出", async ({ page }, testInfo) => { await gotoApp(page, "web"); await openProject(page, FIXTURES.basic, { objects: 3, active: /^Basic/ }); await waitForObjects(page, 3); await page.getByRole("button", { name: "添加立方体", exact: true }).click(); await waitForObjects(page, 4); await page.getByRole("button", { name: "撤销", exact: true }).click(); await waitForObjects(page, 3); await page.getByRole("button", { name: "重做", exact: true }).click(); await waitForObjects(page, 4); /* The export entry is disabled while the session has recorded no diagnostics * (a healthy run legitimately has none), so the check is the state, not a * download that cannot happen. */ const diagnostics = page.getByLabel("导出诊断报告"); await expect(diagnostics).toBeVisible(); const enabled = await diagnostics.isEnabled(); let downloadName: string | null = null; if (enabled) { const downloadPromise = page.waitForEvent("download", { timeout: 20_000 }); await diagnostics.click(); const download = await downloadPromise; expect(download.suggestedFilename()).toMatch(/\.json$/i); downloadName = download.suggestedFilename(); } const image = await shot(page, testInfo, "undo-redo"); receipt(testInfo, { workflow: "add cube (3→4) -> 撤销 (→3) -> 重做 (→4) -> 导出诊断报告", diagnosticsExport: enabled ? downloadName : "disabled (no diagnostics recorded in this session)", screenshot: image, status: "PASS", }); });