Files
gridpilot.gg/apps/website/lib/formatters/HealthStatusFormatter.test.ts
Marc Mintel 3db2209d2a
Some checks failed
CI / lint-typecheck (push) Failing after 4m52s
CI / tests (push) Has been skipped
CI / contract-tests (push) Has been skipped
CI / e2e-tests (push) Has been skipped
CI / comment-pr (push) Has been skipped
CI / commit-types (push) Has been skipped
formatter tests
2026-01-25 11:17:47 +01:00

122 lines
4.4 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { HealthStatusFormatter } from './HealthStatusFormatter';
describe('HealthStatusFormatter', () => {
describe('formatStatusLabel', () => {
it('should format ok status correctly', () => {
expect(HealthStatusFormatter.formatStatusLabel('ok')).toBe('Healthy');
});
it('should format degraded status correctly', () => {
expect(HealthStatusFormatter.formatStatusLabel('degraded')).toBe('Degraded');
});
it('should format error status correctly', () => {
expect(HealthStatusFormatter.formatStatusLabel('error')).toBe('Error');
});
it('should format unknown status correctly', () => {
expect(HealthStatusFormatter.formatStatusLabel('unknown')).toBe('Unknown');
});
it('should default to Unknown for unknown status', () => {
expect(HealthStatusFormatter.formatStatusLabel('invalid')).toBe('Unknown');
});
});
describe('formatStatusColor', () => {
it('should return green for ok', () => {
expect(HealthStatusFormatter.formatStatusColor('ok')).toBe('#10b981');
});
it('should return amber for degraded', () => {
expect(HealthStatusFormatter.formatStatusColor('degraded')).toBe('#f59e0b');
});
it('should return red for error', () => {
expect(HealthStatusFormatter.formatStatusColor('error')).toBe('#ef4444');
});
it('should return gray for unknown', () => {
expect(HealthStatusFormatter.formatStatusColor('unknown')).toBe('#6b7280');
});
it('should default to gray for invalid status', () => {
expect(HealthStatusFormatter.formatStatusColor('invalid')).toBe('#6b7280');
});
});
describe('formatStatusIcon', () => {
it('should return checkmark for ok', () => {
expect(HealthStatusFormatter.formatStatusIcon('ok')).toBe('✓');
});
it('should return warning for degraded', () => {
expect(HealthStatusFormatter.formatStatusIcon('degraded')).toBe('⚠');
});
it('should return X for error', () => {
expect(HealthStatusFormatter.formatStatusIcon('error')).toBe('✕');
});
it('should return question mark for unknown', () => {
expect(HealthStatusFormatter.formatStatusIcon('unknown')).toBe('?');
});
it('should default to question mark for invalid status', () => {
expect(HealthStatusFormatter.formatStatusIcon('invalid')).toBe('?');
});
});
describe('formatTimestamp', () => {
it('should format timestamp correctly', () => {
const timestamp = '2026-01-15T14:30:45Z';
const result = HealthStatusFormatter.formatTimestamp(timestamp);
expect(result).toBe('Jan 15, 2026, 14:30:45');
});
it('should handle different timestamps', () => {
const timestamp = '2026-12-25T09:15:30Z';
const result = HealthStatusFormatter.formatTimestamp(timestamp);
expect(result).toBe('Dec 25, 2026, 09:15:30');
});
});
describe('formatRelativeTime', () => {
it('should return "Just now" for less than 1 minute ago', () => {
const now = new Date();
const oneSecondAgo = new Date(now.getTime() - 1000);
const result = HealthStatusFormatter.formatRelativeTime(oneSecondAgo.toISOString());
expect(result).toBe('Just now');
});
it('should return minutes ago for less than 1 hour', () => {
const now = new Date();
const thirtyMinutesAgo = new Date(now.getTime() - 30 * 60 * 1000);
const result = HealthStatusFormatter.formatRelativeTime(thirtyMinutesAgo.toISOString());
expect(result).toBe('30m ago');
});
it('should return hours ago for less than 24 hours', () => {
const now = new Date();
const fiveHoursAgo = new Date(now.getTime() - 5 * 60 * 60 * 1000);
const result = HealthStatusFormatter.formatRelativeTime(fiveHoursAgo.toISOString());
expect(result).toBe('5h ago');
});
it('should return days ago for less than 7 days', () => {
const now = new Date();
const threeDaysAgo = new Date(now.getTime() - 3 * 24 * 60 * 60 * 1000);
const result = HealthStatusFormatter.formatRelativeTime(threeDaysAgo.toISOString());
expect(result).toBe('3d ago');
});
it('should return weeks ago for more than 7 days', () => {
const now = new Date();
const tenDaysAgo = new Date(now.getTime() - 10 * 24 * 60 * 60 * 1000);
const result = HealthStatusFormatter.formatRelativeTime(tenDaysAgo.toISOString());
expect(result).toBe('1w ago');
});
});
});