const { parseSize, parseStyle, parseLabelpos, parseFontweight, SIZE_MIN, SIZE_MAX } = require('../src/lib/validate'); describe('validate', () => { describe('parseSize', () => { it('should return valid size for valid input', () => { expect(parseSize('24')).toBe(24); expect(parseSize('8')).toBe(8); expect(parseSize('256')).toBe(256); expect(parseSize('100')).toBe(100); }); it('should return default (24) for NaN input', () => { expect(parseSize('abc')).toBe(24); expect(parseSize(undefined)).toBe(24); expect(parseSize(null)).toBe(24); expect(parseSize('')).toBe(24); }); it('should return default (24) for negative values', () => { expect(parseSize('-1')).toBe(24); expect(parseSize('-100')).toBe(24); }); it('should return default (24) for zero', () => { expect(parseSize('0')).toBe(24); }); it('should return default (24) for values above max', () => { expect(parseSize('257')).toBe(24); expect(parseSize('9999')).toBe(24); }); it('should clamp to size for values below min', () => { expect(parseSize('5')).toBe(24); expect(parseSize('7')).toBe(24); }); it('should export SIZE_MIN and SIZE_MAX', () => { expect(SIZE_MIN).toBe(8); expect(SIZE_MAX).toBe(256); }); }); describe('parseStyle', () => { it('should accept valid styles', () => { expect(parseStyle('rect')).toBe('rect'); expect(parseStyle('flat')).toBe('flat'); }); it('should return default (rect) for invalid styles', () => { expect(parseStyle('invalid')).toBe('rect'); expect(parseStyle('')).toBe('rect'); expect(parseStyle(undefined)).toBe('rect'); expect(parseStyle(null)).toBe('rect'); expect(parseStyle('RECT')).toBe('rect'); }); }); describe('parseLabelpos', () => { it('should accept valid positions', () => { expect(parseLabelpos('right')).toBe('right'); expect(parseLabelpos('left')).toBe('left'); expect(parseLabelpos('above')).toBe('above'); expect(parseLabelpos('below')).toBe('below'); }); it('should return default (right) for invalid positions', () => { expect(parseLabelpos('top')).toBe('right'); expect(parseLabelpos('center')).toBe('right'); expect(parseLabelpos('')).toBe('right'); expect(parseLabelpos(undefined)).toBe('right'); }); }); describe('parseFontweight', () => { it('should accept keyword weights', () => { expect(parseFontweight('normal')).toBe('normal'); expect(parseFontweight('bold')).toBe('bold'); expect(parseFontweight('lighter')).toBe('lighter'); expect(parseFontweight('bolder')).toBe('bolder'); }); it('should accept numeric weights (100-900)', () => { expect(parseFontweight('100')).toBe('100'); expect(parseFontweight('400')).toBe('400'); expect(parseFontweight('600')).toBe('600'); expect(parseFontweight('900')).toBe('900'); }); it('should return default (normal) for invalid weights', () => { expect(parseFontweight('ultra')).toBe('normal'); expect(parseFontweight('123')).toBe('normal'); expect(parseFontweight('')).toBe('normal'); expect(parseFontweight(undefined)).toBe('normal'); expect(parseFontweight('000')).toBe('normal'); }); }); });