|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | +import { getControlByMemberType } from './control'; |
| 3 | +import { extendMember } from './info_extend'; |
| 4 | + |
| 5 | +describe('control.js test', function () { |
| 6 | + describe('getControlByMemberType', function () { |
| 7 | + it('uses the boolean control for a plain boolean', function () { |
| 8 | + expect(getControlByMemberType('boolean')).toBe('boolean'); |
| 9 | + }); |
| 10 | + |
| 11 | + it('uses the boolean control for a nullable boolean enum', function () { |
| 12 | + expect(getControlByMemberType('boolean', { values: ['null', true, false] })).toBe('boolean'); |
| 13 | + }); |
| 14 | + |
| 15 | + it('uses the segmented control for the mixed boolean enum', function () { |
| 16 | + expect(getControlByMemberType('boolean', { values: [true, false, 'mixed'] })).toBe('segmented'); |
| 17 | + }); |
| 18 | + |
| 19 | + it('uses the segmented control for short string values', function () { |
| 20 | + expect(getControlByMemberType('string', { values: ['sm', 'md', 'lg'] })).toBe('segmented'); |
| 21 | + }); |
| 22 | + |
| 23 | + it('uses the selection control for longer string values', function () { |
| 24 | + expect(getControlByMemberType('string', { values: ['label', 'count'] })).toBe('selection'); |
| 25 | + }); |
| 26 | + }); |
| 27 | + |
| 28 | + describe('docgen value normalization', function () { |
| 29 | + it('normalizes a mixed boolean enum to runtime values', function () { |
| 30 | + const member = { type: { name: 'boolean|string' }, values: ['true', 'false', '\'mixed\''] }; |
| 31 | + |
| 32 | + extendMember(member); |
| 33 | + |
| 34 | + expect(member.values).toEqual([true, false, 'mixed']); |
| 35 | + }); |
| 36 | + |
| 37 | + it('leaves non-boolean string enums untouched', function () { |
| 38 | + const member = { type: { name: 'string' }, values: ['\'body\'', '\'parent\''] }; |
| 39 | + |
| 40 | + extendMember(member); |
| 41 | + |
| 42 | + expect(member.values).toEqual(['\'body\'', '\'parent\'']); |
| 43 | + }); |
| 44 | + }); |
| 45 | +}); |
0 commit comments