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

26 lines
1.3 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from 'vitest';
import { fallbackWidgetCatalog, isWidgetType, readWidgetCatalog, widgetLabel, widgetTypes } from '../../src/widgetCatalog';
afterEach(() => vi.unstubAllGlobals());
describe('widget catalog client', () => {
it('keeps one bounded fourteen-type catalog including query inspector', () => {
expect(widgetTypes).toHaveLength(14);
expect(new Set(widgetTypes).size).toBe(14);
expect(fallbackWidgetCatalog).toHaveLength(14);
expect(widgetLabel('query-inspector')).toBe('Query-inspecteur');
expect(isWidgetType('made-up')).toBe(false);
});
it('normalizes the existing Go catalog shape and ignores unknown entries', async () => {
vi.stubGlobal('fetch', vi.fn(async () => new Response(JSON.stringify({ items: [
{ Type: 'stat', Capabilities: ['metrics'] }, { Type: 'made-up' }, { type: 'text', capabilities: ['safe-markdown'] },
] }), { status: 200, headers: { 'Content-Type': 'application/json' } })));
const catalog = await readWidgetCatalog();
expect(catalog).toHaveLength(14);
expect(catalog.find((item) => item.type === 'stat')?.capabilities).toEqual(['metrics']);
expect(catalog.find((item) => item.type === 'text')?.capabilities).toEqual(['safe-markdown']);
expect(catalog.some((item) => item.type === ('made-up' as never))).toBe(false);
});
});