import { describe, expect, it } from "vitest"; import { defineToolcraft } from "../schema/define-toolcraft"; import { createToolcraftState } from "../state/create-template-state"; import { createToolcraftArtifactFrameState } from "./artifact-frame-state"; describe("createToolcraftArtifactFrameState", () => { it("evaluates keyframed values without mutating the base snapshot", () => { const state = createToolcraftState( defineToolcraft({ canvas: { enabled: true }, panels: {} }), { timeline: { currentTimeSeconds: 0, isPlaying: true, keyframeGroups: [ { controlId: "shape.opacity", label: "Opacity", keyframes: [ { controlId: "shape.opacity", controlLabel: "Opacity", id: "a", timeSeconds: 0, value: 0, valueLabel: "0", }, { controlId: "shape.opacity", controlLabel: "Opacity", id: "b", timeSeconds: 1, value: 1, valueLabel: "1", }, ], }, ], }, values: { "shape.opacity": 0 }, }, ); const frameState = createToolcraftArtifactFrameState(state, 0.5); expect(frameState).not.toBe(state); expect(frameState.timeline.currentTimeSeconds).toBe(0.5); expect(frameState.timeline.isPlaying).toBe(false); expect(frameState.values["shape.opacity"]).toBeCloseTo(0.5, 5); expect(state.timeline.currentTimeSeconds).toBe(0); expect(state.timeline.isPlaying).toBe(true); expect(state.values["shape.opacity"]).toBe(0); }); });