Add unit tests for resolving viewport world state

This commit is contained in:
2026-05-18 12:59:37 +02:00
parent 101ba4508c
commit 8e5931a1fb

View File

@@ -1,7 +1,10 @@
import { describe, expect, it } from "vitest"; import { describe, expect, it } from "vitest";
import { createDefaultProjectTimeSettings } from "../../src/document/project-time-settings";
import { createDefaultWorldSettings } from "../../src/document/world-settings";
import { import {
createViewportSimulationMembershipSignatures createViewportSimulationMembershipSignatures,
resolveViewportWorldState
} from "../../src/viewport-three/viewport-host"; } from "../../src/viewport-three/viewport-host";
import type { RuntimeSceneDefinition } from "../../src/runtime-three/runtime-scene-build"; import type { RuntimeSceneDefinition } from "../../src/runtime-three/runtime-scene-build";
@@ -98,3 +101,64 @@ describe("createViewportSimulationMembershipSignatures", () => {
).not.toEqual(createViewportSimulationMembershipSignatures(runtimeScene)); ).not.toEqual(createViewportSimulationMembershipSignatures(runtimeScene));
}); });
}); });
describe("resolveViewportWorldState", () => {
it("applies document project time when the runtime scene is unavailable", () => {
const world = createDefaultWorldSettings();
const time = createDefaultProjectTimeSettings();
time.startTimeOfDayHours = 0;
world.projectTimeLightingEnabled = true;
world.ambientLight = {
colorHex: "#ffffff",
intensity: 1
};
world.timeOfDay.night.ambientColorHex = "#101820";
world.timeOfDay.night.ambientIntensityFactor = 0.25;
const state = resolveViewportWorldState({
currentWorld: world,
currentDocument: { time },
currentSimulationScene: null,
currentSimulationClock: {
timeOfDayHours: 0,
dayCount: 0,
dayLengthMinutes: time.dayLengthMinutes
}
});
expect(state.resolvedTime?.dayPhase).toBe("night");
expect(state.resolvedWorld?.ambientLight).toEqual({
colorHex: "#101820",
intensity: 0.25
});
});
it("prefers runtime scene time settings when a runtime scene is available", () => {
const documentWorld = createDefaultWorldSettings();
const runtimeWorld = createDefaultWorldSettings();
const documentTime = createDefaultProjectTimeSettings();
const runtimeTime = createDefaultProjectTimeSettings();
documentTime.sunriseTimeOfDayHours = 6;
documentTime.sunsetTimeOfDayHours = 18;
runtimeTime.sunriseTimeOfDayHours = 10;
runtimeTime.sunsetTimeOfDayHours = 20;
const state = resolveViewportWorldState({
currentWorld: documentWorld,
currentDocument: { time: documentTime },
currentSimulationScene: {
time: runtimeTime,
world: runtimeWorld
},
currentSimulationClock: {
timeOfDayHours: 9,
dayCount: 0,
dayLengthMinutes: runtimeTime.dayLengthMinutes
}
});
expect(state.world).toBe(runtimeWorld);
expect(state.timeSettings).toBe(runtimeTime);
expect(state.resolvedTime?.dayPhase).toBe("night");
});
});