Add tests for box brush face editing and update existing tests
This commit is contained in:
99
tests/domain/box-brush-face-editing.command.test.ts
Normal file
99
tests/domain/box-brush-face-editing.command.test.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
@@ -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]
|
||||
|
||||
@@ -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));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user