import { describe, expect, it } from "vitest"; import { mergeToolcraftInitialState } from "../composition/public-persistence"; import { getToolcraftCollectionItemControlAddress } from "./collection-control-address"; describe("Toolcraft persistence precedence", () => { it("lets explicit initial state override persisted state", () => { expect( mergeToolcraftInitialState( { canvas: { offset: { x: 10, y: 20 }, zoom: 80, }, panels: { controls: { offset: { x: 4, y: 8 } } }, values: { "generation.prompt": "Persisted" }, }, { canvas: { zoom: 95 }, panels: { controls: { collapsed: true } }, values: { "generation.prompt": "Explicit" }, }, ), ).toEqual({ canvas: { offset: { x: 10, y: 20 }, zoom: 95, }, panels: { controls: { collapsed: true, offset: { x: 4, y: 8 } } }, values: { "generation.prompt": "Explicit" }, }); }); it("drops persisted nested tracks when an explicit parent collection replaces them", () => { const nested = getToolcraftCollectionItemControlAddress( "storyboard.notes", 0, "opacity", ); const merged = mergeToolcraftInitialState( { timeline: { keyframeGroups: [ { controlId: nested, keyframes: [], label: "Opacity", }, ], }, values: { "storyboard.notes": [{ opacity: 60 }] }, }, { values: { "storyboard.notes": [{ opacity: 20 }] } }, ); expect(merged.timeline?.keyframeGroups).toEqual([]); expect(merged).not.toHaveProperty("explicitlyReplacedValueTargets"); // @ts-expect-error Persistence precedence metadata must not be public state. merged.explicitlyReplacedValueTargets; }); });