|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { |
| 3 | + CanvasSnapSettingsSchema, |
| 4 | + CanvasZoomSettingsSchema, |
| 5 | + ElementPaletteItemSchema, |
| 6 | + InterfaceBuilderConfigSchema, |
| 7 | + type InterfaceBuilderConfig, |
| 8 | +} from './interface-builder.zod'; |
| 9 | + |
| 10 | +// --------------------------------------------------------------------------- |
| 11 | +// CanvasSnapSettingsSchema |
| 12 | +// --------------------------------------------------------------------------- |
| 13 | +describe('CanvasSnapSettingsSchema', () => { |
| 14 | + it('should accept empty config with defaults', () => { |
| 15 | + const settings = CanvasSnapSettingsSchema.parse({}); |
| 16 | + expect(settings.enabled).toBe(true); |
| 17 | + expect(settings.gridSize).toBe(8); |
| 18 | + expect(settings.showGrid).toBe(true); |
| 19 | + expect(settings.showGuides).toBe(true); |
| 20 | + }); |
| 21 | + |
| 22 | + it('should accept custom snap settings', () => { |
| 23 | + const settings = CanvasSnapSettingsSchema.parse({ |
| 24 | + enabled: false, |
| 25 | + gridSize: 16, |
| 26 | + showGrid: false, |
| 27 | + showGuides: false, |
| 28 | + }); |
| 29 | + expect(settings.enabled).toBe(false); |
| 30 | + expect(settings.gridSize).toBe(16); |
| 31 | + }); |
| 32 | +}); |
| 33 | + |
| 34 | +// --------------------------------------------------------------------------- |
| 35 | +// CanvasZoomSettingsSchema |
| 36 | +// --------------------------------------------------------------------------- |
| 37 | +describe('CanvasZoomSettingsSchema', () => { |
| 38 | + it('should accept empty config with defaults', () => { |
| 39 | + const settings = CanvasZoomSettingsSchema.parse({}); |
| 40 | + expect(settings.min).toBe(0.25); |
| 41 | + expect(settings.max).toBe(3); |
| 42 | + expect(settings.default).toBe(1); |
| 43 | + expect(settings.step).toBe(0.1); |
| 44 | + }); |
| 45 | + |
| 46 | + it('should accept custom zoom settings', () => { |
| 47 | + const settings = CanvasZoomSettingsSchema.parse({ |
| 48 | + min: 0.5, |
| 49 | + max: 5, |
| 50 | + default: 1.5, |
| 51 | + step: 0.25, |
| 52 | + }); |
| 53 | + expect(settings.min).toBe(0.5); |
| 54 | + expect(settings.max).toBe(5); |
| 55 | + }); |
| 56 | +}); |
| 57 | + |
| 58 | +// --------------------------------------------------------------------------- |
| 59 | +// ElementPaletteItemSchema |
| 60 | +// --------------------------------------------------------------------------- |
| 61 | +describe('ElementPaletteItemSchema', () => { |
| 62 | + it('should accept valid palette item', () => { |
| 63 | + const item = ElementPaletteItemSchema.parse({ |
| 64 | + type: 'element:button', |
| 65 | + label: 'Button', |
| 66 | + category: 'interactive', |
| 67 | + }); |
| 68 | + expect(item.type).toBe('element:button'); |
| 69 | + expect(item.defaultWidth).toBe(4); |
| 70 | + expect(item.defaultHeight).toBe(2); |
| 71 | + }); |
| 72 | + |
| 73 | + it('should accept all category values', () => { |
| 74 | + const categories = ['content', 'interactive', 'data', 'layout'] as const; |
| 75 | + categories.forEach(category => { |
| 76 | + expect(() => ElementPaletteItemSchema.parse({ |
| 77 | + type: 'element:text', |
| 78 | + label: 'Text', |
| 79 | + category, |
| 80 | + })).not.toThrow(); |
| 81 | + }); |
| 82 | + }); |
| 83 | + |
| 84 | + it('should reject without required fields', () => { |
| 85 | + expect(() => ElementPaletteItemSchema.parse({})).toThrow(); |
| 86 | + expect(() => ElementPaletteItemSchema.parse({ type: 'element:text' })).toThrow(); |
| 87 | + }); |
| 88 | +}); |
| 89 | + |
| 90 | +// --------------------------------------------------------------------------- |
| 91 | +// InterfaceBuilderConfigSchema |
| 92 | +// --------------------------------------------------------------------------- |
| 93 | +describe('InterfaceBuilderConfigSchema', () => { |
| 94 | + it('should accept empty config with defaults', () => { |
| 95 | + const config: InterfaceBuilderConfig = InterfaceBuilderConfigSchema.parse({}); |
| 96 | + expect(config.showLayerPanel).toBe(true); |
| 97 | + expect(config.showPropertyPanel).toBe(true); |
| 98 | + expect(config.undoLimit).toBe(50); |
| 99 | + }); |
| 100 | + |
| 101 | + it('should accept full builder config', () => { |
| 102 | + const config = InterfaceBuilderConfigSchema.parse({ |
| 103 | + snap: { enabled: true, gridSize: 4 }, |
| 104 | + zoom: { min: 0.5, max: 2 }, |
| 105 | + palette: [ |
| 106 | + { type: 'element:button', label: 'Button', category: 'interactive' }, |
| 107 | + { type: 'element:text', label: 'Text', category: 'content' }, |
| 108 | + ], |
| 109 | + showLayerPanel: false, |
| 110 | + showPropertyPanel: true, |
| 111 | + undoLimit: 100, |
| 112 | + }); |
| 113 | + |
| 114 | + expect(config.snap?.gridSize).toBe(4); |
| 115 | + expect(config.palette).toHaveLength(2); |
| 116 | + expect(config.undoLimit).toBe(100); |
| 117 | + }); |
| 118 | +}); |
0 commit comments