formatter tests
Some checks failed
Some checks failed
This commit is contained in:
84
apps/website/lib/formatters/HealthComponentFormatter.test.ts
Normal file
84
apps/website/lib/formatters/HealthComponentFormatter.test.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { HealthComponentFormatter } from './HealthComponentFormatter';
|
||||
|
||||
describe('HealthComponentFormatter', () => {
|
||||
describe('formatStatusLabel', () => {
|
||||
it('should format ok status correctly', () => {
|
||||
expect(HealthComponentFormatter.formatStatusLabel('ok')).toBe('Healthy');
|
||||
});
|
||||
|
||||
it('should format degraded status correctly', () => {
|
||||
expect(HealthComponentFormatter.formatStatusLabel('degraded')).toBe('Degraded');
|
||||
});
|
||||
|
||||
it('should format error status correctly', () => {
|
||||
expect(HealthComponentFormatter.formatStatusLabel('error')).toBe('Error');
|
||||
});
|
||||
|
||||
it('should format unknown status correctly', () => {
|
||||
expect(HealthComponentFormatter.formatStatusLabel('unknown')).toBe('Unknown');
|
||||
});
|
||||
|
||||
it('should default to Unknown for unknown status', () => {
|
||||
expect(HealthComponentFormatter.formatStatusLabel('invalid')).toBe('Unknown');
|
||||
});
|
||||
});
|
||||
|
||||
describe('formatStatusColor', () => {
|
||||
it('should return green for ok', () => {
|
||||
expect(HealthComponentFormatter.formatStatusColor('ok')).toBe('#10b981');
|
||||
});
|
||||
|
||||
it('should return amber for degraded', () => {
|
||||
expect(HealthComponentFormatter.formatStatusColor('degraded')).toBe('#f59e0b');
|
||||
});
|
||||
|
||||
it('should return red for error', () => {
|
||||
expect(HealthComponentFormatter.formatStatusColor('error')).toBe('#ef4444');
|
||||
});
|
||||
|
||||
it('should return gray for unknown', () => {
|
||||
expect(HealthComponentFormatter.formatStatusColor('unknown')).toBe('#6b7280');
|
||||
});
|
||||
|
||||
it('should default to gray for invalid status', () => {
|
||||
expect(HealthComponentFormatter.formatStatusColor('invalid')).toBe('#6b7280');
|
||||
});
|
||||
});
|
||||
|
||||
describe('formatStatusIcon', () => {
|
||||
it('should return checkmark for ok', () => {
|
||||
expect(HealthComponentFormatter.formatStatusIcon('ok')).toBe('✓');
|
||||
});
|
||||
|
||||
it('should return warning for degraded', () => {
|
||||
expect(HealthComponentFormatter.formatStatusIcon('degraded')).toBe('⚠');
|
||||
});
|
||||
|
||||
it('should return X for error', () => {
|
||||
expect(HealthComponentFormatter.formatStatusIcon('error')).toBe('✕');
|
||||
});
|
||||
|
||||
it('should return question mark for unknown', () => {
|
||||
expect(HealthComponentFormatter.formatStatusIcon('unknown')).toBe('?');
|
||||
});
|
||||
|
||||
it('should default to question mark for invalid status', () => {
|
||||
expect(HealthComponentFormatter.formatStatusIcon('invalid')).toBe('?');
|
||||
});
|
||||
});
|
||||
|
||||
describe('formatTimestamp', () => {
|
||||
it('should format timestamp correctly', () => {
|
||||
const timestamp = '2026-01-15T14:30:45Z';
|
||||
const result = HealthComponentFormatter.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 = HealthComponentFormatter.formatTimestamp(timestamp);
|
||||
expect(result).toBe('Dec 25, 2026, 09:15:30');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user