import { describe, expect, it } from "vitest"; import { defineToolcraft } from "../../schema/define-toolcraft"; import { createToolcraftState } from "../../state/create-template-state"; import { getToolcraftOrientationControlEntries, resolveToolcraftOrientationControl, } from "./orientation-gizmo-selection"; const pose = { position: [0, 0, 5], up: [0, 1, 0] } as const; describe("Toolcraft orientation gizmo selection", () => { it("selects the one visible declaration from mutually exclusive controls", () => { const schema = defineToolcraft({ canvas: { enabled: true }, panels: { controls: { sections: [ { controls: { first: { defaultValue: pose, keyframeable: false, label: false, target: "first.orbit", type: "orientationGizmo", visibleWhen: { equals: "first", target: "model.active" }, }, mode: { defaultValue: "first", label: "Model", options: [ { label: "First", value: "first" }, { label: "Second", value: "second" }, ], target: "model.active", type: "select", }, second: { defaultValue: pose, keyframeable: false, label: false, target: "second.orbit", type: "orientationGizmo", visibleWhen: { equals: "second", target: "model.active" }, }, }, title: "Model", }, ], title: "Controls", }, }, }); const entries = getToolcraftOrientationControlEntries( schema.panels.controls?.sections ?? [], ); expect( resolveToolcraftOrientationControl(createToolcraftState(schema), entries) ?.id, ).toBe("first"); expect( resolveToolcraftOrientationControl( createToolcraftState(schema, { values: { "model.active": "second" } }), entries, )?.id, ).toBe("second"); }); it("rejects an ambiguous runtime state instead of choosing declaration order", () => { const schema = defineToolcraft({ canvas: { enabled: true }, panels: { controls: { sections: [ { controls: { first: { defaultValue: pose, keyframeable: false, label: false, target: "first.orbit", type: "orientationGizmo", }, modelScale: { defaultValue: 1, label: "Scale", target: "model.scale", type: "slider", }, second: { defaultValue: pose, keyframeable: false, label: false, target: "second.orbit", type: "orientationGizmo", }, }, title: "Model", }, ], title: "Controls", }, }, }); const entries = getToolcraftOrientationControlEntries( schema.panels.controls?.sections ?? [], ); expect(() => resolveToolcraftOrientationControl(createToolcraftState(schema), entries), ).toThrow(/Multiple orientationGizmo controls are visible.*first.*second/); }); });