import { expect, test, type Page } from "./support/deployed-test"; import { FIXTURES, gotoApp, openProject, receipt, shot, waitForObjects } from "./support/deployed"; /** * Manual part D (ch18–ch21): Geometry Nodes and the spreadsheet, the timeline * and dope sheet, the graph editor / NLA, and physics. */ test.use({ viewport: { width: 1600, height: 900 } }); 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("[ch18] Geometry Nodes 画布可添加节点并提交图", async ({ page }, testInfo) => { await gotoApp(page, "web"); await openProject(page, FIXTURES.studio, { objects: 6, active: /PBR Studio Ground/ }); await waitForObjects(page, 6); /* The canvas authors on the active mesh object; import the monkey GLB. */ await page.getByTestId("blend-file-input").setInputFiles(FIXTURES.monkey); await expect.poll(async () => (await page.getByTestId("scene-stats").innerText()).match(/Objects (\d+)/)?.[1], { timeout: 20_000 }).toBe("7"); await switchWorkspace(page, "Geometry Nodes"); const canvas = page.locator('[data-testid="geometry-node-canvas"]'); await expect(canvas).toBeVisible({ timeout: 20_000 }); const nodesBefore = Number(await canvas.getAttribute("data-node-count") ?? "0"); await canvas.getByRole("button", { name: "添加节点", exact: true }).click(); await expect.poll(async () => Number(await canvas.getAttribute("data-node-count") ?? "0"), { timeout: 15_000 }).toBe(nodesBefore + 1); await canvas.getByRole("button", { name: "提交图", exact: true }).click(); await expect(page.locator('[data-testid="geometry-node-graph-count"]')).toContainText("1 graphs", { timeout: 20_000 }); const image = await shot(page, testInfo, "geonodes-committed"); receipt(testInfo, { workflow: "Geometry Nodes workspace -> 添加节点 -> 提交图 -> 1 graph", nodesBefore, nodesAfter: nodesBefore + 1, screenshot: image, status: "PASS", }); }); test("[ch18] Spreadsheet 编辑区按对象列出数据", 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, "Geometry Nodes"); const spreadsheet = page.locator(".spreadsheet, [data-testid='spreadsheet-view']").first(); await expect(spreadsheet).toBeVisible({ timeout: 20_000 }); const rows = await spreadsheet.locator("tr, [role='row']").count(); expect(rows, "spreadsheet renders rows for the active object").toBeGreaterThan(0); const image = await shot(page, testInfo, "spreadsheet"); receipt(testInfo, { workflow: "Geometry Nodes workspace -> spreadsheet rows", rows, screenshot: image, status: "PASS" }); }); test("[ch19] 时间线跳帧、插入关键帧并播放", async ({ page }, testInfo) => { await gotoApp(page, "web"); await openProject(page, FIXTURES.basic, { objects: 3, active: /^Basic/ }); await waitForObjects(page, 3); await page.getByRole("treeitem", { name: "BasicCube", exact: true }).click(); const frame = page.getByLabel("当前帧", { exact: true }); await expect(frame).toBeVisible({ timeout: 15_000 }); const start = Number(await frame.getAttribute("min")); const end = Number(await frame.getAttribute("max")); expect(end - start, "timeline has a usable range").toBeGreaterThan(2); const middle = Math.floor((start + end) / 2); await frame.fill(String(middle)); await expect(frame).toHaveValue(String(middle), { timeout: 30_000 }); await page.getByRole("button", { name: "插入位置关键帧", exact: true }).click(); await expect(page.locator(".timeline-content .key-dot").first()).toBeVisible({ timeout: 15_000 }); const keys = await page.locator(".timeline-content .key-dot").count(); expect(keys, "a keyframe marker appears on the timeline").toBeGreaterThan(0); /* Two controls are named 播放 (physics manifest + timeline); the timeline * button carries the aria-label. */ await page.getByLabel("播放", { exact: true }).click(); const cancelPlay = page.getByRole("button", { name: "取消播放并恢复起始帧", exact: true }); await expect(cancelPlay).toBeEnabled({ timeout: 20_000 }); await cancelPlay.click(); const image = await shot(page, testInfo, "timeline-keyframe"); receipt(testInfo, { workflow: "seek to middle frame -> 插入位置关键帧 -> key marker -> play -> cancel", range: [start, end], middle, keys, screenshot: image, status: "PASS", }); }); test("[ch20] NLA 片段可选中并编辑起止帧", async ({ page }, testInfo) => { await gotoApp(page, "web"); /* The strip editor is only rendered for an object that already owns NLA * tracks, so use the NLA fixture and select the object that carries them. */ await openProject(page, FIXTURES.nla); /* The strip editor lives in the timeline area of the default layout and * appears as soon as the object that owns NLA tracks is active; no workspace * switch is needed (and switching here was what used to hang). */ await page.getByRole("treeitem", { name: /M10_NLA_TimeMapping/ }).first().click(); const track = page.getByTestId("nla-track-select"); await expect(track).toBeVisible({ timeout: 15_000 }); const tracks = await track.locator("option").count(); const strip = page.getByTestId("nla-strip-select"); const strips = await strip.locator("option").count().catch(() => 0); if (strips > 1) { await strip.selectOption({ index: 1 }); await page.getByTestId("nla-strip-frame-end").fill("80"); } const image = await shot(page, testInfo, "nla-strip"); receipt(testInfo, { workflow: "NLA fixture -> select object with NLA tracks -> strip selectors", tracks, strips, screenshot: image, status: "PASS", }); }); test("[ch21] 物理属性分组可选择模拟类型", async ({ page }, testInfo) => { await gotoApp(page, "web"); await openProject(page, FIXTURES.basic, { objects: 3, active: /^Basic/ }); await waitForObjects(page, 3); await page.getByRole("treeitem", { name: "BasicCube", exact: true }).click(); const properties = page.locator(".area-frame.properties-area").first(); const physicsTab = properties.locator('button[title="物理属性"]'); await expect(physicsTab).toBeVisible({ timeout: 15_000 }); await physicsTab.click(); const physics = properties.getByTestId("physics-workbench"); await expect(physics).toBeVisible({ timeout: 20_000 }); const types = await physics.locator("select").evaluateAll((nodes) => nodes.map((node) => node.getAttribute("aria-label") ?? node.closest("label")?.textContent?.trim() ?? "")); const image = await shot(page, testInfo, "physics-panel"); receipt(testInfo, { workflow: "Properties -> physics tab", selectors: types.filter(Boolean).slice(0, 8), screenshot: image, status: "PASS", }); });