|
| 1 | +import { listComponents, getComponentProps, getComponentExample } from '../src/tools/components'; |
| 2 | + |
| 3 | +describe('listComponents', () => { |
| 4 | + it('returns all components', () => { |
| 5 | + const result = listComponents(); |
| 6 | + expect(result.length).toBeGreaterThan(80); |
| 7 | + expect(result[0]).toHaveProperty('name'); |
| 8 | + expect(result[0]).toHaveProperty('category'); |
| 9 | + expect(result[0]).toHaveProperty('description'); |
| 10 | + expect(result[0]).not.toHaveProperty('props'); |
| 11 | + expect(result[0]).not.toHaveProperty('demos'); |
| 12 | + }); |
| 13 | + |
| 14 | + it('filters by category', () => { |
| 15 | + const result = listComponents('Foundation'); |
| 16 | + expect(result.length).toBeGreaterThan(0); |
| 17 | + result.forEach((c) => expect(c.category).toBe('Foundation')); |
| 18 | + }); |
| 19 | + |
| 20 | + it('returns empty array for unknown category', () => { |
| 21 | + expect(listComponents('Unknown')).toEqual([]); |
| 22 | + }); |
| 23 | +}); |
| 24 | + |
| 25 | +describe('getComponentProps', () => { |
| 26 | + it('returns props for a known component', () => { |
| 27 | + const result = getComponentProps('Button'); |
| 28 | + expect(result).not.toBeNull(); |
| 29 | + expect(result!.name).toBe('Button'); |
| 30 | + expect(result!.props.length).toBeGreaterThan(0); |
| 31 | + expect(result!.props.find((p) => p.name === 'btnType')).toBeDefined(); |
| 32 | + }); |
| 33 | + |
| 34 | + it('is case-insensitive', () => { |
| 35 | + const result = getComponentProps('button'); |
| 36 | + expect(result).not.toBeNull(); |
| 37 | + expect(result!.name).toBe('Button'); |
| 38 | + }); |
| 39 | + |
| 40 | + it('returns null for unknown component', () => { |
| 41 | + expect(getComponentProps('FooBar')).toBeNull(); |
| 42 | + }); |
| 43 | +}); |
| 44 | + |
| 45 | +describe('getComponentExample', () => { |
| 46 | + it('returns all demos for a component', () => { |
| 47 | + const result = getComponentExample('Button'); |
| 48 | + expect(result).not.toBeNull(); |
| 49 | + expect(result!.length).toBeGreaterThan(0); |
| 50 | + expect(result![0].code).toContain('import'); |
| 51 | + }); |
| 52 | + |
| 53 | + it('returns specific demo by name', () => { |
| 54 | + const result = getComponentExample('Button', 'Type'); |
| 55 | + expect(result).not.toBeNull(); |
| 56 | + expect(result!.length).toBe(1); |
| 57 | + expect(result![0].name).toBe('Type'); |
| 58 | + }); |
| 59 | + |
| 60 | + it('returns null for unknown component', () => { |
| 61 | + expect(getComponentExample('FooBar')).toBeNull(); |
| 62 | + }); |
| 63 | +}); |
0 commit comments