2026-03-31 18:45:53 +02:00
|
|
|
import path from "node:path";
|
|
|
|
|
|
|
|
|
|
import { expect, test } from "@playwright/test";
|
|
|
|
|
|
2026-04-03 00:24:46 +02:00
|
|
|
import { clickViewport, getEditorStoreSnapshot, setViewportCreationPreview } from "./viewport-test-helpers";
|
2026-04-03 00:01:41 +02:00
|
|
|
|
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("outliner-model-instance-list").getByRole("button")).toHaveCount(1);
|
|
|
|
|
|
2026-04-03 00:44:44 +02:00
|
|
|
await page.getByTestId("outliner-add-button").click();
|
|
|
|
|
await page.getByTestId("add-menu-assets").click();
|
|
|
|
|
await page.getByTestId("add-menu-assets-models").click();
|
2026-04-03 00:46:36 +02:00
|
|
|
const addMenu = page.getByRole("menu", { name: "Add" });
|
|
|
|
|
await expect(addMenu.getByRole("menuitem", { name: "scene.gltf" })).toBeVisible();
|
|
|
|
|
await addMenu.getByRole("menuitem", { name: "scene.gltf" }).hover();
|
2026-04-02 23:27:13 +02:00
|
|
|
await expect(page.getByTestId("status-asset-hover")).toContainText("Storage key:");
|
2026-04-03 00:46:36 +02:00
|
|
|
await addMenu.getByRole("menuitem", { name: "scene.gltf" }).click();
|
2026-04-03 00:08:11 +02:00
|
|
|
const importedSnapshot = await getEditorStoreSnapshot(page);
|
|
|
|
|
const importedModelAsset = Object.values(importedSnapshot.document.assets).find(
|
|
|
|
|
(asset) => asset.kind === "model" && asset.sourceName === "scene.gltf"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (importedModelAsset === undefined) {
|
|
|
|
|
throw new Error("Imported model asset was not found in the document snapshot.");
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-03 00:24:46 +02:00
|
|
|
await setViewportCreationPreview(page, "topLeft", { kind: "model-instance", assetId: importedModelAsset.id }, { x: 88, y: 0, z: -84 });
|
2026-04-03 00:01:41 +02:00
|
|
|
await expect(page.getByTestId("viewport-snap-preview-topLeft")).toBeVisible();
|
2026-04-03 00:24:46 +02:00
|
|
|
await clickViewport(page, "topLeft");
|
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:08:35 +02:00
|
|
|
expect(selectedModelInstance.position).toMatchObject({
|
|
|
|
|
x: 88,
|
|
|
|
|
z: -84
|
|
|
|
|
});
|
2026-03-31 18:45:53 +02:00
|
|
|
|
|
|
|
|
expect(pageErrors).toEqual([]);
|
|
|
|
|
expect(consoleErrors).toEqual([]);
|
|
|
|
|
});
|