diff options
| author | godosa <godosa@godosa.eu> | 2026-10-07 00:14:38 +0200 |
|---|---|---|
| committer | godosa <godosa@godosa.eu> | 2026-10-07 00:14:38 +0200 |
| commit | 3443c1c65e9f1753e1e656b35d08416c1fa298f2 (patch) | |
| tree | 4e43236f460145a4d75d1b4616dcb7aa6ef08f51 /viewer/tests/pins.test.mjs | |
| download | worldmap-viewer-3443c1c65e9f1753e1e656b35d08416c1fa298f2.tar.gz worldmap-viewer-3443c1c65e9f1753e1e656b35d08416c1fa298f2.zip | |
worldmap-viewer: initial public history
Diffstat (limited to 'viewer/tests/pins.test.mjs')
| -rw-r--r-- | viewer/tests/pins.test.mjs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/viewer/tests/pins.test.mjs b/viewer/tests/pins.test.mjs new file mode 100644 index 0000000..1d69015 --- /dev/null +++ b/viewer/tests/pins.test.mjs @@ -0,0 +1,51 @@ +import './_planet.mjs'; +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { filterPins, loreWarning, pinPayload, epochIds } from '../js/pins.js'; + +const pins = [ + { id: 'pin-1', name: 'Zeta ford', lat: 1, lon: 2, lore: null, note: 'shallow crossing' }, + { id: 'pin-2', name: 'alpha peak', lat: 3, lon: 4, lore: 'physical-world', note: '' }, + { id: 'pin-3', name: 'Mid Lake', lat: 5, lon: 6, lore: null, note: '' }, +]; + +test('search: name, lore id and note, case-insensitive; sorted by name', () => { + assert.deepEqual(filterPins(pins, '').map(p => p.id), ['pin-2', 'pin-3', 'pin-1']); + assert.deepEqual(filterPins(pins, 'PEAK').map(p => p.id), ['pin-2']); + assert.deepEqual(filterPins(pins, 'physical').map(p => p.id), ['pin-2']); + assert.deepEqual(filterPins(pins, 'crossing').map(p => p.id), ['pin-1']); + assert.deepEqual(filterPins(pins, 'nothing'), []); + assert.equal(pins[0].id, 'pin-1', 'input not reordered'); +}); + +test('lore warning only for unknown ids', () => { + assert.equal(loreWarning('', ['a']), null); + assert.equal(loreWarning('a', ['a']), null); + assert.match(loreWarning('b-c', ['a']), /not a known lore id/); +}); + +test('payload trims and turns an empty lore id into null', () => { + assert.deepEqual(pinPayload({ name: ' Ford ', lat: 1, lon: 2, lore: ' ', note: ' x ', id: 'pin-9', cell: 'c' }), + { name: 'Ford', lat: 1, lon: 2, lore: null, note: 'x', epoch: null }); +}); + +test('a draft marker shows while the new-pin form is open', async () => { + const { FakeEl, installFakeDom } = await import('./fakedom.mjs'); + installFakeDom(); + const { PinsPanel } = await import('../js/pins.js'); + const drafts = []; + const p = new PinsPanel(new FakeEl('section'), [], { onPins() {}, onFly() {}, onPlacing() {}, onDraft: d => drafts.push(d) }); + p.placeAt({ lat: 1, lon: 2 }); + assert.deepEqual(drafts.at(-1), { lat: 1, lon: 2 }); + p.box.find(e => e.tag === 'button' && e.textContent === 'Cancel').fire('click'); + assert.equal(drafts.at(-1), null); +}); + +test('payload carries the epoch and numeric coordinates', () => { + assert.deepEqual(pinPayload({ name: 'X', lat: '-15.5', lon: '-34.2', lore: 'cell-am-zee', note: '', epoch: 'epoch-high-fantasy' }), + { name: 'X', lat: -15.5, lon: -34.2, lore: 'cell-am-zee', note: '', epoch: 'epoch-high-fantasy' }); +}); + +test('epoch choices come from the lore ids', () => { + assert.deepEqual(epochIds(['a', 'epoch-high-fantasy', 'epochs', 'epoch-space-age']), ['epoch-high-fantasy', 'epoch-space-age']); +}); |
