Spaces:
Running
Running
File size: 1,170 Bytes
897170b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | 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');
});
});
|