feat: v0.10.0 — right Jobs & Market pane (contracts accept/dispatch, market buy/sell/refuel with live previews); catalog + economy constants exposed in /api/state; shared applySnapshot for instant action feedback
This commit is contained in:
+38
-1
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { formatCash, formatFuel, formatSimClock } from './format';
|
||||
import { formatCash, formatDeadlineRelative, formatDuration, formatFuel, formatSimClock } from './format';
|
||||
|
||||
describe('formatCash', () => {
|
||||
it('formats EUR with thousands separators and two decimals', () => {
|
||||
@@ -28,3 +28,40 @@ describe('formatSimClock', () => {
|
||||
expect(formatSimClock(Date.UTC(2026, 8, 17, 14, 5, 9))).toBe('2026-09-17 14:05:09 UTC');
|
||||
});
|
||||
});
|
||||
|
||||
const MIN = 60_000;
|
||||
const HOUR = 3_600_000;
|
||||
const DAY = 86_400_000;
|
||||
|
||||
describe('formatDuration', () => {
|
||||
it('renders days + hours, hours + minutes, or bare minutes (rounded to the minute)', () => {
|
||||
expect(formatDuration(2 * DAY + 3 * HOUR)).toBe('2d 3h');
|
||||
expect(formatDuration(14 * HOUR + 30 * MIN)).toBe('14h 30m');
|
||||
expect(formatDuration(45 * MIN)).toBe('45m');
|
||||
expect(formatDuration(60 * MIN)).toBe('1h 0m');
|
||||
// Rounding to the nearest minute: 29m29s stays at 29, 29m31s rounds up to 30.
|
||||
expect(formatDuration(29 * MIN + 29_000)).toBe('29m');
|
||||
expect(formatDuration(29 * MIN + 31_000)).toBe('30m');
|
||||
});
|
||||
|
||||
it('clamps zero and negative input to "0m"', () => {
|
||||
expect(formatDuration(0)).toBe('0m');
|
||||
expect(formatDuration(-5 * MIN)).toBe('0m');
|
||||
});
|
||||
});
|
||||
|
||||
describe('formatDeadlineRelative', () => {
|
||||
const NOW = Date.UTC(2026, 8, 17, 12, 0);
|
||||
|
||||
it('renders "in <duration>" for future deadlines relative to the sim clock', () => {
|
||||
expect(formatDeadlineRelative(NOW + 14 * HOUR + 30 * MIN, NOW)).toBe('in 14h 30m');
|
||||
expect(formatDeadlineRelative(NOW + 2 * DAY + 3 * HOUR, NOW)).toBe('in 2d 3h');
|
||||
expect(formatDeadlineRelative(NOW + 45 * MIN, NOW)).toBe('in 45m');
|
||||
});
|
||||
|
||||
it('renders "now" for sub-minute deadlines and "overdue" at or past the deadline', () => {
|
||||
expect(formatDeadlineRelative(NOW + 30_000, NOW)).toBe('now');
|
||||
expect(formatDeadlineRelative(NOW, NOW)).toBe('overdue');
|
||||
expect(formatDeadlineRelative(NOW - HOUR, NOW)).toBe('overdue');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user