31 lines
1.2 KiB
TypeScript
31 lines
1.2 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { formatCash, formatFuel, formatSimClock } from './format';
|
|
|
|
describe('formatCash', () => {
|
|
it('formats EUR with thousands separators and two decimals', () => {
|
|
expect(formatCash(20_000)).toBe('€20,000.00');
|
|
expect(formatCash(1_234_567.891)).toBe('€1,234,567.89');
|
|
});
|
|
|
|
it('handles zero and fractional values (refuel costs are fractional)', () => {
|
|
expect(formatCash(0)).toBe('€0.00');
|
|
expect(formatCash(30.4)).toBe('€30.40');
|
|
});
|
|
});
|
|
|
|
describe('formatFuel', () => {
|
|
it('shows current / max liters with the current value rounded', () => {
|
|
expect(formatFuel(6300, 6300)).toBe('6300 / 6300 L');
|
|
expect(formatFuel(1234.6, 6300)).toBe('1235 / 6300 L');
|
|
expect(formatFuel(0, 6300)).toBe('0 / 6300 L');
|
|
});
|
|
});
|
|
|
|
describe('formatSimClock', () => {
|
|
it('formats epoch ms as a UTC wall-clock string with seconds (deterministic across timezones)', () => {
|
|
expect(formatSimClock(Date.UTC(2026, 8, 17, 14, 5))).toBe('2026-09-17 14:05:00 UTC');
|
|
expect(formatSimClock(Date.UTC(2026, 0, 1, 0, 0))).toBe('2026-01-01 00:00:00 UTC');
|
|
expect(formatSimClock(Date.UTC(2026, 8, 17, 14, 5, 9))).toBe('2026-09-17 14:05:09 UTC');
|
|
});
|
|
});
|