From bbd05f7b320dd1da1c9e6e37dd46789c959d4dd3 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Wed, 13 May 2026 00:51:37 +0200 Subject: [PATCH] Add tests for terrain layer management, including undo/redo functionality --- tests/domain/terrain.command.test.ts | 54 ++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tests/domain/terrain.command.test.ts b/tests/domain/terrain.command.test.ts index f27793d7..ad32ff43 100644 --- a/tests/domain/terrain.command.test.ts +++ b/tests/domain/terrain.command.test.ts @@ -1,8 +1,10 @@ import { describe, expect, it } from "vitest"; import { createEditorStore } from "../../src/app/editor-store"; +import { createAddTerrainLayerCommand } from "../../src/commands/add-terrain-layer-command"; import { createApplyTerrainBrushPatchCommand } from "../../src/commands/apply-terrain-brush-patch-command"; import { createDeleteTerrainCommand } from "../../src/commands/delete-terrain-command"; +import { createDeleteTerrainLayerCommand } from "../../src/commands/delete-terrain-layer-command"; import { createUpsertTerrainCommand } from "../../src/commands/upsert-terrain-command"; import { createEmptySceneDocument } from "../../src/document/scene-document"; import { @@ -355,4 +357,56 @@ describe("terrain commands", () => { ) ).toBe(0.85); }); + + it("adds and removes terrain material layers with undo and redo", () => { + const terrain = createTerrain({ + id: "terrain-layer-command", + sampleCountX: 2, + sampleCountZ: 2 + }); + const store = createEditorStore({ + initialDocument: { + ...createEmptySceneDocument({ name: "Terrain Layer Command Scene" }), + terrains: { + [terrain.id]: terrain + } + } + }); + + store.executeCommand( + createAddTerrainLayerCommand({ + terrainId: terrain.id, + materialId: "ground_sand_300x300" + }) + ); + + expect(store.getState().document.terrains[terrain.id]?.layers).toHaveLength( + 5 + ); + expect( + store.getState().document.terrains[terrain.id]?.paintWeights + ).toHaveLength(2 * 2 * 4); + + expect(store.undo()).toBe(true); + expect(store.getState().document.terrains[terrain.id]?.layers).toHaveLength( + 4 + ); + + expect(store.redo()).toBe(true); + store.executeCommand( + createDeleteTerrainLayerCommand({ + terrainId: terrain.id, + layerIndex: 4 + }) + ); + + expect(store.getState().document.terrains[terrain.id]?.layers).toHaveLength( + 4 + ); + + expect(store.undo()).toBe(true); + expect(store.getState().document.terrains[terrain.id]?.layers).toHaveLength( + 5 + ); + }); });