Added tests for format and storage, run in UK time

This commit is contained in:
bwilliams committed 2026-10-16 16:46:08 +01:00
1 parent 13232bb15c
commit a6630f112f
3 files changed
+67 -1

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
import { expect, test } from 'vitest';
import { formatDate, formatMoney, parseDate } from './format';
test.each([
{ name: 'null', value: null },
{ name: 'undefined', value: undefined },
{ name: 'empty', value: '' },
{ name: 'Go’s zero time', value: '0001-01-01T00:00:00Z' },
{ name: 'not a date', value: 'soon' },
])('parseDate reads $name as no date', ({ value }) => {
expect(parseDate(value)).toBeNull();
expect(formatDate(value)).toBe('—');
});
test('dates are shown day, short month and year', () => {
// Tests run in UK time (vite.config.ts), as dates are shown in local time.
expect(parseDate('2026-03-03T12:00:00Z')?.toISOString()).toBe('2026-03-03T12:00:00.000Z');
expect(formatDate('2026-03-03T12:00:00Z')).toBe('3 Mar 2026');
// 23:30 UTC is already the next day in British Summer Time.
expect(formatDate('2026-07-01T23:30:00Z')).toBe('2 Jul 2026');
});
test('money is shown in whole pounds, and nothing as a dash', () => {
expect(formatMoney(125000.5)).toBe('£125,001');
expect(formatMoney(0)).toBe('—');
expect(formatMoney(-5)).toBe('—');
});