import { mediaSourceModule } from "../modules/built-ins/media-source/media-source-module"; import { describe, expect, it } from "vitest"; import { defineToolcraft } from "../schema/define-toolcraft"; import { createToolcraftState } from "./create-template-state"; import { parseToolcraftPersistenceSnapshot } from "../composition/public-persistence"; describe("Toolcraft persisted image geometry", () => { it("restores current image scene and source geometry independently", () => { const schema = defineToolcraft({ base: { identity: { id: "current-image-geometry-test", title: "Toolcraft fixture", }, canvas: { enabled: true, size: { height: 720, unit: "px", width: 1280 }, upload: true, }, panels: {}, persistence: { storage: "localStorage", }, }, modules: [mediaSourceModule()], }); const raw = JSON.stringify({ state: { mediaAssets: [ { assetKind: "image", fileName: "current.png", id: "current-image", layerId: "current-layer", lifecycle: "ready", mimeType: "image/png", position: { x: 75, y: -25 }, resourceRef: "media:image:current", size: { height: 180, unit: "px", width: 320 }, sourceSize: { height: 900, unit: "px", width: 1600 }, }, ], }, version: 2, }); const restored = createToolcraftState( schema, parseToolcraftPersistenceSnapshot(schema, raw), ); expect(restored.mediaAssets[0]).toMatchObject({ lifecycle: "restoring", position: { x: 75, y: -25 }, size: { height: 180, unit: "px", width: 320 }, sourceSize: { height: 900, unit: "px", width: 1600 }, }); }); });