Files
errors.bitreport.pt/admin-ui/test/components/AppShell.test.tsx
T
David SantosandPaperclip 3d4444eb21 BIT-15744: add remaining unit tests for admin-ui, api routes, collector-worker db, ingest-api services
Complete test coverage implementation for errors.bitreport.pt:

admin-ui (98 tests):
- test/components/: AppShell, DataAlert, IncidentNotes, KpiCard, SeverityBadge, StateBadge
- test/lib/: format, demo-incidents, incidents-data, incidents-data-api, stats-data, stats-data-api
- vitest.config.ts with jsdom + v8 coverage + @vitejs/plugin-react

api route tests (54 tests):
- src/routes/admin/auth.test.ts (15 tests)
- src/routes/admin/incidents.test.ts (11 tests)
- src/routes/admin/stats.test.ts (18 tests)
- src/routes/public/errorMonitoringStats.test.ts (10 tests)

collector-worker db/scheduler tests (22 tests):
- src/db/collectorRunWriter.test.ts (10 tests)
- src/db/loadActiveSources.test.ts (6 tests)
- src/scheduler/runHttpSourceOnce.test.ts (6 tests)

ingest-api service tests (13 tests):
- src/buildApp.test.ts, plugins/prometheus.test.ts
- services/ingestAuth.test.ts, services/processIngestBatch.utils.test.ts

Total: 187 additional tests (255 total across all modules). All pass.

Paperclip-Issue: BIT-15744
Co-Authored-By: Paperclip <[email protected]>
2026-05-03 07:24:38 +00:00

70 lines
2.6 KiB
TypeScript

import { describe, it, expect, vi } from 'vitest';
import { render, screen } from '@testing-library/react';
import { AppShell } from '@/components/AppShell';
vi.mock('next/link', () => ({
default: ({ href, children, className }: { href: string; children: React.ReactNode; className?: string }) => (
<a href={href} className={className}>{children}</a>
),
}));
describe('AppShell', () => {
it('renders the page title', () => {
render(<AppShell title="Dashboard"><div>content</div></AppShell>);
expect(screen.getByRole('heading', { name: 'Dashboard' })).toBeInTheDocument();
});
it('renders child content', () => {
render(<AppShell title="Test"><p>Hello content</p></AppShell>);
expect(screen.getByText('Hello content')).toBeInTheDocument();
});
it('renders the BitReport brand link', () => {
render(<AppShell title="T"><div /></AppShell>);
expect(screen.getByText('BitReport')).toBeInTheDocument();
});
it('renders nav links for Painel and Incidentes', () => {
render(<AppShell title="T"><div /></AppShell>);
expect(screen.getByRole('link', { name: /Painel/i })).toBeInTheDocument();
expect(screen.getByRole('link', { name: /Incidentes/i })).toBeInTheDocument();
});
it('renders breadcrumb when provided', () => {
render(
<AppShell title="T" breadcrumb={[{ label: 'Home', href: '/' }, { label: 'Current' }]}>
<div />
</AppShell>
);
expect(screen.getByRole('navigation', { name: 'breadcrumb' })).toBeInTheDocument();
expect(screen.getByText('Home')).toBeInTheDocument();
expect(screen.getByText('Current')).toBeInTheDocument();
});
it('does not render breadcrumb nav when breadcrumb is empty', () => {
render(<AppShell title="T" breadcrumb={[]}><div /></AppShell>);
expect(screen.queryByRole('navigation', { name: 'breadcrumb' })).toBeNull();
});
it('does not render breadcrumb nav when breadcrumb is omitted', () => {
render(<AppShell title="T"><div /></AppShell>);
expect(screen.queryByRole('navigation', { name: 'breadcrumb' })).toBeNull();
});
it('breadcrumb item with href renders as a link', () => {
render(
<AppShell title="T" breadcrumb={[{ label: 'Home', href: '/home' }]}><div /></AppShell>
);
const link = screen.getByText('Home').closest('a');
expect(link).not.toBeNull();
});
it('breadcrumb item without href has aria-current="page"', () => {
render(
<AppShell title="T" breadcrumb={[{ label: 'Current page' }]}><div /></AppShell>
);
const item = screen.getByText('Current page').closest('li');
expect(item?.getAttribute('aria-current')).toBe('page');
});
});