import { expect, test, type Page } from "./support/deployed-test"; import { FIXTURES, gotoApp, openProject, receipt, shot, waitForObjects } from "./support/deployed"; /** * Manual part F (ch29–ch31): the scripting editors, preferences and keymap, * and the troubleshooting entry points. */ test.use({ viewport: { width: 1600, height: 900 } }); async function menu(page: Page, ...items: string[]): Promise { await page.getByRole("button", { name: items[0], exact: true }).click(); for (const name of items.slice(1)) await page.getByRole("menuitem", { name, exact: true }).click(); } async function switchWorkspace(page: Page, name: string): Promise { await page.locator('nav[aria-label="工作区"] button', { hasText: new RegExp(`^${name}$`) }).click(); await expect(page.locator("main.blender-app")).toHaveAttribute("data-workspace", name, { timeout: 15_000 }); } test("[ch29] Scripting 工作区提供文本编辑器与 Python 控制台", async ({ page }, testInfo) => { await gotoApp(page, "web"); await openProject(page, FIXTURES.studio, { objects: 6, active: /PBR Studio Ground/ }); await waitForObjects(page, 6); await switchWorkspace(page, "Scripting"); const textEditor = page.locator(".area-frame.text-editor-area, .text-editor-area").first(); const console_ = page.locator(".area-frame.console-area, .console-area").first(); await expect(textEditor).toBeVisible({ timeout: 20_000 }); await expect(console_).toBeVisible({ timeout: 20_000 }); const infoLine = await page.getByTestId("info-engine-line").innerText().catch(() => ""); expect(infoLine || (await textEditor.innerText()).length, "scripting surfaces render content").toBeTruthy(); const image = await shot(page, testInfo, "scripting"); receipt(testInfo, { workflow: "Scripting workspace -> Text Editor + Python Console + Info", infoLine: infoLine.trim().slice(0, 120), screenshot: image, status: "PASS", }); }); test("[ch30] @smoke 偏好设置计数与保存落盘到 OPFS", async ({ page }, testInfo) => { await gotoApp(page, "web"); await openProject(page, FIXTURES.studio, { objects: 6, active: /PBR Studio Ground/ }); await waitForObjects(page, 6); await menu(page, "编辑", "偏好设置"); const window = page.getByTestId("preferences-window"); await expect(window).toBeVisible({ timeout: 15_000 }); const navCount = await page.getByRole("dialog", { name: "Web Blender 偏好设置" }).locator("nav button").count(); expect(navCount, "preferences has all nine sections").toBe(9); const statusToggle = page.getByLabel("显示状态栏", { exact: true }); const wasChecked = await statusToggle.isChecked(); if (wasChecked) await statusToggle.uncheck(); else await statusToggle.check(); await page.getByRole("button", { name: "保存偏好", exact: true }).click(); await expect(window.locator("header output")).toContainText("已保存到 OPFS", { timeout: 15_000 }); /* Restore the previous value so later runs see a stable default. */ if (wasChecked) await statusToggle.check(); else await statusToggle.uncheck(); await page.getByRole("button", { name: "保存偏好", exact: true }).click(); await expect(window.locator("header output")).toContainText("已保存到 OPFS", { timeout: 15_000 }); const stored = await page.evaluate(async () => { const root = await navigator.storage.getDirectory(); const settings = await root.getDirectoryHandle("settings"); const file = await (await settings.getFileHandle("web-interface.json")).getFile(); return JSON.parse(await file.text()) as { preferences?: unknown }; }); expect(stored.preferences, "preferences are written to OPFS settings/web-interface.json").toBeTruthy(); const image = await shot(page, testInfo, "preferences-saved"); receipt(testInfo, { workflow: "编辑 → 偏好设置 -> toggle 显示状态栏 -> 保存偏好 -> OPFS settings/web-interface.json", navCount, screenshot: image, status: "PASS", }); }); test("[ch31] 诊断报告可从顶栏导出", async ({ page }, testInfo) => { await gotoApp(page, "web"); await openProject(page, FIXTURES.studio, { objects: 6, active: /PBR Studio Ground/ }); await waitForObjects(page, 6); /* A healthy session records no diagnostics and the export entry stays * disabled; that is the documented behaviour, so the case asserts the state * and downloads only when diagnostics exist. */ const button = page.getByLabel("导出诊断报告"); await expect(button).toBeVisible({ timeout: 15_000 }); const enabled = await button.isEnabled(); let downloadName: string | null = null; if (enabled) { const downloadPromise = page.waitForEvent("download", { timeout: 20_000 }); await button.click(); const download = await downloadPromise; expect(download.suggestedFilename()).toMatch(/diagnostics.*\.json$|\.json$/i); downloadName = download.suggestedFilename(); } const image = await shot(page, testInfo, "diagnostics"); receipt(testInfo, { workflow: "top bar 导出诊断报告", diagnosticsExport: enabled ? downloadName : "disabled (no diagnostics recorded in this session)", screenshot: image, status: "PASS", }); });