92 lines
3.4 KiB
TypeScript
92 lines
3.4 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { HealthAlertFormatter } from './HealthAlertFormatter';
|
|
|
|
describe('HealthAlertFormatter', () => {
|
|
describe('formatSeverity', () => {
|
|
it('should format critical severity correctly', () => {
|
|
expect(HealthAlertFormatter.formatSeverity('critical')).toBe('Critical');
|
|
});
|
|
|
|
it('should format warning severity correctly', () => {
|
|
expect(HealthAlertFormatter.formatSeverity('warning')).toBe('Warning');
|
|
});
|
|
|
|
it('should format info severity correctly', () => {
|
|
expect(HealthAlertFormatter.formatSeverity('info')).toBe('Info');
|
|
});
|
|
|
|
it('should default to Info for unknown severity', () => {
|
|
expect(HealthAlertFormatter.formatSeverity('unknown')).toBe('Info');
|
|
});
|
|
});
|
|
|
|
describe('formatSeverityColor', () => {
|
|
it('should return red for critical', () => {
|
|
expect(HealthAlertFormatter.formatSeverityColor('critical')).toBe('#ef4444');
|
|
});
|
|
|
|
it('should return amber for warning', () => {
|
|
expect(HealthAlertFormatter.formatSeverityColor('warning')).toBe('#f59e0b');
|
|
});
|
|
|
|
it('should return blue for info', () => {
|
|
expect(HealthAlertFormatter.formatSeverityColor('info')).toBe('#3b82f6');
|
|
});
|
|
|
|
it('should default to blue for unknown severity', () => {
|
|
expect(HealthAlertFormatter.formatSeverityColor('unknown')).toBe('#3b82f6');
|
|
});
|
|
});
|
|
|
|
describe('formatTimestamp', () => {
|
|
it('should format timestamp correctly', () => {
|
|
const timestamp = '2026-01-15T14:30:45Z';
|
|
const result = HealthAlertFormatter.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 = HealthAlertFormatter.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 = HealthAlertFormatter.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 = HealthAlertFormatter.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 = HealthAlertFormatter.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 = HealthAlertFormatter.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 = HealthAlertFormatter.formatRelativeTime(tenDaysAgo.toISOString());
|
|
expect(result).toBe('1w ago');
|
|
});
|
|
});
|
|
});
|