import { describe, it, expect } from 'vitest';
import { fmtDuration } from './format';

describe('fmtDuration', () => {
    it('renders sub-second as ms', () => {
        expect(fmtDuration(0)).toBe('0ms');
        expect(fmtDuration(420)).toBe('420ms');
        expect(fmtDuration(999)).toBe('999ms');
    });

    it('renders seconds with one decimal under 10s, none above', () => {
        expect(fmtDuration(6100)).toBe('6.1s');
        expect(fmtDuration(42000)).toBe('42s');
    });

    it('renders minutes + zero-padded seconds', () => {
        expect(fmtDuration(62000)).toBe('1m 02s');
        expect(fmtDuration(125000)).toBe('2m 05s');
    });

    it('rounds the seconds carry into minutes (no "1m 60s")', () => {
        expect(fmtDuration(119600)).toBe('2m 00s');
    });

    it('renders null/undefined as an em-dash', () => {
        expect(fmtDuration(null)).toBe('—');
        expect(fmtDuration(undefined)).toBe('—');
    });
});
