2026-03-31 17:52:07 +02:00
|
|
|
import path from "node:path";
|
|
|
|
|
|
|
|
|
|
import { expect, test } from "@playwright/test";
|
|
|
|
|
|
2026-04-03 00:07:58 +02:00
|
|
|
import { getEditorStoreSnapshot, setViewportPlacementPreview } from "./viewport-test-helpers";
|
2026-04-03 00:01:24 +02:00
|
|
|
|
2026-03-31 17:52:07 +02:00
|
|
|
const fixturePath = path.resolve(process.cwd(), "fixtures/assets/tiny-triangle.gltf");
|
|
|
|
|
|
|
|
|
|
test("imports a model asset, places an instance, and survives reload", async ({ page }) => {
|
|
|
|
|
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:24 +02:00
|
|
|
await page.getByTestId("outliner-add-button").click();
|
|
|
|
|
await page.getByTestId("add-menu-import").click();
|
|
|
|
|
await expect(page.getByTestId("import-menu-model")).toBeVisible();
|
|
|
|
|
await expect(page.getByTestId("import-menu-environment")).toBeVisible();
|
|
|
|
|
await expect(page.getByTestId("import-menu-audio")).toBeVisible();
|
|
|
|
|
await page.getByTestId("import-menu-model").click();
|
2026-03-31 17:52:07 +02:00
|
|
|
|
|
|
|
|
await page.locator('input[type="file"][accept*="gltf"]').setInputFiles(fixturePath);
|
|
|
|
|
|
2026-03-31 17:53:09 +02:00
|
|
|
await expect(page.getByTestId("asset-list").getByText("tiny-triangle.gltf", { exact: true })).toBeVisible();
|
2026-04-02 23:27:09 +02:00
|
|
|
await expect(page.getByTestId("asset-list")).not.toContainText("Storage key:");
|
2026-03-31 17:52:07 +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 tiny-triangle.gltf" }).hover();
|
2026-04-02 23:27:09 +02:00
|
|
|
await expect(page.getByTestId("status-asset-hover")).toContainText("Storage key:");
|
2026-04-03 00:01:41 +02:00
|
|
|
await page.getByRole("button", { name: "Place instance for tiny-triangle.gltf" }).click();
|
2026-04-03 00:07:58 +02:00
|
|
|
const importedSnapshot = await getEditorStoreSnapshot(page);
|
|
|
|
|
const importedModelAsset = Object.values(importedSnapshot.document.assets).find(
|
|
|
|
|
(asset) => asset.kind === "model" && asset.sourceName === "tiny-triangle.gltf"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (importedModelAsset === undefined) {
|
|
|
|
|
throw new Error("Imported model asset was not found in the document snapshot.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await setViewportPlacementPreview(page, "topLeft", { kind: "model-instance", assetId: importedModelAsset.id }, { x: 92, y: 0, z: -76 });
|
2026-04-03 00:01:24 +02:00
|
|
|
await expect(page.getByTestId("viewport-snap-preview-topLeft")).toBeVisible();
|
2026-04-03 00:09:33 +02:00
|
|
|
await page.getByTestId("viewport-fallback-place-topLeft").dispatchEvent("click");
|
2026-03-31 17:52:07 +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:00 +02:00
|
|
|
const selectedModelInstanceId = snapshot.selection.kind === "modelInstances" ? snapshot.selection.ids?.[0] ?? null : null;
|
2026-04-03 00:01:24 +02:00
|
|
|
|
2026-04-03 00:01:41 +02:00
|
|
|
expect(selectedModelInstanceId).not.toBeNull();
|
2026-04-03 00:01:24 +02:00
|
|
|
|
2026-04-03 00:01:41 +02:00
|
|
|
const selectedModelInstance = snapshot.document.modelInstances[selectedModelInstanceId as string];
|
2026-04-03 00:01:24 +02:00
|
|
|
|
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: 92,
|
|
|
|
|
z: -76
|
|
|
|
|
});
|
2026-03-31 17:52:07 +02:00
|
|
|
|
|
|
|
|
await page.getByRole("button", { name: "Save Draft" }).click();
|
|
|
|
|
await expect(page.getByTestId("status-message")).toContainText("Local draft saved.");
|
|
|
|
|
|
|
|
|
|
await page.reload();
|
|
|
|
|
|
2026-03-31 17:53:09 +02:00
|
|
|
await expect(page.getByTestId("asset-list").getByText("tiny-triangle.gltf", { exact: true })).toBeVisible();
|
2026-04-02 23:27:09 +02:00
|
|
|
await expect(page.getByTestId("asset-list")).not.toContainText("Storage key:");
|
2026-03-31 17:52:07 +02:00
|
|
|
await expect(page.getByTestId("outliner-model-instance-list").getByRole("button")).toHaveCount(2);
|
|
|
|
|
await expect(page.getByTestId("asset-status-message")).toHaveCount(0);
|
|
|
|
|
|
|
|
|
|
expect(pageErrors).toEqual([]);
|
|
|
|
|
expect(consoleErrors).toEqual([]);
|
|
|
|
|
});
|