aboutsummaryrefslogtreecommitdiffziptar.gz
path: root/viewer/tests/inspector.test.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'viewer/tests/inspector.test.mjs')
-rw-r--r--viewer/tests/inspector.test.mjs30
1 files changed, 30 insertions, 0 deletions
diff --git a/viewer/tests/inspector.test.mjs b/viewer/tests/inspector.test.mjs
new file mode 100644
index 0000000..ea9c456
--- /dev/null
+++ b/viewer/tests/inspector.test.mjs
@@ -0,0 +1,30 @@
+import './_planet.mjs';
+import { test } from 'node:test';
+import assert from 'node:assert/strict';
+import { groupFields, fmtValue } from '../js/inspector.js';
+
+test('fields grouped in order of first appearance', () => {
+ const g = groupFields([{ key: 'a', group: 'Terrain' }, { key: 'b', group: 'Climate' }, { key: 'c', group: 'Terrain' }]);
+ assert.deepEqual([...g.keys()], ['Terrain', 'Climate']);
+ assert.deepEqual(g.get('Terrain').map(f => f.key), ['a', 'c']);
+});
+
+test('values: text wins; large numbers rounded with separators; small ones to 2 decimals', () => {
+ assert.equal(fmtValue({ value: 3, text: 'Boreal moist forest', unit: '' }), 'Boreal moist forest');
+ assert.equal(fmtValue({ value: 1234.5, unit: 'm' }), '1,235 m');
+ assert.equal(fmtValue({ value: -3.456, unit: '°C' }), '-3.46 °C');
+ assert.equal(fmtValue({ value: 0.2, unit: '' }), '0.2');
+});
+
+test('inspect asks for the era and shows its label', async () => {
+ const { installFakeDom, FakeEl } = await import('./fakedom.mjs');
+ installFakeDom();
+ const { inspect } = await import('../js/inspector.js');
+ const box = new FakeEl('div');
+ let asked = null;
+ globalThis.fetch = async url => { asked = url; return { ok: true, status: 200, json: async () => ({
+ lat: 1, lon: 2, cell: '84', era: { name: 'high-fantasy', label: 'High Fantasy' }, fields: [] }) }; };
+ await inspect(box, { lat: 1, lon: 2 }, 'high-fantasy');
+ assert.match(asked, /&era=high-fantasy$/);
+ assert.match(box.textContent, /High Fantasy/);
+});