mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 09:42:21 +00:00
Review fixes for #1781: - One rule for cards: the world-overlay host hands its hit test to the pick registry, and every click handler reads the topmost interactive card or label once per click (`clickCard`, `isUnderOtherCard` in src/data/pickRegistry.js), so all handlers agree in any listener order. A layer whose own card or label is on top acts on it whatever is drawn under it; a layer under another layer's card neither acts nor treats the click as empty space (a tracked aircraft stays tracked, a selection stays selected); Context names nothing under a card. A selected news card over a vessel no longer opens the link and selects the vessel. - With one rule, the per-owner arbitration options are no longer read and are removed: `passive`, `expanded` and `declinesClick` pick owners, `rememberClickPickActions`, `isActedOnByOtherLayer`, card backgrounds and `cardKeepsClick`. The dispatcher is unchanged from main. - A drag that ends on a quake disc, label or card does nothing; opening the USGS page or clearing the selection needs a clean click. - A click on the map under another layer's card opens no Street Level ground image. - A CCTV card that is going away is still not the scene under it. - Docs and changelog describe the new rule.
221 lines
5.7 KiB
JavaScript
221 lines
5.7 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { createControls as bikeshareControls } from '../layers/bikeshare/controls.js';
|
|
import { createControls as launchControls } from '../layers/launches/controls.js';
|
|
import { createControls as installationControls } from '../layers/installations/controls.js';
|
|
import { createQueries as transitQueries } from '../layers/transit/queries.js';
|
|
import { createCyclonesLayer } from '../layers/cyclones/index.js';
|
|
import { ANALYST_LAYERS } from '../data/analystEngine.js';
|
|
import { fakeInput } from '../input/testDoubles.mjs';
|
|
|
|
/** Every declared analyst field must be a key the accessor actually emits. */
|
|
function assertDeclaredFields(layerId, record) {
|
|
const layer = ANALYST_LAYERS[layerId];
|
|
for (const field of [
|
|
...layer.numeric,
|
|
...layer.text,
|
|
...layer.flags,
|
|
...layer.time,
|
|
])
|
|
assert.ok(Object.hasOwn(record, field), `${layerId} record lacks ${field}`);
|
|
assert.equal(typeof record.lat, 'number');
|
|
assert.equal(typeof record.lon, 'number');
|
|
}
|
|
|
|
test('bikeshare stations join coordinates from station information', () => {
|
|
const state = {
|
|
_enabled: true,
|
|
_stationRenderMap: new Map([
|
|
[
|
|
'austin:1',
|
|
{
|
|
cityId: 'austin',
|
|
stationId: '1',
|
|
stationName: 'Congress',
|
|
bikesAvailable: 4,
|
|
docksAvailable: 6,
|
|
capacity: 10,
|
|
isRenting: true,
|
|
},
|
|
],
|
|
[
|
|
'austin:2',
|
|
{
|
|
cityId: 'austin',
|
|
stationId: '2',
|
|
stationName: 'No coordinates',
|
|
bikesAvailable: 1,
|
|
},
|
|
],
|
|
]),
|
|
_stationInfoCache: new Map([
|
|
['austin', new Map([['1', { lat: 30.27, lon: -97.74 }]])],
|
|
]),
|
|
};
|
|
const { methods } = bikeshareControls({ state, parts: {} });
|
|
const rows = methods.getAnalystRecords();
|
|
assert.equal(
|
|
rows.length,
|
|
1,
|
|
'a station without coordinates is not countable',
|
|
);
|
|
assert.deepEqual(rows[0], {
|
|
id: 'Congress',
|
|
name: 'Congress',
|
|
city: 'austin',
|
|
lat: 30.27,
|
|
lon: -97.74,
|
|
bikesAvailable: 4,
|
|
docksAvailable: 6,
|
|
capacity: 10,
|
|
renting: true,
|
|
});
|
|
assertDeclaredFields('bikeshare', rows[0]);
|
|
state._enabled = false;
|
|
assert.deepEqual(methods.getAnalystRecords(), []);
|
|
});
|
|
|
|
test('launches carry time and hours until launch at the world time', () => {
|
|
const now = Date.UTC(2026, 10, 1);
|
|
const at = now + 5 * 3_600_000;
|
|
const state = {
|
|
now: () => now,
|
|
_enabled: true,
|
|
_launches: [
|
|
{
|
|
id: 'L1',
|
|
name: 'Falcon 9 | Starlink',
|
|
provider: 'SpaceX',
|
|
status: 'Go',
|
|
launchSite: 'SLC-40',
|
|
missionName: 'Starlink',
|
|
lat: 28.56,
|
|
lon: -80.58,
|
|
launchTime: new Date(at).toISOString(),
|
|
},
|
|
],
|
|
};
|
|
const { methods } = launchControls({ state, parts: {} });
|
|
const [row] = methods.getAnalystRecords();
|
|
assert.equal(row.launchTimeMs, at);
|
|
assert.equal(row.hoursUntil, 5);
|
|
assertDeclaredFields('rocket-launches', row);
|
|
});
|
|
|
|
test('mapped installations flatten latitude/longitude', () => {
|
|
const state = {
|
|
enabled: true,
|
|
records: [
|
|
{
|
|
id: 'node/1',
|
|
name: 'Fort Example',
|
|
class: 'military_land',
|
|
kind: 'installation',
|
|
latitude: 31,
|
|
longitude: -97,
|
|
},
|
|
],
|
|
};
|
|
const { methods } = installationControls({ state, parts: {} });
|
|
const [row] = methods.getAnalystRecords();
|
|
assert.deepEqual(row, {
|
|
id: 'Fort Example',
|
|
name: 'Fort Example',
|
|
class: 'military_land',
|
|
kind: 'installation',
|
|
lat: 31,
|
|
lon: -97,
|
|
});
|
|
assertDeclaredFields('military-installations', row);
|
|
});
|
|
|
|
test('transit vehicles report their last fix, mode and route', () => {
|
|
const state = {
|
|
_enabled: true,
|
|
_vehicles: new Map([
|
|
[
|
|
'cap:1',
|
|
{
|
|
key: 'cap:1',
|
|
mode: 'bus',
|
|
courseDeg: 90,
|
|
record: {
|
|
id: '1',
|
|
label: '2554',
|
|
routeId: '335',
|
|
lat: 30.2,
|
|
lon: -97.7,
|
|
speedMps: 8,
|
|
status: 'IN_TRANSIT_TO',
|
|
occupancy: null,
|
|
},
|
|
},
|
|
],
|
|
]),
|
|
};
|
|
const { methods } = transitQueries({ state, parts: {} });
|
|
const [row] = methods.getAnalystRecords();
|
|
assert.equal(row.id, '2554');
|
|
assert.equal(row.mode, 'bus');
|
|
assertDeclaredFields('transit', row);
|
|
});
|
|
|
|
test('cyclones flatten the storm position and stay empty while off', async () => {
|
|
const storm = {
|
|
id: 'al052026',
|
|
name: 'Fay',
|
|
classification: 'TS',
|
|
basin: 'AL',
|
|
position: { latitude: 29.8, longitude: -40 },
|
|
windKt: 35,
|
|
pressureHpa: 1010,
|
|
issuedAt: '2026-09-23T00:00:00Z',
|
|
forecastPoints: [],
|
|
track: null,
|
|
cone: null,
|
|
};
|
|
const layer = createCyclonesLayer({
|
|
feed: {
|
|
getSnapshot: async () => ({
|
|
schemaVersion: 1,
|
|
storms: [storm],
|
|
unavailable: false,
|
|
stale: false,
|
|
fetchedAt: Date.now(),
|
|
}),
|
|
},
|
|
cesium: {},
|
|
createRendering: () => ({
|
|
setSnapshot: async () => true,
|
|
setSelection() {},
|
|
clear() {},
|
|
destroy() {},
|
|
pickStorm: () => null,
|
|
ownsPickId: () => false,
|
|
getDiagnostics: () => ({}),
|
|
}),
|
|
});
|
|
const viewer = {
|
|
scene: { canvas: new EventTarget(), pick: () => null },
|
|
camera: {},
|
|
};
|
|
const input = fakeInput(viewer);
|
|
layer.init(viewer);
|
|
assert.deepEqual(layer.getAnalystRecords(), []);
|
|
layer.enable();
|
|
await layer.update();
|
|
const [row] = layer.getAnalystRecords();
|
|
assert.deepEqual(row, {
|
|
id: 'Fay',
|
|
name: 'Fay',
|
|
classification: 'TS',
|
|
basin: 'AL',
|
|
lat: 29.8,
|
|
lon: -40,
|
|
windKt: 35,
|
|
pressureHpa: 1010,
|
|
});
|
|
assertDeclaredFields('weather-cyclones', row);
|
|
layer.destroy?.();
|
|
});
|