Files
minecraft-atm10-stats/web/test/format.test.ts
T
lucashahmannandClaude Opus 5.5 e66f89f49e feat: ATM10-Statistikportal
Statistikportal für den All-the-Mods-10-Server (Minecraft 1.21.1, NeoForge 21.1):

- mod/: serverseitige NeoForge-Mod atmstats – Ereignisse, Live-Zähler, Servergesundheit,
  FTB-Dateien; Outbox auf der Festplatte, signierter gzip-Versand per HTTPS mit Backoff
- backend/: Fastify + PostgreSQL – idempotenter Ingest, Projektionen, Parser für SNBT,
  FTB Quests/Teams, world/stats, world/advancements und latest.log; Ranglisten, Snapshots,
  Retention, öffentliche API, SSE-Live-Updates, Admin mit argon2/CSRF, SFTP-Worker
- web/: Next.js-Dashboard – Übersicht, Ranglisten, Spielerprofile, ATM10, Server,
  Datenquellen, Verwaltung
- shared/: Protokoll v1 und API-Typen; tools/: Simulator, Log-Anonymisierer, RCON-Client
- deploy/: Docker Compose hinter Traefik, Backup; docs/: Architektur, Datenquellen, Betrieb

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 09:33:25 +02:00

48 lines
1.8 KiB
TypeScript

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');
});
});