import { describe, expect, it } from "vitest"; import { DEFAULT_SKETCHUP_PREFS, SKETCHUP_TOOLS, mapToolToCursorMode, normalizeSketchUpPrefs, parseVcbInput, } from "@/lib/sketchupInterface"; describe("SketchUp Classic Interface — VCB Parser, Prefs & Tool Mapping", () => { it("parses linear/polar array repeat multipliers (*5, x5, 5x, 5*)", () => { expect(parseVcbInput("*5")).toEqual({ kind: "array-multiply", count: 5 }); expect(parseVcbInput("x8")).toEqual({ kind: "array-multiply", count: 8 }); expect(parseVcbInput("4x")).toEqual({ kind: "array-multiply", count: 4 }); expect(parseVcbInput("3*")).toEqual({ kind: "array-multiply", count: 3 }); }); it("parses equidistant array division (/N)", () => { expect(parseVcbInput("/4")).toEqual({ kind: "array-divide", count: 4 }); expect(parseVcbInput("/ 12")).toEqual({ kind: "array-divide", count: 12 }); expect(parseVcbInput("/0")).toEqual({ kind: "invalid", raw: "/0" }); }); it("parses 2D and 3D dimensions with semicolons, x, and comma+space", () => { expect(parseVcbInput("100;50")).toEqual({ kind: "dimensions-2d", width: 100, depth: 50, }); expect(parseVcbInput("100,5;60,25")).toEqual({ kind: "dimensions-2d", width: 100.5, depth: 60.25, }); expect(parseVcbInput("120;80;35")).toEqual({ kind: "dimensions-3d", width: 120, depth: 80, height: 35, }); expect(parseVcbInput("45x90x15")).toEqual({ kind: "dimensions-3d", width: 45, depth: 90, height: 15, }); expect(parseVcbInput("100, 60")).toEqual({ kind: "dimensions-2d", width: 100, depth: 60, }); }); it("distinguishes decimal commas (12,5) from comma 2D pairs based on tool context", () => { expect(parseVcbInput("12,5", { prefer2dDimensions: false })).toEqual({ kind: "single-number", value: 12.5, }); expect(parseVcbInput("100,60", { prefer2dDimensions: true })).toEqual({ kind: "dimensions-2d", width: 100, depth: 60, }); }); it("parses angles and length unit conversions (mm, cm, m)", () => { expect(parseVcbInput("45°")).toEqual({ kind: "angle", degrees: 45 }); expect(parseVcbInput("-22.5deg")).toEqual({ kind: "angle", degrees: -22.5 }); expect(parseVcbInput("2.5m")).toEqual({ kind: "single-number", value: 2500 }); expect(parseVcbInput("50cm")).toEqual({ kind: "single-number", value: 500 }); expect(parseVcbInput("-15mm")).toEqual({ kind: "single-number", value: -15 }); }); it("handles empty and invalid inputs cleanly", () => { expect(parseVcbInput(" ")).toEqual({ kind: "empty" }); expect(parseVcbInput("abc")).toEqual({ kind: "invalid", raw: "abc" }); expect(parseVcbInput("10;0")).toEqual({ kind: "invalid", raw: "10;0" }); }); it("maps SketchUp tool IDs to viewport cursor modes", () => { expect(mapToolToCursorMode("orbit")).toBe("orbit"); expect(mapToolToCursorMode("pan")).toBe("pan"); expect(mapToolToCursorMode("zoom")).toBe("zoom"); expect(mapToolToCursorMode("eraser")).toBe("eraser"); expect(mapToolToCursorMode("rectangle")).toBe("rectangle"); expect(mapToolToCursorMode("circle")).toBe("circle"); expect(mapToolToCursorMode("polygon")).toBe("polygon"); expect(mapToolToCursorMode("push-pull")).toBe("push-pull"); expect(mapToolToCursorMode("move")).toBe("move"); expect(mapToolToCursorMode("zoom-extents")).toBe("select"); expect(Object.keys(SKETCHUP_TOOLS).length).toBeGreaterThanOrEqual(25); }); it("normalizes user workspace prefs safely with defaults on corrupt data", () => { expect(normalizeSketchUpPrefs(null)).toEqual(DEFAULT_SKETCHUP_PREFS); expect(normalizeSketchUpPrefs("invalid")).toEqual(DEFAULT_SKETCHUP_PREFS); const normalized = normalizeSketchUpPrefs({ layoutMode: "compact-modern", keymapProfile: "snapcad-standard", showLeftToolset: false, showDefaultTray: true, showSecondaryRibbon: true, skyGroundEnabled: true, backEdgesEnabled: true, openTraySections: ["styles", "unknown-section", "components", "styles"], }); expect(normalized).toEqual({ layoutMode: "compact-modern", keymapProfile: "snapcad-standard", showLeftToolset: false, showDefaultTray: true, showSecondaryRibbon: true, skyGroundEnabled: true, backEdgesEnabled: true, openTraySections: ["styles", "components"], }); }); });