pooyash1998_chartspark/tests/templates/chartTemplates.test.ts
2026-04-26 08:43:06 +02:00

34 lines
1 KiB
TypeScript

import { CHART_TEMPLATES, getTemplate } from '../../src/templates/chartTemplates';
describe('CHART_TEMPLATES', () => {
it('contains at least 4 templates', () => {
expect(CHART_TEMPLATES.length).toBeGreaterThanOrEqual(4);
});
it('every template has required fields', () => {
for (const t of CHART_TEMPLATES) {
expect(t.id).toBeTruthy();
expect(t.name).toBeTruthy();
expect(t.description).toBeTruthy();
expect(t.config.type).toMatch(/^(pie|bar|line|doughnut)$/);
expect(t.config.data.labels.length).toBeGreaterThan(0);
expect(t.config.data.datasets.length).toBeGreaterThan(0);
}
});
it('all template ids are unique', () => {
const ids = CHART_TEMPLATES.map(t => t.id);
expect(new Set(ids).size).toBe(ids.length);
});
});
describe('getTemplate', () => {
it('finds template by id', () => {
const t = getTemplate('task-completion');
expect(t?.name).toBe('Task completion');
});
it('returns undefined for unknown id', () => {
expect(getTemplate('nonexistent')).toBeUndefined();
});
});