|
1 | | -import { describe, it, expect } from 'vitest'; |
| 1 | +import { describe, it, expect, beforeAll } from 'vitest'; |
| 2 | +import { ComponentRegistry } from '@object-ui/core'; |
2 | 3 |
|
3 | | -describe('@object-ui/plugin-charts', () => { |
4 | | - it('should pass', () => { |
5 | | - expect(true).toBe(true); |
| 4 | +describe('Plugin Charts', () => { |
| 5 | + // Import all renderers to register them |
| 6 | + beforeAll(async () => { |
| 7 | + await import('./index'); |
| 8 | + }); |
| 9 | + |
| 10 | + describe('chart-bar component', () => { |
| 11 | + it('should be registered in ComponentRegistry', () => { |
| 12 | + const chartBarRenderer = ComponentRegistry.get('chart-bar'); |
| 13 | + expect(chartBarRenderer).toBeDefined(); |
| 14 | + }); |
| 15 | + |
| 16 | + it('should have proper metadata', () => { |
| 17 | + const config = ComponentRegistry.getConfig('chart-bar'); |
| 18 | + expect(config).toBeDefined(); |
| 19 | + expect(config?.label).toBe('Bar Chart'); |
| 20 | + expect(config?.category).toBe('plugin'); |
| 21 | + expect(config?.inputs).toBeDefined(); |
| 22 | + expect(config?.defaultProps).toBeDefined(); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should have expected inputs', () => { |
| 26 | + const config = ComponentRegistry.getConfig('chart-bar'); |
| 27 | + const inputNames = config?.inputs?.map((input: any) => input.name) || []; |
| 28 | + |
| 29 | + expect(inputNames).toContain('data'); |
| 30 | + expect(inputNames).toContain('dataKey'); |
| 31 | + expect(inputNames).toContain('xAxisKey'); |
| 32 | + expect(inputNames).toContain('height'); |
| 33 | + expect(inputNames).toContain('color'); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should have data as required input', () => { |
| 37 | + const config = ComponentRegistry.getConfig('chart-bar'); |
| 38 | + const dataInput = config?.inputs?.find((input: any) => input.name === 'data'); |
| 39 | + |
| 40 | + expect(dataInput).toBeDefined(); |
| 41 | + expect(dataInput?.required).toBe(true); |
| 42 | + expect(dataInput?.type).toBe('array'); |
| 43 | + }); |
| 44 | + |
| 45 | + it('should have sensible default props', () => { |
| 46 | + const config = ComponentRegistry.getConfig('chart-bar'); |
| 47 | + const defaults = config?.defaultProps; |
| 48 | + |
| 49 | + expect(defaults).toBeDefined(); |
| 50 | + expect(defaults?.dataKey).toBe('value'); |
| 51 | + expect(defaults?.xAxisKey).toBe('name'); |
| 52 | + expect(defaults?.height).toBe(400); |
| 53 | + expect(defaults?.color).toBe('#8884d8'); |
| 54 | + expect(defaults?.data).toBeDefined(); |
| 55 | + expect(Array.isArray(defaults?.data)).toBe(true); |
| 56 | + expect(defaults?.data.length).toBeGreaterThan(0); |
| 57 | + }); |
| 58 | + }); |
| 59 | + |
| 60 | + describe('chart (advanced) component', () => { |
| 61 | + it('should be registered in ComponentRegistry', () => { |
| 62 | + const chartRenderer = ComponentRegistry.get('chart'); |
| 63 | + expect(chartRenderer).toBeDefined(); |
| 64 | + }); |
| 65 | + |
| 66 | + it('should have proper metadata', () => { |
| 67 | + const config = ComponentRegistry.getConfig('chart'); |
| 68 | + expect(config).toBeDefined(); |
| 69 | + expect(config?.label).toBe('Chart'); |
| 70 | + expect(config?.category).toBe('plugin'); |
| 71 | + expect(config?.inputs).toBeDefined(); |
| 72 | + expect(config?.defaultProps).toBeDefined(); |
| 73 | + }); |
| 74 | + |
| 75 | + it('should have expected inputs', () => { |
| 76 | + const config = ComponentRegistry.getConfig('chart'); |
| 77 | + const inputNames = config?.inputs?.map((input: any) => input.name) || []; |
| 78 | + |
| 79 | + expect(inputNames).toContain('chartType'); |
| 80 | + expect(inputNames).toContain('data'); |
| 81 | + expect(inputNames).toContain('config'); |
| 82 | + expect(inputNames).toContain('xAxisKey'); |
| 83 | + expect(inputNames).toContain('series'); |
| 84 | + expect(inputNames).toContain('className'); |
| 85 | + }); |
| 86 | + |
| 87 | + it('should have chartType as enum input', () => { |
| 88 | + const config = ComponentRegistry.getConfig('chart'); |
| 89 | + const chartTypeInput = config?.inputs?.find((input: any) => input.name === 'chartType'); |
| 90 | + |
| 91 | + expect(chartTypeInput).toBeDefined(); |
| 92 | + expect(chartTypeInput?.type).toBe('enum'); |
| 93 | + expect(chartTypeInput?.enum).toBeDefined(); |
| 94 | + expect(Array.isArray(chartTypeInput?.enum)).toBe(true); |
| 95 | + |
| 96 | + const enumValues = chartTypeInput?.enum?.map((e: any) => e.value) || []; |
| 97 | + expect(enumValues).toContain('bar'); |
| 98 | + expect(enumValues).toContain('line'); |
| 99 | + expect(enumValues).toContain('area'); |
| 100 | + }); |
| 101 | + |
| 102 | + it('should have data and series as required inputs', () => { |
| 103 | + const config = ComponentRegistry.getConfig('chart'); |
| 104 | + const dataInput = config?.inputs?.find((input: any) => input.name === 'data'); |
| 105 | + const seriesInput = config?.inputs?.find((input: any) => input.name === 'series'); |
| 106 | + |
| 107 | + expect(dataInput?.required).toBe(true); |
| 108 | + expect(seriesInput?.required).toBe(true); |
| 109 | + }); |
| 110 | + |
| 111 | + it('should have sensible default props', () => { |
| 112 | + const config = ComponentRegistry.getConfig('chart'); |
| 113 | + const defaults = config?.defaultProps; |
| 114 | + |
| 115 | + expect(defaults).toBeDefined(); |
| 116 | + expect(defaults?.chartType).toBe('bar'); |
| 117 | + expect(defaults?.xAxisKey).toBe('name'); |
| 118 | + expect(defaults?.data).toBeDefined(); |
| 119 | + expect(Array.isArray(defaults?.data)).toBe(true); |
| 120 | + expect(defaults?.data.length).toBeGreaterThan(0); |
| 121 | + expect(defaults?.config).toBeDefined(); |
| 122 | + expect(typeof defaults?.config).toBe('object'); |
| 123 | + expect(defaults?.series).toBeDefined(); |
| 124 | + expect(Array.isArray(defaults?.series)).toBe(true); |
| 125 | + expect(defaults?.series.length).toBeGreaterThan(0); |
| 126 | + }); |
6 | 127 | }); |
7 | 128 | }); |
0 commit comments