Add tests for world environment settings and document migration
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createBoxBrush } from "../../src/document/brushes";
|
||||
import { SCENE_DOCUMENT_VERSION, createEmptySceneDocument } from "../../src/document/scene-document";
|
||||
import { FIRST_ROOM_POLISH_SCENE_DOCUMENT_VERSION, SCENE_DOCUMENT_VERSION, createEmptySceneDocument } from "../../src/document/scene-document";
|
||||
import { migrateSceneDocument } from "../../src/document/migrate-scene-document";
|
||||
import { createPlayerStartEntity } from "../../src/entities/entity-instances";
|
||||
import { STARTER_MATERIAL_LIBRARY } from "../../src/materials/starter-material-library";
|
||||
@@ -80,6 +80,30 @@ describe("scene document JSON", () => {
|
||||
expect(parseSceneDocumentJson(serializeSceneDocument(document))).toEqual(document);
|
||||
});
|
||||
|
||||
it("round-trips authored world environment settings", () => {
|
||||
const document = createEmptySceneDocument({ name: "World Environment Scene" });
|
||||
document.world.background = {
|
||||
mode: "verticalGradient",
|
||||
topColorHex: "#6a87ab",
|
||||
bottomColorHex: "#151b23"
|
||||
};
|
||||
document.world.ambientLight = {
|
||||
colorHex: "#d4e2ff",
|
||||
intensity: 0.45
|
||||
};
|
||||
document.world.sunLight = {
|
||||
colorHex: "#ffd8a6",
|
||||
intensity: 2.25,
|
||||
direction: {
|
||||
x: -1,
|
||||
y: 0.8,
|
||||
z: 0.2
|
||||
}
|
||||
};
|
||||
|
||||
expect(parseSceneDocumentJson(serializeSceneDocument(document))).toEqual(document);
|
||||
});
|
||||
|
||||
it("round-trips a document containing an authored PlayerStart entity", () => {
|
||||
const playerStart = createPlayerStartEntity({
|
||||
id: "entity-player-start-main",
|
||||
@@ -248,6 +272,27 @@ describe("scene document JSON", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("migrates slice 1.4 documents to the world-environment schema without changing authored solid backgrounds", () => {
|
||||
const migratedDocument = migrateSceneDocument({
|
||||
version: FIRST_ROOM_POLISH_SCENE_DOCUMENT_VERSION,
|
||||
name: "First Room Scene",
|
||||
world: createEmptySceneDocument().world,
|
||||
materials: createEmptySceneDocument().materials,
|
||||
textures: {},
|
||||
assets: {},
|
||||
brushes: {},
|
||||
modelInstances: {},
|
||||
entities: {},
|
||||
interactionLinks: {}
|
||||
});
|
||||
|
||||
expect(migratedDocument.version).toBe(SCENE_DOCUMENT_VERSION);
|
||||
expect(migratedDocument.world.background).toEqual({
|
||||
mode: "solid",
|
||||
colorHex: "#2f3947"
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects unsupported versions", () => {
|
||||
expect(() =>
|
||||
migrateSceneDocument({
|
||||
|
||||
Reference in New Issue
Block a user