Some checks failed
/ publish (push) Failing after 2m20s
Co-authored-by: Shelley <shelley@exe.dev>
43 lines
1.6 KiB
JavaScript
43 lines
1.6 KiB
JavaScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { serializeSettings, parseSettings } from './settings.mjs';
|
|
|
|
test('settings store only entered minutes and seconds, not countdown state', () => {
|
|
assert.deepEqual(JSON.parse(serializeSettings('2', '90')), {
|
|
minutes: '2', seconds: '90',
|
|
});
|
|
assert.deepEqual(parseSettings(serializeSettings('2', '90')), {
|
|
minutes: '2', seconds: '90',
|
|
});
|
|
});
|
|
|
|
test('restored seconds have at least two digits and leading zeros are canonicalized', () => {
|
|
assert.deepEqual(parseSettings(serializeSettings('001', '005')), {
|
|
minutes: '1', seconds: '05',
|
|
});
|
|
});
|
|
|
|
test('empty input is stored as zero', () => {
|
|
assert.deepEqual(parseSettings(serializeSettings('', '')), {
|
|
minutes: '0', seconds: '00',
|
|
});
|
|
});
|
|
|
|
test('large entered integers round trip without losing precision', () => {
|
|
const minutes = '123456789012345678901234567890';
|
|
const seconds = '987654321098765432109876543210';
|
|
assert.deepEqual(parseSettings(serializeSettings(minutes, seconds)), { minutes, seconds });
|
|
});
|
|
|
|
test('missing, malformed, or invalid settings restore the default countdown', () => {
|
|
for (const json of [
|
|
null, '', 'invalid json', 'null', '[]', '{}', '42',
|
|
'{"minutes": 1, "seconds": 2}',
|
|
'{"minutes": "-1", "seconds": "00"}',
|
|
'{"minutes": "0", "seconds": "1.5"}',
|
|
'{"minutes": "0", "seconds": ""}',
|
|
'{"minutes": "0", "seconds": "1e2"}',
|
|
]) {
|
|
assert.deepEqual(parseSettings(json), { minutes: '0', seconds: '00' });
|
|
}
|
|
});
|