auto-git:
[add] .prettierrc.json [add] eslint.config.js [add] index.html [add] package.json [add] playwright.config.ts [add] src/app/App.tsx [add] src/app/app.css [add] src/app/editor-store.ts [add] src/app/use-editor-store.ts [add] src/assets/.gitkeep [add] src/commands/command-history.ts [add] src/commands/command.ts [add] src/commands/set-scene-name-command.ts [add] src/core/ids.ts [add] src/core/selection.ts [add] src/core/tool-mode.ts [add] src/core/vector.ts [add] src/document/migrate-scene-document.ts [add] src/document/scene-document.ts [add] src/entities/.gitkeep [add] src/geometry/.gitkeep [add] src/main.tsx [add] src/materials/.gitkeep [add] src/runtime-three/.gitkeep [add] src/serialization/local-draft-storage.ts [add] src/serialization/scene-document-json.ts [add] src/shared-ui/Panel.tsx [add] src/viewport-three/ViewportCanvas.tsx [add] src/viewport-three/viewport-host.ts [add] src/vite-env.d.ts [add] tests/domain/create-empty-scene-document.test.ts [add] tests/domain/editor-store.test.ts [add] tests/e2e/app-smoke.e2e.ts [add] tests/serialization/scene-document-json.test.ts [add] tests/setup/vitest.setup.ts [add] tsconfig.json [add] vite.config.ts [add] vitest.config.ts
This commit is contained in:
15
tests/domain/create-empty-scene-document.test.ts
Normal file
15
tests/domain/create-empty-scene-document.test.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { SCENE_DOCUMENT_VERSION, createEmptySceneDocument } from "../../src/document/scene-document";
|
||||
|
||||
describe("createEmptySceneDocument", () => {
|
||||
it("creates a versioned empty scene document", () => {
|
||||
const document = createEmptySceneDocument();
|
||||
|
||||
expect(document.version).toBe(SCENE_DOCUMENT_VERSION);
|
||||
expect(document.name).toBe("Untitled Scene");
|
||||
expect(document.brushes).toEqual({});
|
||||
expect(document.entities).toEqual({});
|
||||
expect(document.modelInstances).toEqual({});
|
||||
});
|
||||
});
|
||||
56
tests/domain/editor-store.test.ts
Normal file
56
tests/domain/editor-store.test.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createEditorStore } from "../../src/app/editor-store";
|
||||
import { createSetSceneNameCommand } from "../../src/commands/set-scene-name-command";
|
||||
import { createEmptySceneDocument } from "../../src/document/scene-document";
|
||||
import type { KeyValueStorage } from "../../src/serialization/local-draft-storage";
|
||||
|
||||
class MemoryStorage implements KeyValueStorage {
|
||||
private readonly values = new Map<string, string>();
|
||||
|
||||
getItem(key: string): string | null {
|
||||
return this.values.get(key) ?? null;
|
||||
}
|
||||
|
||||
setItem(key: string, value: string): void {
|
||||
this.values.set(key, value);
|
||||
}
|
||||
|
||||
removeItem(key: string): void {
|
||||
this.values.delete(key);
|
||||
}
|
||||
}
|
||||
|
||||
describe("EditorStore", () => {
|
||||
it("applies command history with undo and redo", () => {
|
||||
const store = createEditorStore();
|
||||
|
||||
store.executeCommand(createSetSceneNameCommand("Foundation Room"));
|
||||
|
||||
expect(store.getState().document.name).toBe("Foundation Room");
|
||||
expect(store.getState().canUndo).toBe(true);
|
||||
|
||||
expect(store.undo()).toBe(true);
|
||||
expect(store.getState().document.name).toBe("Untitled Scene");
|
||||
expect(store.getState().canRedo).toBe(true);
|
||||
|
||||
expect(store.redo()).toBe(true);
|
||||
expect(store.getState().document.name).toBe("Foundation Room");
|
||||
});
|
||||
|
||||
it("saves and loads a local draft document", () => {
|
||||
const storage = new MemoryStorage();
|
||||
const writerStore = createEditorStore({ storage });
|
||||
|
||||
writerStore.executeCommand(createSetSceneNameCommand("Draft Scene"));
|
||||
expect(writerStore.saveDraft()).toBe(true);
|
||||
|
||||
const readerStore = createEditorStore({
|
||||
initialDocument: createEmptySceneDocument({ name: "Fresh Scene" }),
|
||||
storage
|
||||
});
|
||||
|
||||
expect(readerStore.loadDraft()).toBe(true);
|
||||
expect(readerStore.getState().document.name).toBe("Draft Scene");
|
||||
});
|
||||
});
|
||||
24
tests/e2e/app-smoke.e2e.ts
Normal file
24
tests/e2e/app-smoke.e2e.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
test("app boots and shows the viewport shell", 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("/");
|
||||
|
||||
await expect(page.getByText("WebEditor3D")).toBeVisible();
|
||||
await expect(page.getByTestId("viewport-shell")).toBeVisible();
|
||||
|
||||
expect(pageErrors).toEqual([]);
|
||||
expect(consoleErrors).toEqual([]);
|
||||
});
|
||||
31
tests/serialization/scene-document-json.test.ts
Normal file
31
tests/serialization/scene-document-json.test.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createEmptySceneDocument } from "../../src/document/scene-document";
|
||||
import { migrateSceneDocument } from "../../src/document/migrate-scene-document";
|
||||
import { parseSceneDocumentJson, serializeSceneDocument } from "../../src/serialization/scene-document-json";
|
||||
|
||||
describe("scene document JSON", () => {
|
||||
it("round-trips the current empty schema", () => {
|
||||
const document = createEmptySceneDocument({ name: "Bootstrap Scene" });
|
||||
const serializedDocument = serializeSceneDocument(document);
|
||||
|
||||
expect(parseSceneDocumentJson(serializedDocument)).toEqual(document);
|
||||
});
|
||||
|
||||
it("rejects unsupported versions", () => {
|
||||
expect(() =>
|
||||
migrateSceneDocument({
|
||||
version: 99,
|
||||
name: "Legacy",
|
||||
world: {},
|
||||
materials: {},
|
||||
textures: {},
|
||||
assets: {},
|
||||
brushes: {},
|
||||
modelInstances: {},
|
||||
entities: {},
|
||||
interactionLinks: {}
|
||||
})
|
||||
).toThrow("Unsupported scene document version");
|
||||
});
|
||||
});
|
||||
1
tests/setup/vitest.setup.ts
Normal file
1
tests/setup/vitest.setup.ts
Normal file
@@ -0,0 +1 @@
|
||||
import "@testing-library/jest-dom/vitest";
|
||||
Reference in New Issue
Block a user