From 002215fd3cee3fa6c0df4a069befc8c71dc5681b Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Sat, 11 Apr 2026 04:18:23 +0200 Subject: [PATCH] Add unit test for project document JSON serialization --- .../project-document-json.test.ts | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 tests/serialization/project-document-json.test.ts diff --git a/tests/serialization/project-document-json.test.ts b/tests/serialization/project-document-json.test.ts new file mode 100644 index 00000000..28ca1f89 --- /dev/null +++ b/tests/serialization/project-document-json.test.ts @@ -0,0 +1,69 @@ +import { describe, expect, it } from "vitest"; + +import { + MULTI_SCENE_FOUNDATION_SCENE_DOCUMENT_VERSION, + SCENE_DOCUMENT_VERSION, + createDefaultSceneLoadingScreenSettings, + createEmptyProjectDocument, + createEmptyProjectScene +} from "../../src/document/scene-document"; +import { + parseProjectDocumentJson, + serializeProjectDocument +} from "../../src/serialization/scene-document-json"; + +describe("project document JSON", () => { + it("round-trips authored scene loading overlay settings", () => { + const document = { + ...createEmptyProjectDocument({ sceneName: "Entry" }), + activeSceneId: "scene-cellar", + scenes: { + "scene-main": createEmptyProjectScene({ + id: "scene-main", + name: "Entry" + }), + "scene-cellar": createEmptyProjectScene({ + id: "scene-cellar", + name: "Cellar", + loadingScreen: { + colorHex: "#233041", + headline: "Descending", + description: "Dust and echoes settle before the next room appears." + } + }) + } + }; + + const serializedDocument = serializeProjectDocument(document); + + expect(parseProjectDocumentJson(serializedDocument)).toEqual(document); + }); + + it("migrates v22 project documents by defaulting missing scene loading overlays", () => { + const legacyScene = createEmptyProjectScene({ + id: "scene-main", + name: "Legacy Entry" + }); + const { loadingScreen: _loadingScreen, ...legacySceneWithoutLoadingScreen } = + legacyScene; + void _loadingScreen; + + const migratedDocument = parseProjectDocumentJson( + JSON.stringify({ + version: MULTI_SCENE_FOUNDATION_SCENE_DOCUMENT_VERSION, + activeSceneId: "scene-main", + scenes: { + "scene-main": legacySceneWithoutLoadingScreen + }, + materials: createEmptyProjectDocument().materials, + textures: {}, + assets: {} + }) + ); + + expect(migratedDocument.version).toBe(SCENE_DOCUMENT_VERSION); + expect(migratedDocument.scenes["scene-main"]?.loadingScreen).toEqual( + createDefaultSceneLoadingScreenSettings() + ); + }); +});