Spaces:
Paused
Paused
Download src/lib/chart-tools.test.ts from WaveCut/Bonsai-Chat-WebGPU: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/spaces/WaveCut/Bonsai-Chat-WebGPU/resolve/main/src/lib/chart-tools.test.ts
- Command line
-
hf download hf://spaces/WaveCut/Bonsai-Chat-WebGPU/src/lib/chart-tools.test.ts
-
curl -L -o chart-tools.test.ts https://huggingface.co/spaces/WaveCut/Bonsai-Chat-WebGPU/resolve/main/src/lib/chart-tools.test.ts
1.17 kB
| 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'); | |
| }); | |
| }); | |