From 744bb0bc32dbe049b7fac90820b484ab241027b8 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Tue, 31 Mar 2026 20:17:15 +0200 Subject: [PATCH] Add tests for Point Light and Spot Light entities --- tests/domain/entity.command.test.ts | 92 ++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/tests/domain/entity.command.test.ts b/tests/domain/entity.command.test.ts index 69ad36d3..c1557da0 100644 --- a/tests/domain/entity.command.test.ts +++ b/tests/domain/entity.command.test.ts @@ -2,7 +2,7 @@ import { describe, expect, it } from "vitest"; import { createEditorStore } from "../../src/app/editor-store"; import { createUpsertEntityCommand } from "../../src/commands/upsert-entity-command"; -import { createSoundEmitterEntity, createTriggerVolumeEntity } from "../../src/entities/entity-instances"; +import { createPointLightEntity, createSoundEmitterEntity, createSpotLightEntity, createTriggerVolumeEntity } from "../../src/entities/entity-instances"; describe("typed entity upsert command", () => { it("places a Sound Emitter and restores the previous tool mode across undo and redo", () => { @@ -41,6 +41,43 @@ describe("typed entity upsert command", () => { expect(store.getState().document.entities[soundEmitter.id]).toEqual(soundEmitter); }); + it("places a Point Light and restores the previous tool mode across undo and redo", () => { + const store = createEditorStore(); + const pointLight = createPointLightEntity({ + position: { + x: 2, + y: 3, + z: 4 + }, + colorHex: "#ccddee", + intensity: 1.5, + distance: 9 + }); + + store.setToolMode("box-create"); + store.executeCommand( + createUpsertEntityCommand({ + entity: pointLight, + label: "Place point light" + }) + ); + + expect(store.getState().toolMode).toBe("select"); + expect(store.getState().selection).toEqual({ + kind: "entities", + ids: [pointLight.id] + }); + expect(store.getState().document.entities[pointLight.id]).toEqual(pointLight); + + expect(store.undo()).toBe(true); + expect(store.getState().toolMode).toBe("box-create"); + expect(store.getState().document.entities).toEqual({}); + + expect(store.redo()).toBe(true); + expect(store.getState().toolMode).toBe("select"); + expect(store.getState().document.entities[pointLight.id]).toEqual(pointLight); + }); + it("updates an existing Trigger Volume without changing its entity id", () => { const store = createEditorStore(); const triggerVolume = createTriggerVolumeEntity({ @@ -91,4 +128,57 @@ describe("typed entity upsert command", () => { expect(store.redo()).toBe(true); expect(store.getState().document.entities[triggerVolume.id]).toEqual(movedTriggerVolume); }); + + it("updates an existing Spot Light without changing its entity id", () => { + const store = createEditorStore(); + const spotLight = createSpotLightEntity({ + id: "entity-spot-main", + position: { + x: -3, + y: 4, + z: 2 + } + }); + const movedSpotLight = createSpotLightEntity({ + ...spotLight, + position: { + x: 5, + y: 6, + z: -4 + }, + direction: { + x: 0.5, + y: -1, + z: 0.25 + }, + colorHex: "#aaccee", + intensity: 2.25, + distance: 14, + angleDegrees: 50 + }); + + store.executeCommand( + createUpsertEntityCommand({ + entity: spotLight, + label: "Place spot light" + }) + ); + store.setToolMode("box-create"); + store.executeCommand( + createUpsertEntityCommand({ + entity: movedSpotLight, + label: "Update spot light" + }) + ); + + expect(store.getState().toolMode).toBe("select"); + expect(store.getState().document.entities[spotLight.id]).toEqual(movedSpotLight); + + expect(store.undo()).toBe(true); + expect(store.getState().toolMode).toBe("box-create"); + expect(store.getState().document.entities[spotLight.id]).toEqual(spotLight); + + expect(store.redo()).toBe(true); + expect(store.getState().document.entities[spotLight.id]).toEqual(movedSpotLight); + }); });