formatter tests
Some checks failed
Some checks failed
This commit is contained in:
57
apps/website/lib/formatters/DurationFormatter.test.ts
Normal file
57
apps/website/lib/formatters/DurationFormatter.test.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
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');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user