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/); });