Update tests for project document serialization and add project name handling

This commit is contained in:
2026-04-11 13:26:46 +02:00
parent 8506b235db
commit 811b51bd6a
4 changed files with 83 additions and 4 deletions

View File

@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
import { createBoxBrush } from "../../src/document/brushes";
import {
DEFAULT_PROJECT_NAME,
SCENE_DOCUMENT_VERSION,
createEmptyProjectDocument,
createEmptyProjectScene,
@@ -196,7 +197,10 @@ describe("local draft storage", () => {
it("stores and restores all project scenes in autosave drafts", () => {
const storage = new MemoryStorage();
const document = {
...createEmptyProjectDocument({ sceneName: "Entry" }),
...createEmptyProjectDocument({
name: "Castle Campaign",
sceneName: "Entry"
}),
activeSceneId: "scene-hall",
scenes: {
"scene-main": createEmptyProjectScene({
@@ -228,6 +232,7 @@ describe("local draft storage", () => {
return;
}
expect(result.document.name).toBe("Castle Campaign");
expect(result.document.activeSceneId).toBe("scene-hall");
expect(Object.keys(result.document.scenes)).toEqual([
"scene-main",
@@ -255,6 +260,7 @@ describe("local draft storage", () => {
return;
}
expect(result.document.name).toBe(DEFAULT_PROJECT_NAME);
expect(result.document.scenes[result.document.activeSceneId]?.name).toBe(
"Legacy Draft"
);

View File

@@ -1,6 +1,8 @@
import { describe, expect, it } from "vitest";
import {
DEFAULT_PROJECT_NAME,
PLAYER_START_GAMEPAD_CAMERA_LOOK_SCENE_DOCUMENT_VERSION,
RUNNER_LOADING_SCREEN_SCENE_DOCUMENT_VERSION,
SCENE_DOCUMENT_VERSION,
createEmptyProjectDocument,
@@ -16,7 +18,7 @@ import {
} from "../../src/serialization/scene-document-json";
describe("project document JSON", () => {
it("round-trips authored scene loading overlay settings", () => {
it("round-trips the project name and authored scene loading overlay settings", () => {
const cellarEntry = createSceneEntryEntity({
id: "entity-scene-entry-cellar-stairs",
position: {
@@ -37,7 +39,10 @@ describe("project document JSON", () => {
targetEntryEntityId: cellarEntry.id
});
const document = {
...createEmptyProjectDocument({ sceneName: "Entry" }),
...createEmptyProjectDocument({
name: "Castle Project",
sceneName: "Entry"
}),
activeSceneId: "scene-cellar",
scenes: {
"scene-main": createEmptyProjectScene({
@@ -63,6 +68,28 @@ describe("project document JSON", () => {
expect(parseProjectDocumentJson(serializedDocument)).toEqual(document);
});
it("migrates pre-project-name multi-scene documents to Untitled Project", () => {
const migratedDocument = parseProjectDocumentJson(
JSON.stringify({
version: PLAYER_START_GAMEPAD_CAMERA_LOOK_SCENE_DOCUMENT_VERSION,
activeSceneId: "scene-main",
scenes: {
"scene-main": createEmptyProjectScene({
id: "scene-main",
name: "Legacy Entry"
})
},
materials: createEmptyProjectDocument().materials,
textures: {},
assets: {}
})
);
expect(migratedDocument.version).toBe(SCENE_DOCUMENT_VERSION);
expect(migratedDocument.name).toBe(DEFAULT_PROJECT_NAME);
expect(migratedDocument.scenes["scene-main"]?.name).toBe("Legacy Entry");
});
it("migrates v23 project documents without Scene Entry and Scene Exit entities", () => {
const legacyScene = createEmptyProjectScene({
id: "scene-main",

View File

@@ -136,6 +136,7 @@ describe("project package serialization", () => {
...createProjectDocument(
createEmptySceneDocument({ name: "Portable Entry" })
),
name: "Portable Campaign",
activeSceneId: "scene-dungeon",
scenes: {
"scene-main": createEmptyProjectScene({