Add tests for box brush face editing and update existing tests

This commit is contained in:
2026-03-31 02:39:12 +02:00
parent 6c41d31e68
commit cbf7e16dd4
5 changed files with 292 additions and 3 deletions

View File

@@ -0,0 +1,99 @@
import { describe, expect, it } from "vitest";
import { createEditorStore } from "../../src/app/editor-store";
import { createCreateBoxBrushCommand } from "../../src/commands/create-box-brush-command";
import { createSetBoxBrushFaceMaterialCommand } from "../../src/commands/set-box-brush-face-material-command";
import { createSetBoxBrushFaceUvStateCommand } from "../../src/commands/set-box-brush-face-uv-state-command";
describe("box brush face editing commands", () => {
it("applies a material to one box face and supports undo/redo", () => {
const store = createEditorStore();
store.executeCommand(createCreateBoxBrushCommand());
const createdBrush = Object.values(store.getState().document.brushes)[0];
store.executeCommand(
createSetBoxBrushFaceMaterialCommand({
brushId: createdBrush.id,
faceId: "posZ",
materialId: "starter-amber-grid"
})
);
expect(store.getState().document.brushes[createdBrush.id].faces.posZ.materialId).toBe("starter-amber-grid");
expect(store.getState().selection).toEqual({
kind: "brushFace",
brushId: createdBrush.id,
faceId: "posZ"
});
expect(store.undo()).toBe(true);
expect(store.getState().document.brushes[createdBrush.id].faces.posZ.materialId).toBeNull();
expect(store.redo()).toBe(true);
expect(store.getState().document.brushes[createdBrush.id].faces.posZ.materialId).toBe("starter-amber-grid");
});
it("updates face UV state through an undoable command", () => {
const store = createEditorStore();
store.executeCommand(createCreateBoxBrushCommand());
const createdBrush = Object.values(store.getState().document.brushes)[0];
store.executeCommand(
createSetBoxBrushFaceUvStateCommand({
brushId: createdBrush.id,
faceId: "posY",
uvState: {
offset: {
x: 0.5,
y: -0.25
},
scale: {
x: 0.25,
y: 0.5
},
rotationQuarterTurns: 1,
flipU: true,
flipV: false
},
label: "Adjust top face UVs"
})
);
expect(store.getState().document.brushes[createdBrush.id].faces.posY.uv).toEqual({
offset: {
x: 0.5,
y: -0.25
},
scale: {
x: 0.25,
y: 0.5
},
rotationQuarterTurns: 1,
flipU: true,
flipV: false
});
expect(store.undo()).toBe(true);
expect(store.getState().document.brushes[createdBrush.id].faces.posY.uv).toEqual({
offset: {
x: 0,
y: 0
},
scale: {
x: 1,
y: 1
},
rotationQuarterTurns: 0,
flipU: false,
flipV: false
});
expect(store.redo()).toBe(true);
expect(store.getState().document.brushes[createdBrush.id].faces.posY.uv.rotationQuarterTurns).toBe(1);
expect(store.getState().document.brushes[createdBrush.id].faces.posY.uv.flipU).toBe(true);
});
});

View File

@@ -39,6 +39,22 @@ describe("box brush commands", () => {
z: 4
});
expect(Object.keys(brush.faces)).toEqual(["posX", "negX", "posY", "negY", "posZ", "negZ"]);
expect(brush.faces.posX).toEqual({
materialId: null,
uv: {
offset: {
x: 0,
y: 0
},
scale: {
x: 1,
y: 1
},
rotationQuarterTurns: 0,
flipU: false,
flipV: false
}
});
expect(store.getState().selection).toEqual({
kind: "brushes",
ids: [brush.id]

View File

@@ -1,6 +1,7 @@
import { describe, expect, it } from "vitest";
import { SCENE_DOCUMENT_VERSION, createEmptySceneDocument } from "../../src/document/scene-document";
import { STARTER_MATERIAL_LIBRARY } from "../../src/materials/starter-material-library";
describe("createEmptySceneDocument", () => {
it("creates a versioned empty scene document", () => {
@@ -11,5 +12,6 @@ describe("createEmptySceneDocument", () => {
expect(document.brushes).toEqual({});
expect(document.entities).toEqual({});
expect(document.modelInstances).toEqual({});
expect(Object.keys(document.materials)).toEqual(STARTER_MATERIAL_LIBRARY.map((material) => material.id));
});
});