import { describe, expect, it } from 'vitest'; import { formatCount, formatDuration, formatHours, formatKm, formatRelative, formatUnit, prettyId } from '@/lib/format'; describe('format', () => { it('formats counts with German grouping', () => { expect(formatCount(1234)).toBe('1.234'); expect(formatCount(1234567)).toBe('1.234.567'); expect(formatCount(0)).toBe('0'); }); it('formats hours with one decimal and unit', () => { expect(formatHours(1175736 / 72000)).toBe('16,3 h'); expect(formatHours(1234.5)).toBe('1.234,5 h'); }); it('formats kilometres', () => { expect(formatKm(2)).toBe('2,0 km'); expect(formatKm(32.337)).toBe('32,3 km'); }); it('formats by board unit', () => { expect(formatUnit(16.33, 'hours')).toBe('16,3 h'); expect(formatUnit(5, 'count')).toBe('5'); expect(formatUnit(1200, 'blocks')).toBe('1.200'); expect(formatUnit(2, 'km')).toBe('2,0 km'); }); it('formats relative times', () => { const now = Date.UTC(2026, 9, 13, 12, 0, 0); expect(formatRelative(now - 20_000, now)).toBe('gerade eben'); expect(formatRelative(now - 5 * 60_000, now)).toBe('vor 5 Min.'); expect(formatRelative(now - 3 * 3600_000, now)).toBe('vor 3 Std.'); expect(formatRelative(now - 2 * 86_400_000, now)).toBe('vor 2 Tagen'); expect(formatRelative(null, now)).toBe('nie'); }); it('formats durations', () => { expect(formatDuration(45 * 60_000)).toBe('45 Min.'); expect(formatDuration(125 * 60_000)).toBe('2 Std. 5 Min.'); }); it('turns resource ids into readable names', () => { expect(prettyId('minecraft:wither_skeleton')).toBe('Wither Skeleton'); expect(prettyId('minecraft:play_time')).toBe('Play Time'); expect(prettyId('allthemodium:the_other')).toBe('The Other'); }); });