import { expect, test } from "@playwright/test"; import path from "node:path"; const materialBlend = path.resolve(import.meta.dirname, "../../../tests/files/web/attribute_scene.blend"); const exportableBlend = path.resolve(import.meta.dirname, "../../../tests/files/web/basic_scene.blend"); const image = path.resolve(import.meta.dirname, "../../../tests/files/web/media/sequencer-frame.png"); test("M7-01 records import, open, save, save-as and export success", async ({ page }) => { await page.goto("/"); await expect(page.getByTestId("engine-status")).toContainText("ready, open a .blend file", { timeout: 20_000 }); const app = page.locator(".blender-app"); await page.getByTestId("blend-file-input").setInputFiles(exportableBlend); await expect(app).toHaveAttribute("data-user-action-open-status", "SUCCEEDED"); await expect(app).toHaveAttribute("data-user-action-open-id", /^OPEN:\d+$/); const glbDownload = page.waitForEvent("download"); await page.getByRole("button", { name: "导出 GLB" }).click(); expect((await glbDownload).suggestedFilename()).toBe("blender-web.glb"); await expect(app).toHaveAttribute("data-user-action-export-status", "SUCCEEDED"); await expect(app).toHaveAttribute("data-user-action-export-id", /^EXPORT:\d+$/); await page.getByTestId("blend-file-input").setInputFiles(materialBlend); await expect(app).toHaveAttribute("data-user-action-open-status", "SUCCEEDED"); await page.locator("label.file-button input[type=file]").setInputFiles(image); await expect(app).toHaveAttribute("data-user-action-import-status", "SUCCEEDED"); await expect(app).toHaveAttribute("data-user-action-import-id", /^IMPORT:\d+$/); const blendDownload = page.waitForEvent("download"); await page.getByRole("button", { name: "保存项目" }).click(); expect((await blendDownload).suggestedFilename()).toBe("blender-web.blend"); await expect(app).toHaveAttribute("data-user-action-save-status", "SUCCEEDED"); await expect(app).toHaveAttribute("data-user-action-save-as-status", "SUCCEEDED"); await expect(app).toHaveAttribute("data-user-action-save-id", /^SAVE:\d+$/); await expect(app).toHaveAttribute("data-user-action-save-as-id", /^SAVE_AS:\d+$/); await expect(app).toHaveAttribute("data-save-transaction-status", "SUCCEEDED"); await expect(app).toHaveAttribute("data-save-transaction-stage", "METADATA_COMMIT"); await expect(app).toHaveAttribute("data-save-committed-hash", /^[a-f0-9]{64}$/); }); test("M7-01 exposes stable failure codes without replacing the last valid scene", async ({ page }) => { await page.goto("/"); await expect(page.getByTestId("engine-status")).toContainText("ready, open a .blend file", { timeout: 20_000 }); const app = page.locator(".blender-app"); await page.getByRole("button", { name: "导出 GLB" }).click(); await expect(app).toHaveAttribute("data-user-action-export-status", "FAILED"); await expect(app).toHaveAttribute("data-user-action-export-error", "EXPORT_PROJECT_UNAVAILABLE"); await page.getByTestId("blend-file-input").setInputFiles(materialBlend); await expect(page.getByText("AttributeMeshObject", { exact: true })).toBeVisible(); await page.getByTestId("blend-file-input").setInputFiles({ name: "invalid.blend", mimeType: "application/octet-stream", buffer: Buffer.from([0x42, 0x41, 0x44]), }); await expect(app).toHaveAttribute("data-user-action-open-status", "FAILED"); await expect(app).toHaveAttribute("data-user-action-open-error", "OPEN_ENGINE_FAILED"); await expect(page.getByText("AttributeMeshObject", { exact: true })).toBeVisible(); await page.locator("label.file-button input[type=file]").setInputFiles({ name: "invalid.png", mimeType: "image/png", buffer: Buffer.from("not-a-png"), }); await expect(app).toHaveAttribute("data-user-action-import-status", "FAILED"); await expect(app).toHaveAttribute("data-user-action-import-error", "IMPORT_DECODE_FAILED"); });