import { describe, expect, it } from "vitest"; import { imageExportModule } from "../modules/built-ins/image-export/image-export-module"; import { timelineModule } from "../modules/built-ins/timeline/timeline-module"; import { defineToolcraft } from "./define-toolcraft"; import type { ToolcraftProductDefinition } from "./product-base"; import { extractToolcraftRuntimeSetupBackground } from "./runtime-setup-background"; function createBackgroundSchema(): ToolcraftProductDefinition { return { base: { canvas: { enabled: true, renderScale: true, size: { height: 1350, unit: "px", width: 1080 }, sizing: { mode: "editable-output" }, }, identity: { id: "setup-background-test", title: "Controls" }, panels: { controls: { sections: [ { controls: { includeBackground: { applicability: { mode: "always" as const }, defaultValue: true, description: "Controls preview and PNG background visibility while video keeps the background.", label: "Include", target: "export.includeBackground", type: "switch", }, background: { applicability: { mode: "always" as const }, defaultValue: "#0F0F0F", label: false, target: "appearance.background", type: "color", }, }, id: "background", layoutGroups: [ { columns: 2, controls: ["includeBackground", "background"], layout: "inline", }, ], title: "Background", }, ], title: "Controls", }, }, }, modules: [imageExportModule(), timelineModule({ mode: "playback" })], }; } describe("defineToolcraft runtime setup background controls", () => { it("moves the managed background pair into Setup and places Timeline last", () => { const app = defineToolcraft(createBackgroundSchema()); const sections = app.panels.controls?.sections ?? []; const setupSection = sections[1]; expect(sections.map((section) => section.title)).toEqual([ "Defaults", "Settings", "Image Export", "Export", ]); expect(Object.keys(setupSection?.controls ?? {})).toEqual([ "includeBackground", "infinityCanvas", "background", "workspaceBackground", "canvasAspectRatio", "canvasWidth", "canvasHeight", "canvasRenderScale", "timelineExtended", ]); expect(setupSection?.controls.includeBackground).toMatchObject({ applicability: { mode: "always" as const }, defaultValue: true, label: "Background", target: "export.includeBackground", type: "switch", }); expect(setupSection?.controls.background).toMatchObject({ applicability: { mode: "always" as const }, defaultValue: "#0F0F0F", label: "Background color", target: "appearance.background", type: "color", }); expect(setupSection?.controls.infinityCanvas).toMatchObject({ applicability: { mode: "always" as const }, disabledWhen: { equals: false, target: "export.includeBackground", }, target: "canvas.infinity", type: "switch", }); expect(setupSection?.layoutGroups).toEqual([ { columns: 2, controls: ["includeBackground", "infinityCanvas"], layout: "inline", }, { columns: 2, controls: ["background", "workspaceBackground"], layout: "inline", }, { columns: 2, controls: ["canvasWidth", "canvasHeight"], layout: "inline", }, ]); }); it("extracts the same background facts repeatedly without mutating authored sections", () => { const sections = createBackgroundSchema().base.panels.controls!.sections; const before = JSON.stringify(sections); const first = extractToolcraftRuntimeSetupBackground({ sections }); const second = extractToolcraftRuntimeSetupBackground({ sections }); expect(second).toEqual(first); expect(JSON.stringify(sections)).toBe(before); }); });