Persist countdown inputs and show completion bell in tab title
Some checks failed
/ publish (push) Failing after 2m20s
Some checks failed
/ publish (push) Failing after 2m20s
Co-authored-by: Shelley <shelley@exe.dev>
This commit is contained in:
parent
ebfd6e4ce1
commit
a42f897248
3 changed files with 90 additions and 1 deletions
43
site/countdown/settings.test.mjs
Normal file
43
site/countdown/settings.test.mjs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
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' });
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue