From 3ca210961cc503d9437656567e5bb157f28da4c7 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Wed, 22 Apr 2026 14:04:13 +0200 Subject: [PATCH] auto-git: [change] tests/unit/world-background-renderer.test.ts --- tests/unit/world-background-renderer.test.ts | 93 +++++++++++++++++++- 1 file changed, 92 insertions(+), 1 deletion(-) diff --git a/tests/unit/world-background-renderer.test.ts b/tests/unit/world-background-renderer.test.ts index 57d4c3b2..4647bcd9 100644 --- a/tests/unit/world-background-renderer.test.ts +++ b/tests/unit/world-background-renderer.test.ts @@ -2,7 +2,10 @@ import { Texture } from "three"; import { describe, expect, it, vi } from "vitest"; import { createDefaultWorldSettings } from "../../src/document/world-settings"; -import { resolveWorldEnvironmentState } from "../../src/rendering/world-background-renderer"; +import { + resolveWorldCelestialBodiesState, + resolveWorldEnvironmentState +} from "../../src/rendering/world-background-renderer"; describe("resolveWorldEnvironmentState", () => { it("keeps the authored day environment when no night overlay is active", () => { @@ -125,3 +128,91 @@ describe("resolveWorldEnvironmentState", () => { }); }); }); + +describe("resolveWorldCelestialBodiesState", () => { + it("returns aligned sun and moon overlay state when enabled", () => { + const world = createDefaultWorldSettings(); + world.showCelestialBodies = true; + + const celestialBodies = resolveWorldCelestialBodiesState( + world.showCelestialBodies, + { + colorHex: "#ffddaa", + intensity: 1.8, + direction: { + x: 0.2, + y: 0.9, + z: -0.1 + } + }, + { + colorHex: "#c7d8ff", + intensity: 0.28, + direction: { + x: -0.2, + y: 0.45, + z: 0.87 + } + } + ); + + expect(celestialBodies.sun).toMatchObject({ + colorHex: "#ffddaa", + intensity: 1.8, + size: 28 + }); + expect(celestialBodies.moon).toMatchObject({ + colorHex: "#c7d8ff", + intensity: 0.28, + size: 20 + }); + expect(celestialBodies.sun?.direction.y ?? 0).toBeGreaterThan(0); + expect(celestialBodies.moon?.direction.y ?? 0).toBeGreaterThan(0); + }); + + it("hides celestial bodies when the feature is disabled or the light sits below the horizon", () => { + const enabledButBelowHorizon = resolveWorldCelestialBodiesState( + true, + { + colorHex: "#ffddaa", + intensity: 1.8, + direction: { + x: 0.2, + y: -0.25, + z: -0.1 + } + }, + { + colorHex: "#c7d8ff", + intensity: 0.28, + direction: { + x: -0.2, + y: -0.45, + z: 0.87 + } + } + ); + const disabled = resolveWorldCelestialBodiesState( + false, + { + colorHex: "#ffddaa", + intensity: 1.8, + direction: { + x: 0.2, + y: 0.9, + z: -0.1 + } + }, + null + ); + + expect(enabledButBelowHorizon).toEqual({ + sun: null, + moon: null + }); + expect(disabled).toEqual({ + sun: null, + moon: null + }); + }); +});