2026-03-31 18:45:53 +02:00
|
|
|
import path from "node:path";
|
|
|
|
|
|
|
|
|
|
import { expect, test } from "@playwright/test";
|
|
|
|
|
|
2026-04-03 00:01:41 +02:00
|
|
|
import { getEditorStoreSnapshot, getViewportCanvas } from "./viewport-test-helpers";
|
|
|
|
|
|
2026-03-31 18:45:53 +02:00
|
|
|
const gltfFixturePath = path.resolve(process.cwd(), "fixtures/assets/external-triangle/scene.gltf");
|
|
|
|
|
const binFixturePath = path.resolve(process.cwd(), "fixtures/assets/external-triangle/triangle.bin");
|
|
|
|
|
|
2026-04-02 23:34:27 +02:00
|
|
|
test("imports a gltf asset with external resources and places an instance", async ({ page }) => {
|
2026-03-31 18:45:53 +02:00
|
|
|
const pageErrors: string[] = [];
|
|
|
|
|
const consoleErrors: string[] = [];
|
|
|
|
|
|
|
|
|
|
page.on("pageerror", (error) => {
|
|
|
|
|
pageErrors.push(error.message);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
page.on("console", (message) => {
|
|
|
|
|
if (message.type() === "error") {
|
|
|
|
|
consoleErrors.push(message.text());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await page.goto("/");
|
|
|
|
|
|
2026-04-03 00:01:41 +02:00
|
|
|
await page.getByTestId("outliner-add-button").click();
|
|
|
|
|
await page.getByTestId("add-menu-import").click();
|
|
|
|
|
await page.getByTestId("import-menu-model").click();
|
2026-03-31 18:45:53 +02:00
|
|
|
|
|
|
|
|
await page.locator('input[type="file"][accept*="gltf"]').setInputFiles([gltfFixturePath, binFixturePath]);
|
|
|
|
|
|
|
|
|
|
await expect(page.getByTestId("asset-list").getByText("scene.gltf", { exact: true })).toBeVisible();
|
2026-04-02 23:27:13 +02:00
|
|
|
await expect(page.getByTestId("asset-list")).not.toContainText("Storage key:");
|
2026-03-31 18:45:53 +02:00
|
|
|
await expect(page.getByTestId("outliner-model-instance-list").getByRole("button")).toHaveCount(1);
|
|
|
|
|
|
2026-04-02 23:31:44 +02:00
|
|
|
await page.getByRole("button", { name: "Place instance for scene.gltf" }).hover();
|
2026-04-02 23:27:13 +02:00
|
|
|
await expect(page.getByTestId("status-asset-hover")).toContainText("Storage key:");
|
2026-04-02 23:31:44 +02:00
|
|
|
await page.getByRole("button", { name: "Place instance for scene.gltf" }).click();
|
2026-04-03 00:06:31 +02:00
|
|
|
await page.getByTestId("viewport-panel-topLeft").click({ position: { x: 16, y: 16 }, force: true });
|
2026-04-03 00:01:41 +02:00
|
|
|
const viewportCanvas = getViewportCanvas(page);
|
2026-04-03 00:04:24 +02:00
|
|
|
await viewportCanvas.hover({ position: { x: 88, y: 84 }, force: true });
|
2026-04-03 00:01:41 +02:00
|
|
|
await expect(page.getByTestId("viewport-snap-preview-topLeft")).toBeVisible();
|
2026-04-03 00:04:24 +02:00
|
|
|
await viewportCanvas.click({ position: { x: 88, y: 84 }, force: true });
|
2026-03-31 18:45:53 +02:00
|
|
|
await expect(page.getByTestId("outliner-model-instance-list").getByRole("button")).toHaveCount(2);
|
2026-04-03 00:01:41 +02:00
|
|
|
const snapshot = await getEditorStoreSnapshot(page);
|
2026-04-03 00:03:02 +02:00
|
|
|
const selectedModelInstanceId = snapshot.selection.kind === "modelInstances" ? snapshot.selection.ids?.[0] ?? null : null;
|
2026-04-03 00:01:41 +02:00
|
|
|
|
|
|
|
|
expect(selectedModelInstanceId).not.toBeNull();
|
|
|
|
|
|
|
|
|
|
const selectedModelInstance = snapshot.document.modelInstances[selectedModelInstanceId as string];
|
|
|
|
|
|
2026-04-03 00:02:33 +02:00
|
|
|
if (selectedModelInstance === undefined) {
|
|
|
|
|
throw new Error("Placed model instance is missing from the document snapshot.");
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-03 00:01:41 +02:00
|
|
|
expect(Math.abs(selectedModelInstance.position.x) > 0 || Math.abs(selectedModelInstance.position.z) > 0).toBe(true);
|
2026-03-31 18:45:53 +02:00
|
|
|
|
|
|
|
|
expect(pageErrors).toEqual([]);
|
|
|
|
|
expect(consoleErrors).toEqual([]);
|
|
|
|
|
});
|