Files
errors.bitreport.pt/admin-ui/test/components/IncidentNotes.test.tsx
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

52 lines
1.9 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from 'vitest';
import { render, screen, fireEvent } from '@testing-library/react';
import { IncidentNotes } from '@/components/IncidentNotes';
describe('IncidentNotes', () => {
beforeEach(() => {
sessionStorage.clear();
});
it('renders the label', () => {
render(<IncidentNotes incidentId="inc-1" />);
expect(screen.getByText('Notas do operador')).toBeInTheDocument();
});
it('renders a textarea', () => {
render(<IncidentNotes incidentId="inc-1" />);
expect(screen.getByRole('textbox')).toBeInTheDocument();
});
it('starts with empty textarea when no stored value', () => {
render(<IncidentNotes incidentId="inc-new" />);
const ta = screen.getByRole('textbox') as HTMLTextAreaElement;
expect(ta.value).toBe('');
});
it('loads stored value from sessionStorage', () => {
sessionStorage.setItem('er-incident-notes:inc-42', 'saved note');
render(<IncidentNotes incidentId="inc-42" />);
const ta = screen.getByRole('textbox') as HTMLTextAreaElement;
expect(ta.value).toBe('saved note');
});
it('saves to sessionStorage when user types', () => {
render(<IncidentNotes incidentId="inc-99" />);
const ta = screen.getByRole('textbox');
fireEvent.change(ta, { target: { value: 'new note text' } });
expect(sessionStorage.getItem('er-incident-notes:inc-99')).toBe('new note text');
});
it('shows the helper text about server persistence', () => {
render(<IncidentNotes incidentId="inc-1" />);
expect(screen.getByText(/não são enviadas ao servidor/i)).toBeInTheDocument();
});
it('textarea is linked to its label via htmlFor/id', () => {
render(<IncidentNotes incidentId="inc-1" />);
const label = screen.getByText('Notas do operador');
const ta = screen.getByRole('textbox');
expect(label.getAttribute('for')).toBe(ta.getAttribute('id'));
});
});