/** * Tests for the pure helpers in the Companies feature. We don't * test the list / detail components here (they require a full * QueryClient + router + auth context setup; that's a v1.1 * concern). The format helpers are the contract that the rest of * the feature relies on. */ import { describe, expect, it } from 'vitest'; import { formatDate, formatRateLimit, statusLabel, statusVariant } from '@/features/companies/format'; describe('companies/format', () => { it('statusLabel maps known statuses', () => { expect(statusLabel('active')).toBe('Active'); expect(statusLabel('suspended')).toBe('Suspended'); expect(statusLabel('archived')).toBe('Archived'); }); it('statusLabel falls back to the raw value for unknown', () => { // Defensive: if the API ever grows a new status, the badge // shows the raw value rather than empty. expect(statusLabel('paused' as never)).toBe('paused'); }); it('statusVariant picks a color per status', () => { expect(statusVariant('active')).toBe('success'); expect(statusVariant('suspended')).toBe('warning'); expect(statusVariant('archived')).toBe('muted'); }); it('formatRateLimit renders k/M/s suffixes', () => { expect(formatRateLimit(100)).toBe('100/s'); expect(formatRateLimit(1500)).toBe('1.5k/s'); expect(formatRateLimit(10_000)).toBe('10.0k/s'); expect(formatRateLimit(1_000_000)).toBe('1.0M/s'); }); it('formatDate handles null and invalid', () => { expect(formatDate(null)).toBe('\u2014'); expect(formatDate(undefined)).toBe('\u2014'); expect(formatDate('not-a-date')).toBe('not-a-date'); }); it('formatDate renders ISO timestamps', () => { const out = formatDate('2026-01-15T10:00:00Z'); expect(out).toMatch(/2026/); expect(out).toMatch(/Jan/); }); });