Files
ITWorx-Pulse-Public/apps/web/tests/unit/ApplicationPage.test.tsx
T
ITWorx Pulse release export bd774932d5
Public source validation / validate (push) Failing after 3m8s
Publish ITWorx Pulse source
2026-09-03 02:09:19 +02:00

44 lines
2.1 KiB
TypeScript

import { cleanup, render, screen, within } from '@testing-library/react';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { ApplicationPage } from '../../src/ApplicationPage';
afterEach(() => { cleanup(); vi.unstubAllGlobals(); });
describe('application status projection', () => {
it('uses attention for failures and unknown for incomplete evidence', async () => {
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(new Response(JSON.stringify({
source: { id: 'agent+services', state: 'healthy', freshness: 'fresh' },
total: 2,
applications: [
{ id: 'a', name: 'attention-app', status: 'DOWN', overridden: false, components: [] },
{ id: 'b', name: 'unknown-app', status: 'unknown', overridden: false, components: [] },
],
}), { status: 200, headers: { 'Content-Type': 'application/json' } })));
render(<ApplicationPage />);
const attention = (await screen.findByText('attention-app')).closest('li');
const unknown = screen.getByText('unknown-app').closest('li');
expect(attention).not.toBeNull();
expect(unknown).not.toBeNull();
expect(within(attention!).getByText('Aandacht').closest('.status-badge')).toHaveClass('status-badge--attention');
expect(within(unknown!).getByText('Onbekend').closest('.status-badge')).toHaveClass('status-badge--unknown');
});
it('vertaalt staleness en toont nooit een jaar-1-waarneming als echte tijd', async () => {
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(new Response(JSON.stringify({
source: { id: 'agent+services', state: 'healthy', freshness: 'stale', observedAt: '0001-01-01T00:00:00Z', reason: 'source_stale' },
total: 0,
applications: [],
}), { status: 200, headers: { 'Content-Type': 'application/json' } })));
render(<ApplicationPage />);
expect(await screen.findByText(/laatste meting is verouderd/i)).toBeVisible();
expect(screen.getByText('Nooit ontvangen')).toBeVisible();
expect(screen.queryByText(/1 jan 1/i)).not.toBeInTheDocument();
expect(screen.getByText('source_stale')).not.toBeVisible();
});
});