Add tests for box brush face editing and update existing tests
This commit is contained in:
@@ -3,6 +3,7 @@ import { describe, expect, it } from "vitest";
|
||||
import { createBoxBrush } from "../../src/document/brushes";
|
||||
import { createEmptySceneDocument } from "../../src/document/scene-document";
|
||||
import { migrateSceneDocument } from "../../src/document/migrate-scene-document";
|
||||
import { STARTER_MATERIAL_LIBRARY } from "../../src/materials/starter-material-library";
|
||||
import { parseSceneDocumentJson, serializeSceneDocument } from "../../src/serialization/scene-document-json";
|
||||
|
||||
describe("scene document JSON", () => {
|
||||
@@ -37,12 +38,51 @@ describe("scene document JSON", () => {
|
||||
expect(parseSceneDocumentJson(serializeSceneDocument(document))).toEqual(document);
|
||||
});
|
||||
|
||||
it("round-trips per-face material and UV state", () => {
|
||||
const brush = createBoxBrush({
|
||||
id: "brush-face-room",
|
||||
center: {
|
||||
x: 2,
|
||||
y: 2,
|
||||
z: -1
|
||||
},
|
||||
size: {
|
||||
x: 6,
|
||||
y: 4,
|
||||
z: 8
|
||||
}
|
||||
});
|
||||
|
||||
brush.faces.posX.materialId = "starter-amber-grid";
|
||||
brush.faces.posX.uv = {
|
||||
offset: {
|
||||
x: 0.5,
|
||||
y: -0.25
|
||||
},
|
||||
scale: {
|
||||
x: 0.25,
|
||||
y: 0.5
|
||||
},
|
||||
rotationQuarterTurns: 3,
|
||||
flipU: true,
|
||||
flipV: true
|
||||
};
|
||||
|
||||
const document = {
|
||||
...createEmptySceneDocument({ name: "Face UV Scene" }),
|
||||
brushes: {
|
||||
[brush.id]: brush
|
||||
}
|
||||
};
|
||||
|
||||
expect(parseSceneDocumentJson(serializeSceneDocument(document))).toEqual(document);
|
||||
});
|
||||
|
||||
it("migrates the foundation schema to the current schema version", () => {
|
||||
const migratedDocument = migrateSceneDocument({
|
||||
version: 1,
|
||||
name: "Foundation Scene",
|
||||
world: createEmptySceneDocument().world,
|
||||
materials: {},
|
||||
textures: {},
|
||||
assets: {},
|
||||
brushes: {},
|
||||
@@ -51,9 +91,64 @@ describe("scene document JSON", () => {
|
||||
interactionLinks: {}
|
||||
});
|
||||
|
||||
expect(migratedDocument.version).toBe(2);
|
||||
expect(migratedDocument.version).toBe(3);
|
||||
expect(migratedDocument.brushes).toEqual({});
|
||||
expect(migratedDocument.name).toBe("Foundation Scene");
|
||||
expect(Object.keys(migratedDocument.materials)).toEqual(STARTER_MATERIAL_LIBRARY.map((material) => material.id));
|
||||
});
|
||||
|
||||
it("migrates slice 1.1 box brushes to explicit per-face UV state", () => {
|
||||
const migratedDocument = migrateSceneDocument({
|
||||
version: 2,
|
||||
name: "Legacy Brush Scene",
|
||||
world: createEmptySceneDocument().world,
|
||||
materials: {},
|
||||
textures: {},
|
||||
assets: {},
|
||||
brushes: {
|
||||
"brush-legacy": {
|
||||
id: "brush-legacy",
|
||||
kind: "box",
|
||||
center: {
|
||||
x: 0,
|
||||
y: 1,
|
||||
z: 0
|
||||
},
|
||||
size: {
|
||||
x: 4,
|
||||
y: 2,
|
||||
z: 6
|
||||
},
|
||||
faces: {
|
||||
posX: { materialId: null },
|
||||
negX: { materialId: null },
|
||||
posY: { materialId: null },
|
||||
negY: { materialId: null },
|
||||
posZ: { materialId: "starter-amber-grid" },
|
||||
negZ: { materialId: null }
|
||||
}
|
||||
}
|
||||
},
|
||||
modelInstances: {},
|
||||
entities: {},
|
||||
interactionLinks: {}
|
||||
});
|
||||
|
||||
expect(migratedDocument.version).toBe(3);
|
||||
expect(migratedDocument.brushes["brush-legacy"].faces.posZ.materialId).toBe("starter-amber-grid");
|
||||
expect(migratedDocument.brushes["brush-legacy"].faces.posZ.uv).toEqual({
|
||||
offset: {
|
||||
x: 0,
|
||||
y: 0
|
||||
},
|
||||
scale: {
|
||||
x: 1,
|
||||
y: 1
|
||||
},
|
||||
rotationQuarterTurns: 0,
|
||||
flipU: false,
|
||||
flipV: false
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects unsupported versions", () => {
|
||||
@@ -62,7 +157,6 @@ describe("scene document JSON", () => {
|
||||
version: 99,
|
||||
name: "Legacy",
|
||||
world: {},
|
||||
materials: {},
|
||||
textures: {},
|
||||
assets: {},
|
||||
brushes: {},
|
||||
|
||||
Reference in New Issue
Block a user