Spaces:
Running
Running
| import { describe, expect, it } from 'vitest'; | |
| import { generateBarChartHtml, generatePieChartHtml } from './chart-tools'; | |
| describe('chart artifact generators', () => { | |
| it('renders escaped aligned data as a responsive bar chart', () => { | |
| const html = generateBarChartHtml({ | |
| title: 'Build & test', | |
| labels: ['Alpha <script>', 'Beta'], | |
| values: [10, 5], | |
| }); | |
| expect(html).toContain('Build & test'); | |
| expect(html).toContain('Alpha <script>'); | |
| expect(html).toContain('width:100.0000%'); | |
| expect(html).toContain('width:50.0000%'); | |
| }); | |
| it('renders parts of a positive whole as a pie chart', () => { | |
| const html = generatePieChartHtml({ title: 'Share', labels: ['One', 'Two'], values: [1, 3] }); | |
| expect(html).toContain('conic-gradient('); | |
| expect(html).toContain('25.0%'); | |
| expect(html).toContain('75.0%'); | |
| }); | |
| it('rejects mismatched or zero-only pie data', () => { | |
| expect(() => generateBarChartHtml({ title: 'Bad', labels: ['One'], values: [1, 2] })).toThrow('same length'); | |
| expect(() => generatePieChartHtml({ title: 'Bad', labels: ['One'], values: [0] })).toThrow('positive total'); | |
| }); | |
| }); | |