mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-21 02:32:18 +00:00
A drifting touch tap or a cockpit-mode tap on a fire, quake or vessel card
beside an aircraft did nothing: the cards deferred to the aircraft, whose
click handler ignores such taps. Pick owners can now declare the clicks
they ignore (registerPickOwner(..., { declinesClick })); flights and
military decline a drag or a cockpit tap and CCTV declines any click that
is not clean, so a card over them keeps that tap.
Also from review:
- the selected quake's contour rings sit on the ground the disc is draped
on, re-read through the heights service while they paint;
- a label's fly-to frames the whole disc for large quakes;
- a quake that ages out of the feed clears its selection as evicted;
- id-less quakes are named by their content, not their row;
- the Bhote Koshi trigger-record callout opens its source on a click, as
its keyboard action does, and yields like the other cards;
- the card's place line is cut to 48 characters, its link hint shows only
with an opener, and its accessible name carries depth, place and time; a
link-less card's click and keyboard action fly to the quake;
- camera trace comparison scales its tolerance with the value and wraps
heading and roll.
287 lines
7.4 KiB
JavaScript
287 lines
7.4 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import { normalizeEarthquakeSnapshot } from './records.js';
|
|
|
|
test('normalizeEarthquakeSnapshot parses valid GeoJSON earthquake features', () => {
|
|
const geojson = {
|
|
type: 'FeatureCollection',
|
|
features: [
|
|
{
|
|
id: 'us7000m123',
|
|
type: 'Feature',
|
|
geometry: {
|
|
type: 'Point',
|
|
coordinates: [-122.4194, 37.7749, 10.5],
|
|
},
|
|
properties: {
|
|
mag: 4.2,
|
|
place: 'San Francisco Bay Area, CA',
|
|
time: 1711929600000,
|
|
},
|
|
},
|
|
],
|
|
};
|
|
|
|
const rows = normalizeEarthquakeSnapshot(geojson);
|
|
assert.equal(Array.isArray(rows), true);
|
|
assert.equal(rows.length, 1);
|
|
assert.deepEqual(rows[0], {
|
|
stableId: 'us7000m123',
|
|
usgsId: 'us7000m123',
|
|
lon: -122.4194,
|
|
lat: 37.7749,
|
|
depthKm: 10.5,
|
|
mag: 4.2,
|
|
place: 'San Francisco Bay Area, CA',
|
|
time: 1711929600000,
|
|
});
|
|
});
|
|
|
|
test('normalizeEarthquakeSnapshot names id-less events by their content, not their row', () => {
|
|
const geojson = {
|
|
features: [
|
|
{
|
|
id: null,
|
|
geometry: { type: 'Point', coordinates: [139.6917, 35.6895, 25.0] },
|
|
properties: { mag: 3.5, place: 'Tokyo, Japan', time: 1711930000000 },
|
|
},
|
|
{
|
|
id: '',
|
|
geometry: { type: 'Point', coordinates: [-70.6693, -33.4489, 45.2] },
|
|
properties: { mag: 5.1, place: 'Santiago, Chile', time: 1711931000000 },
|
|
},
|
|
],
|
|
};
|
|
|
|
const rows = normalizeEarthquakeSnapshot(geojson);
|
|
assert.equal(rows.length, 2);
|
|
assert.equal(rows[0].stableId, 'event-1711930000000:139.6917:35.6895:25:3.5');
|
|
assert.equal(rows[0].usgsId, null);
|
|
assert.equal(
|
|
rows[1].stableId,
|
|
'event-1711931000000:-70.6693:-33.4489:45.2:5.1',
|
|
);
|
|
assert.equal(rows[1].usgsId, '');
|
|
// A row inserted ahead of them keeps each id-less quake's id, so a selected
|
|
// one stays selected across the refresh.
|
|
const inserted = normalizeEarthquakeSnapshot({
|
|
features: [
|
|
{
|
|
id: 'us7000new',
|
|
geometry: { type: 'Point', coordinates: [10, 20, 5] },
|
|
properties: { mag: 4, place: 'New', time: 1711932000000 },
|
|
},
|
|
...geojson.features,
|
|
],
|
|
});
|
|
assert.deepEqual(
|
|
inserted.map((row) => row.stableId).slice(1),
|
|
rows.map((row) => row.stableId),
|
|
);
|
|
// Two id-less events that match exactly stay apart.
|
|
const twins = normalizeEarthquakeSnapshot({
|
|
features: [geojson.features[0], geojson.features[0]],
|
|
});
|
|
assert.equal(twins.length, 2);
|
|
assert.notEqual(twins[0].stableId, twins[1].stableId);
|
|
});
|
|
|
|
test('normalizeEarthquakeSnapshot filters events below M2.5 without dropping the feed', () => {
|
|
const geojson = {
|
|
features: [
|
|
{
|
|
id: 'ev-sub',
|
|
geometry: { type: 'Point', coordinates: [10, 20, 5] },
|
|
properties: { mag: 2.49, place: 'Minor tremor' },
|
|
},
|
|
{
|
|
id: 'ev-null-mag',
|
|
geometry: { type: 'Point', coordinates: [11, 21, 5] },
|
|
properties: { mag: null, place: 'Uncalculated' },
|
|
},
|
|
{
|
|
id: 'ev-threshold',
|
|
geometry: { type: 'Point', coordinates: [12, 22, 5] },
|
|
properties: { mag: 2.5, place: 'Threshold event' },
|
|
},
|
|
{
|
|
id: 'ev-strong',
|
|
geometry: { type: 'Point', coordinates: [13, 23, 5] },
|
|
properties: { mag: 6.8, place: 'Major event' },
|
|
},
|
|
],
|
|
};
|
|
|
|
const rows = normalizeEarthquakeSnapshot(geojson);
|
|
assert.equal(rows.length, 2);
|
|
assert.equal(rows[0].stableId, 'ev-threshold');
|
|
assert.equal(rows[0].mag, 2.5);
|
|
assert.equal(rows[1].stableId, 'ev-strong');
|
|
assert.equal(rows[1].mag, 6.8);
|
|
});
|
|
|
|
test('normalizeEarthquakeSnapshot normalizes optional fields to null when omitted or invalid', () => {
|
|
const geojson = {
|
|
features: [
|
|
{
|
|
id: 'ev-sparse',
|
|
geometry: { coordinates: [-100, 40] }, // depth omitted
|
|
properties: { mag: 3.0, place: 12345, time: 'invalid' }, // place not string, time not number
|
|
},
|
|
],
|
|
};
|
|
|
|
const rows = normalizeEarthquakeSnapshot(geojson);
|
|
assert.equal(rows.length, 1);
|
|
assert.equal(rows[0].depthKm, null);
|
|
assert.equal(rows[0].place, null);
|
|
assert.equal(rows[0].time, null);
|
|
});
|
|
|
|
test('normalizeEarthquakeSnapshot returns null for malformed structures or non-array features', () => {
|
|
assert.equal(normalizeEarthquakeSnapshot(null), null);
|
|
assert.equal(normalizeEarthquakeSnapshot(undefined), null);
|
|
assert.equal(normalizeEarthquakeSnapshot({}), null);
|
|
assert.equal(normalizeEarthquakeSnapshot({ features: 'not-an-array' }), null);
|
|
assert.equal(normalizeEarthquakeSnapshot({ features: null }), null);
|
|
});
|
|
|
|
test('normalizeEarthquakeSnapshot returns null for invalid geometries or out-of-range coordinates', () => {
|
|
const baseFeature = {
|
|
id: 'test',
|
|
geometry: { type: 'Point', coordinates: [0, 0, 0] },
|
|
properties: { mag: 3.0 },
|
|
};
|
|
|
|
// Non-Point geometry
|
|
assert.equal(
|
|
normalizeEarthquakeSnapshot({
|
|
features: [
|
|
{
|
|
...baseFeature,
|
|
geometry: {
|
|
type: 'LineString',
|
|
coordinates: [
|
|
[0, 0],
|
|
[1, 1],
|
|
],
|
|
},
|
|
},
|
|
],
|
|
}),
|
|
null,
|
|
);
|
|
|
|
// Missing or short coordinates
|
|
assert.equal(
|
|
normalizeEarthquakeSnapshot({
|
|
features: [
|
|
{ ...baseFeature, geometry: { type: 'Point', coordinates: [0] } },
|
|
],
|
|
}),
|
|
null,
|
|
);
|
|
|
|
// Longitude out of range [-180, 180]
|
|
assert.equal(
|
|
normalizeEarthquakeSnapshot({
|
|
features: [
|
|
{
|
|
...baseFeature,
|
|
geometry: { type: 'Point', coordinates: [180.1, 0, 0] },
|
|
},
|
|
],
|
|
}),
|
|
null,
|
|
);
|
|
assert.equal(
|
|
normalizeEarthquakeSnapshot({
|
|
features: [
|
|
{
|
|
...baseFeature,
|
|
geometry: { type: 'Point', coordinates: [-180.1, 0, 0] },
|
|
},
|
|
],
|
|
}),
|
|
null,
|
|
);
|
|
|
|
// Latitude out of range [-90, 90]
|
|
assert.equal(
|
|
normalizeEarthquakeSnapshot({
|
|
features: [
|
|
{
|
|
...baseFeature,
|
|
geometry: { type: 'Point', coordinates: [0, 90.1, 0] },
|
|
},
|
|
],
|
|
}),
|
|
null,
|
|
);
|
|
assert.equal(
|
|
normalizeEarthquakeSnapshot({
|
|
features: [
|
|
{
|
|
...baseFeature,
|
|
geometry: { type: 'Point', coordinates: [0, -90.1, 0] },
|
|
},
|
|
],
|
|
}),
|
|
null,
|
|
);
|
|
|
|
// Non-finite depth
|
|
assert.equal(
|
|
normalizeEarthquakeSnapshot({
|
|
features: [
|
|
{
|
|
...baseFeature,
|
|
geometry: { type: 'Point', coordinates: [0, 0, NaN] },
|
|
},
|
|
],
|
|
}),
|
|
null,
|
|
);
|
|
|
|
// Magnitude > 10
|
|
assert.equal(
|
|
normalizeEarthquakeSnapshot({
|
|
features: [{ ...baseFeature, properties: { mag: 10.1 } }],
|
|
}),
|
|
null,
|
|
);
|
|
|
|
// Non-object or array properties
|
|
assert.equal(
|
|
normalizeEarthquakeSnapshot({
|
|
features: [{ ...baseFeature, properties: 'invalid' }],
|
|
}),
|
|
null,
|
|
);
|
|
assert.equal(
|
|
normalizeEarthquakeSnapshot({
|
|
features: [{ ...baseFeature, properties: [] }],
|
|
}),
|
|
null,
|
|
);
|
|
});
|
|
|
|
test('normalizeEarthquakeSnapshot returns null when feed contains duplicate IDs', () => {
|
|
const geojson = {
|
|
features: [
|
|
{
|
|
id: 'duplicate-id',
|
|
geometry: { type: 'Point', coordinates: [0, 0, 0] },
|
|
properties: { mag: 3.0 },
|
|
},
|
|
{
|
|
id: 'duplicate-id',
|
|
geometry: { type: 'Point', coordinates: [1, 1, 1] },
|
|
properties: { mag: 4.0 },
|
|
},
|
|
],
|
|
};
|
|
|
|
assert.equal(normalizeEarthquakeSnapshot(geojson), null);
|
|
});
|