Files
gridpilot.gg/apps/website/lib/formatters/DurationFormatter.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

58 lines
2.0 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { DurationFormatter } from './DurationFormatter';
describe('DurationFormatter', () => {
describe('formatMs', () => {
it('should format milliseconds with 2 decimal places', () => {
expect(DurationFormatter.formatMs(123.456)).toBe('123.46ms');
expect(DurationFormatter.formatMs(123.454)).toBe('123.45ms');
});
it('should handle zero milliseconds', () => {
expect(DurationFormatter.formatMs(0)).toBe('0.00ms');
});
it('should handle large milliseconds', () => {
expect(DurationFormatter.formatMs(123456.789)).toBe('123456.79ms');
});
it('should handle negative milliseconds', () => {
expect(DurationFormatter.formatMs(-123.456)).toBe('-123.46ms');
});
});
describe('formatSeconds', () => {
it('should format seconds as "M:SS.mmm"', () => {
expect(DurationFormatter.formatSeconds(65.123)).toBe('1:05.123');
expect(DurationFormatter.formatSeconds(125.456)).toBe('2:05.456');
});
it('should handle zero seconds', () => {
expect(DurationFormatter.formatSeconds(0)).toBe('0:00.000');
});
it('should handle less than 60 seconds', () => {
expect(DurationFormatter.formatSeconds(5.123)).toBe('0:05.123');
expect(DurationFormatter.formatSeconds(59.999)).toBe('0:59.999');
});
it('should handle exactly 60 seconds', () => {
expect(DurationFormatter.formatSeconds(60)).toBe('1:00.000');
});
it('should handle multiple minutes', () => {
expect(DurationFormatter.formatSeconds(125.123)).toBe('2:05.123');
expect(DurationFormatter.formatSeconds(365.456)).toBe('6:05.456');
});
it('should pad seconds with leading zeros', () => {
expect(DurationFormatter.formatSeconds(5.123)).toBe('0:05.123');
expect(DurationFormatter.formatSeconds(0.123)).toBe('0:00.123');
});
it('should handle negative seconds', () => {
expect(DurationFormatter.formatSeconds(-65.123)).toBe('-1:05.123');
});
});
});