aboutsummaryrefslogtreecommitdiffziptar.gz
path: root/viewer/tests/vents.test.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'viewer/tests/vents.test.mjs')
-rw-r--r--viewer/tests/vents.test.mjs27
1 files changed, 27 insertions, 0 deletions
diff --git a/viewer/tests/vents.test.mjs b/viewer/tests/vents.test.mjs
new file mode 100644
index 0000000..78d3386
--- /dev/null
+++ b/viewer/tests/vents.test.mjs
@@ -0,0 +1,27 @@
+import './_planet.mjs';
+import { test } from 'node:test';
+import assert from 'node:assert/strict';
+import { clusterVents, ventText, zoomBucket } from '../js/vents.js';
+
+const V = (lat, lon, type = 0) => ({ lat, lon, type, temp_c: 350, flow: 2, mineral: type });
+
+test('far apart: one marker each; close together: one cluster with a count', () => {
+ const vents = [V(0, 0), V(0.01, 0.01), V(10, 10)];
+ const fine = clusterVents(vents, 0.01); // 40 px ≈ 0.4 km: nothing merges
+ assert.equal(fine.length, 3);
+ assert.ok(fine.every(c => c.n === 1 && c.v));
+ const coarse = clusterVents(vents, 10); // 40 px ≈ 400 km
+ assert.equal(coarse.length, 2);
+ const big = coarse.find(c => c.n === 2);
+ assert.ok(big && Math.abs(big.lat - 0.005) < 1e-9);
+});
+
+test('hover text names type, temperature and mineral', () => {
+ const t = ventText(V(0, 0, 0), ['black smoker', 'white smoker'], ['copper-iron sulfides', 'zinc sulfides and barite']);
+ assert.equal(t, 'black smoker · 350 °C · copper-iron sulfides · strong flow');
+});
+
+test('zoom buckets change every ×1.5', () => {
+ assert.equal(zoomBucket(1), zoomBucket(1.2));
+ assert.notEqual(zoomBucket(1), zoomBucket(1.6));
+});