Add tests for world settings command and helpers
This commit is contained in:
33
tests/domain/world-settings.command.test.ts
Normal file
33
tests/domain/world-settings.command.test.ts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
import { createEditorStore } from "../../src/app/editor-store";
|
||||||
|
import { createSetWorldSettingsCommand } from "../../src/commands/set-world-settings-command";
|
||||||
|
import { createEmptySceneDocument } from "../../src/document/scene-document";
|
||||||
|
import { cloneWorldSettings } from "../../src/document/world-settings";
|
||||||
|
|
||||||
|
describe("createSetWorldSettingsCommand", () => {
|
||||||
|
it("updates authored world settings and restores them through undo", () => {
|
||||||
|
const store = createEditorStore();
|
||||||
|
const originalWorld = cloneWorldSettings(store.getState().document.world);
|
||||||
|
const nextWorld = cloneWorldSettings(originalWorld);
|
||||||
|
|
||||||
|
nextWorld.background = {
|
||||||
|
mode: "verticalGradient",
|
||||||
|
topColorHex: "#6e8db4",
|
||||||
|
bottomColorHex: "#18212b"
|
||||||
|
};
|
||||||
|
nextWorld.ambientLight.intensity = 0.45;
|
||||||
|
|
||||||
|
store.executeCommand(
|
||||||
|
createSetWorldSettingsCommand({
|
||||||
|
label: "Set world lighting",
|
||||||
|
world: nextWorld
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(store.getState().document.world).toEqual(nextWorld);
|
||||||
|
|
||||||
|
expect(store.undo()).toBe(true);
|
||||||
|
expect(store.getState().document.world).toEqual(createEmptySceneDocument().world);
|
||||||
|
});
|
||||||
|
});
|
||||||
43
tests/domain/world-settings.test.ts
Normal file
43
tests/domain/world-settings.test.ts
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
import { createDefaultWorldSettings } from "../../src/document/scene-document";
|
||||||
|
import { areWorldSettingsEqual, changeWorldBackgroundMode, cloneWorldSettings } from "../../src/document/world-settings";
|
||||||
|
|
||||||
|
describe("world settings helpers", () => {
|
||||||
|
it("clones world settings without retaining nested references", () => {
|
||||||
|
const source = createDefaultWorldSettings();
|
||||||
|
const clone = cloneWorldSettings(source);
|
||||||
|
|
||||||
|
expect(clone).toEqual(source);
|
||||||
|
expect(clone).not.toBe(source);
|
||||||
|
expect(clone.background).not.toBe(source.background);
|
||||||
|
expect(clone.sunLight.direction).not.toBe(source.sunLight.direction);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("switches a solid background into a gradient while preserving the authored color as the top edge", () => {
|
||||||
|
const gradient = changeWorldBackgroundMode(
|
||||||
|
{
|
||||||
|
mode: "solid",
|
||||||
|
colorHex: "#334455"
|
||||||
|
},
|
||||||
|
"verticalGradient"
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(gradient).toEqual({
|
||||||
|
mode: "verticalGradient",
|
||||||
|
topColorHex: "#334455",
|
||||||
|
bottomColorHex: "#141a22"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("compares authored world settings by value", () => {
|
||||||
|
const left = createDefaultWorldSettings();
|
||||||
|
const right = cloneWorldSettings(left);
|
||||||
|
|
||||||
|
expect(areWorldSettingsEqual(left, right)).toBe(true);
|
||||||
|
|
||||||
|
right.sunLight.direction.x = right.sunLight.direction.x + 0.25;
|
||||||
|
|
||||||
|
expect(areWorldSettingsEqual(left, right)).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user