Files
ITWorx-Pulse-Public/apps/web/tests/unit/dashboardTemplates.test.ts
T
2026-09-30 01:14:48 +00:00

18 lines
1.4 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { buildDashboardDocument, dashboardSlug } from '../../src/dashboardTemplates';
describe('dashboard templates', () => {
it('creates a schema v2 blank document with required fields', () => {
let index = 0;
const document = buildDashboardDocument({ name: 'Mijn Test', scope: 'personal', template: 'blank', idFactory: () => `00000000-0000-4000-8000-${String(++index).padStart(12, '0')}` });
expect(document.schemaVersion).toBe(2); expect(document.scope).toBe('personal'); expect(document.widgets).toEqual([]); expect(document.slug).toMatch(/^mijn-test-/);
});
it('only uses proven runtime sources in the operations template', () => {
let index = 0;
const document = buildDashboardDocument({ name: 'Operations', scope: 'shared', template: 'operations', idFactory: () => `10000000-0000-4000-8000-${String(++index).padStart(12, '0')}` });
const widgets = document.widgets as Array<{ data?: { sourceType?: string } }>;
expect(widgets.length).toBeGreaterThan(0); expect(new Set(widgets.map((widget) => widget.data?.sourceType))).toEqual(new Set(['inventory', 'semantic-metric', 'events']));
});
it('normalizes a unicode name to a valid bounded slug', () => { const slug = dashboardSlug('Opslag & Café / Test', 'ABC123'); expect(slug).toBe('opslag-cafe-test-abc123'); expect(slug.length).toBeLessThanOrEqual(80); });
});