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/hover.test.mjs | |
| download | worldmap-viewer-3443c1c65e9f1753e1e656b35d08416c1fa298f2.tar.gz worldmap-viewer-3443c1c65e9f1753e1e656b35d08416c1fa298f2.zip | |
worldmap-viewer: initial public history
Diffstat (limited to 'viewer/tests/hover.test.mjs')
| -rw-r--r-- | viewer/tests/hover.test.mjs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/viewer/tests/hover.test.mjs b/viewer/tests/hover.test.mjs new file mode 100644 index 0000000..7b26be5 --- /dev/null +++ b/viewer/tests/hover.test.mjs @@ -0,0 +1,30 @@ +import './_planet.mjs'; +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { hoverText } from '../js/hover.js'; + +const cell = fields => ({ cell: 'x', lat: 0, lon: 0, fields }); + +test('land shows elevation and life zone', () => { + assert.equal(hoverText(cell([{ key: 'z_surface_m', value: 2344.4 }, { key: 'ocean', value: false, text: 'no' }, + { key: 'lake', value: false, text: 'no' }, { key: 'holdridge', value: 3, text: 'cool temperate desert scrub' }])), + '2,344 m · cool temperate desert scrub'); +}); + +test('sea shows depth; lakes are named; procedural detail only when tiles show', () => { + assert.equal(hoverText(cell([{ key: 'z_surface_m', value: -3300 }, { key: 'ocean', value: true, text: 'yes' }])), 'sea, 3,300 m deep'); + assert.equal(hoverText(cell([{ key: 'z_surface_m', value: 120 }, { key: 'ocean', value: false }, { key: 'lake', value: true }, + { key: 'holdridge', value: 1, text: 'boreal moist forest' }])), '120 m · lake · boreal moist forest'); + const both = cell([{ key: 'z_surface_m', value: 120 }, { key: 'z_detail_m', value: 131.6 }, { key: 'ocean', value: false }]); + assert.equal(hoverText(both), '120 m', 'zoomed out: the build value'); + assert.equal(hoverText(both, true), '132 m', 'procedural tiles showing: the detail value'); +}); + +test('a cell answer is reused near its centre, never under procedural detail', async () => { + const { canReuse } = await import('../js/hover.js'); + const c = { center: [10, 20], inner_km: 50 }; + assert.equal(canReuse(c, { lat: 10.1, lon: 20 }, false), true); + assert.equal(canReuse(c, { lat: 11, lon: 20 }, false), false); + assert.equal(canReuse(c, { lat: 10.1, lon: 20 }, true), false); + assert.equal(canReuse(null, { lat: 10, lon: 20 }, false), false); +}); |
