import { describe, it, expect } from 'vitest' import { getFieldRegistryEntry, getTypeDefault } from '../../composables/formBuilderRegistry' import type { FormFieldType } from '../../types/form-builder' describe('formBuilderRegistry', () => { describe('getFieldRegistryEntry', () => { it('should return an entry for every supported field type', () => { const types: FormFieldType[] = [ 'text', 'email', 'password', 'tel', 'url', 'search', 'number', 'textarea', 'select', 'multiselect', 'checkbox', 'toggle', 'radio', 'slider', 'tags', 'date', 'time', 'datetime', 'file', 'path', 'formula', 'sequence', 'molecule', 'concentration', 'unit', ] for (const type of types) { const entry = getFieldRegistryEntry(type) expect(entry, `missing registry entry for type "${type}"`).toBeDefined() expect(entry.component).toBeDefined() expect(typeof entry.vModel).toBe('boolean') expect(typeof entry.defaults).toBe('object') } }) it('should return correct component for text type', () => { const entry = getFieldRegistryEntry('text') expect(entry.vModel).toBe(true) expect(entry.defaults).toEqual({ type: 'text' }) }) it('should return correct defaults for email type', () => { const entry = getFieldRegistryEntry('email') expect(entry.defaults).toEqual({ type: 'email' }) expect(entry.vModel).toBe(true) }) it('should return correct defaults for password type', () => { const entry = getFieldRegistryEntry('password') expect(entry.defaults).toEqual({ type: 'password' }) }) it('should return correct defaults for tel type', () => { const entry = getFieldRegistryEntry('tel') expect(entry.defaults).toEqual({ type: 'tel' }) }) it('should return correct defaults for url type', () => { const entry = getFieldRegistryEntry('url') expect(entry.defaults).toEqual({ type: 'url' }) }) it('should return correct defaults for search type', () => { const entry = getFieldRegistryEntry('search') expect(entry.defaults).toEqual({ type: 'search' }) }) it('should have vModel false for file type', () => { const entry = getFieldRegistryEntry('file') expect(entry.vModel).toBe(false) }) it('should bind generated path inputs with v-model', () => { expect(getFieldRegistryEntry('path').vModel).toBe(true) }) it('should have vModel true for all non-file types', () => { const vModelTypes: FormFieldType[] = [ 'text', 'email', 'password', 'tel', 'url', 'search', 'number', 'textarea', 'select', 'multiselect', 'checkbox', 'toggle', 'radio', 'slider', 'tags', 'date', 'time', 'datetime', 'formula', 'sequence', 'molecule', 'concentration', 'unit', ] for (const type of vModelTypes) { const entry = getFieldRegistryEntry(type) expect(entry.vModel, `vModel should be true for "${type}"`).toBe(true) } }) it('should return empty defaults object for number type', () => { const entry = getFieldRegistryEntry('number') expect(entry.defaults).toEqual({}) }) it('should return empty defaults object for checkbox type', () => { const entry = getFieldRegistryEntry('checkbox') expect(entry.defaults).toEqual({}) }) }) describe('getTypeDefault', () => { it('should return false for checkbox', () => { expect(getTypeDefault('checkbox')).toBe(false) }) it('should return false for toggle', () => { expect(getTypeDefault('toggle')).toBe(false) }) it('should return undefined for number', () => { expect(getTypeDefault('number')).toBeUndefined() }) it('should return undefined for slider', () => { expect(getTypeDefault('slider')).toBeUndefined() }) it('should return empty array for multiselect', () => { expect(getTypeDefault('multiselect')).toEqual([]) }) it('should return empty array for tags', () => { expect(getTypeDefault('tags')).toEqual([]) }) it('should return empty string for text', () => { expect(getTypeDefault('text')).toBe('') }) it('should return empty string for email', () => { expect(getTypeDefault('email')).toBe('') }) it('should return empty string for password', () => { expect(getTypeDefault('password')).toBe('') }) it('should return empty string for textarea', () => { expect(getTypeDefault('textarea')).toBe('') }) it('should return empty string for select', () => { expect(getTypeDefault('select')).toBe('') }) it('should return empty string for date', () => { expect(getTypeDefault('date')).toBe('') }) it('should return empty string for time', () => { expect(getTypeDefault('time')).toBe('') }) it('should return empty string for datetime', () => { expect(getTypeDefault('datetime')).toBe('') }) it('should return empty string for file', () => { expect(getTypeDefault('file')).toBe('') }) it('should return empty string for radio', () => { expect(getTypeDefault('radio')).toBe('') }) it('should return empty string for formula', () => { expect(getTypeDefault('formula')).toBe('') }) it('should return empty string for sequence', () => { expect(getTypeDefault('sequence')).toBe('') }) it('should return empty string for molecule', () => { expect(getTypeDefault('molecule')).toBe('') }) it('should return empty string for concentration', () => { expect(getTypeDefault('concentration')).toBe('') }) it('should return empty string for unit', () => { expect(getTypeDefault('unit')).toBe('') }) it('should return a new array instance each call for multiselect', () => { const a = getTypeDefault('multiselect') const b = getTypeDefault('multiselect') expect(a).toEqual(b) // Each call should return a distinct array expect(a).not.toBe(b) }) it('should return a new array instance each call for tags', () => { const a = getTypeDefault('tags') const b = getTypeDefault('tags') expect(a).not.toBe(b) }) }) })