Files
minstrel/web/src/lib/media/duration.test.ts
T
bvandeusen 7345625ecd feat(web): add formatDuration helper
Renders seconds as mm:ss or h:mm:ss. Negative inputs clamp to 0:00
so a bad backend value doesn't crash the UI.
2026-04-23 08:23:22 -04:00

34 lines
964 B
TypeScript

import { describe, expect, test } from 'vitest';
import { formatDuration } from './duration';
describe('formatDuration', () => {
test('under a minute renders 0:SS', () => {
expect(formatDuration(42)).toBe('0:42');
expect(formatDuration(5)).toBe('0:05');
});
test('under an hour renders M:SS', () => {
expect(formatDuration(242)).toBe('4:02');
expect(formatDuration(600)).toBe('10:00');
});
test('at or above an hour renders H:MM:SS', () => {
expect(formatDuration(3600)).toBe('1:00:00');
expect(formatDuration(3723)).toBe('1:02:03');
expect(formatDuration(36000)).toBe('10:00:00');
});
test('zero renders 0:00', () => {
expect(formatDuration(0)).toBe('0:00');
});
test('negative values clamp to 0:00', () => {
expect(formatDuration(-1)).toBe('0:00');
expect(formatDuration(-100)).toBe('0:00');
});
test('fractional seconds floor', () => {
expect(formatDuration(61.9)).toBe('1:01');
});
});