aboutsummaryrefslogtreecommitdiffziptar.gz
path: root/viewer/tests/searchbox.test.mjs
diff options
context:
space:
mode:
authorgodosa <godosa@godosa.eu>2026-10-07 00:14:38 +0200
committergodosa <godosa@godosa.eu>2026-10-07 00:14:38 +0200
commit3443c1c65e9f1753e1e656b35d08416c1fa298f2 (patch)
tree4e43236f460145a4d75d1b4616dcb7aa6ef08f51 /viewer/tests/searchbox.test.mjs
downloadworldmap-viewer-3443c1c65e9f1753e1e656b35d08416c1fa298f2.tar.gz
worldmap-viewer-3443c1c65e9f1753e1e656b35d08416c1fa298f2.zip
worldmap-viewer: initial public history
Diffstat (limited to 'viewer/tests/searchbox.test.mjs')
-rw-r--r--viewer/tests/searchbox.test.mjs65
1 files changed, 65 insertions, 0 deletions
diff --git a/viewer/tests/searchbox.test.mjs b/viewer/tests/searchbox.test.mjs
new file mode 100644
index 0000000..bdf79b1
--- /dev/null
+++ b/viewer/tests/searchbox.test.mjs
@@ -0,0 +1,65 @@
+import './_planet.mjs';
+import { test } from 'node:test';
+import assert from 'node:assert/strict';
+import { FakeEl, installFakeDom } from './fakedom.mjs';
+
+installFakeDom();
+const { SearchBox } = await import('../js/searchbox.js');
+const tick = () => new Promise(r => setTimeout(r, 0));
+
+function box(pins = [], locate = async () => ({ lat: 1, lon: 2 })) {
+ const input = new FakeEl('input'), list = new FakeEl('div'), went = [];
+ new SearchBox(input, list, { pins: () => pins, locate, go: r => went.push(r) });
+ return { input, list, went };
+}
+
+test('typing suggests; Enter flies to coordinates with a marker', async () => {
+ const { input, list, went } = box();
+ input.value = '40N 10W';
+ input.fire('input');
+ assert.equal(list.hidden, false);
+ assert.equal(list.kids.length, 1);
+ input.fire('keydown', { key: 'Enter' });
+ await tick();
+ assert.deepEqual([went[0].lat, went[0].lon, went[0].marker], [40, -10, true]);
+ assert.equal(list.hidden, true);
+});
+
+test('arrows move the selection; pins fly without a marker', async () => {
+ const pins = [{ name: 'Alpha', lat: 3, lon: 4, lore: null, note: '' }, { name: 'Alpine', lat: 5, lon: 6, lore: null, note: '' }];
+ const { input, list, went } = box(pins);
+ input.value = 'alp';
+ input.fire('input');
+ assert.equal(list.kids.length, 2);
+ input.fire('keydown', { key: 'ArrowDown' });
+ assert.match(list.kids[1].className, /sel/);
+ input.fire('keydown', { key: 'Enter' });
+ await tick();
+ assert.deepEqual([went[0].lat, went[0].lon, went[0].marker], [5, 6, false]);
+});
+
+test('cell ids go through the server; failures are reported', async () => {
+ const ok = box([], async cell => ({ cell, lat: -20, lon: 100 }));
+ ok.input.value = '8528308ffffffff';
+ ok.input.fire('input');
+ ok.input.fire('keydown', { key: 'Enter' });
+ await tick();
+ assert.deepEqual([ok.went[0].lat, ok.went[0].lon], [-20, 100]);
+ const bad = box([], async () => { throw new Error('nope'); });
+ bad.input.value = '8528308ffffffff';
+ bad.input.fire('input');
+ bad.input.fire('keydown', { key: 'Enter' });
+ await tick();
+ assert.equal(bad.went[0].error, 'nope');
+});
+
+test('Esc closes the list; junk shows nothing', () => {
+ const { input, list } = box();
+ input.value = '95 10';
+ input.fire('input');
+ assert.equal(list.hidden, true);
+ input.value = '40N 10W';
+ input.fire('input');
+ input.fire('keydown', { key: 'Escape' });
+ assert.equal(list.hidden, true);
+});