companies.test.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * Tests for the pure helpers in the Companies feature. We don't
  3. * test the list / detail components here (they require a full
  4. * QueryClient + router + auth context setup; that's a v1.1
  5. * concern). The format helpers are the contract that the rest of
  6. * the feature relies on.
  7. */
  8. import { describe, expect, it } from 'vitest';
  9. import { formatDate, formatRateLimit, statusLabel, statusVariant } from '@/features/companies/format';
  10. describe('companies/format', () => {
  11. it('statusLabel maps known statuses', () => {
  12. expect(statusLabel('active')).toBe('Active');
  13. expect(statusLabel('suspended')).toBe('Suspended');
  14. expect(statusLabel('archived')).toBe('Archived');
  15. });
  16. it('statusLabel falls back to the raw value for unknown', () => {
  17. // Defensive: if the API ever grows a new status, the badge
  18. // shows the raw value rather than empty.
  19. expect(statusLabel('paused' as never)).toBe('paused');
  20. });
  21. it('statusVariant picks a color per status', () => {
  22. expect(statusVariant('active')).toBe('success');
  23. expect(statusVariant('suspended')).toBe('warning');
  24. expect(statusVariant('archived')).toBe('muted');
  25. });
  26. it('formatRateLimit renders k/M/s suffixes', () => {
  27. expect(formatRateLimit(100)).toBe('100/s');
  28. expect(formatRateLimit(1500)).toBe('1.5k/s');
  29. expect(formatRateLimit(10_000)).toBe('10.0k/s');
  30. expect(formatRateLimit(1_000_000)).toBe('1.0M/s');
  31. });
  32. it('formatDate handles null and invalid', () => {
  33. expect(formatDate(null)).toBe('\u2014');
  34. expect(formatDate(undefined)).toBe('\u2014');
  35. expect(formatDate('not-a-date')).toBe('not-a-date');
  36. });
  37. it('formatDate renders ISO timestamps', () => {
  38. const out = formatDate('2026-01-15T10:00:00Z');
  39. expect(out).toMatch(/2026/);
  40. expect(out).toMatch(/Jan/);
  41. });
  42. });