From 2b5bbeb74e1d29d3e1ebbb0a2a9d04849956c2d7 Mon Sep 17 00:00:00 2001 From: Bilawal Sidhu Date: Tue, 15 Sep 2026 11:06:25 -0500 Subject: [PATCH] style: adopt analyst tests under current formatting policy --- scripts/format-scope.json | 5 +- src/data/localGeojson.analyst.test.mjs | 115 +++++++++++++++++-------- src/data/satellites.analyst.test.mjs | 38 ++++++-- 3 files changed, 108 insertions(+), 50 deletions(-) diff --git a/scripts/format-scope.json b/scripts/format-scope.json index 0021faebc..9b7bab3d5 100644 --- a/scripts/format-scope.json +++ b/scripts/format-scope.json @@ -382,10 +382,9 @@ "src/layers/launches/model.js", "src/layers/launches/selection.js", "src/layers/launches/camera.js", - "src/layers/satellites/records.js", - "src/data/layerSnapshot.js", + "src/data/localGeojson.analyst.test.mjs", + "src/data/satellites.analyst.test.mjs", "src/data/layerSnapshot.test.mjs", - "src/data/satellitePass.js", "src/data/satellitePass.test.mjs", "src/data/satellites.js", "src/data/rocketLaunches.js", diff --git a/src/data/localGeojson.analyst.test.mjs b/src/data/localGeojson.analyst.test.mjs index d1cc74343..061a7f27c 100644 --- a/src/data/localGeojson.analyst.test.mjs +++ b/src/data/localGeojson.analyst.test.mjs @@ -2,10 +2,7 @@ import { test } from 'node:test'; import assert from 'node:assert/strict'; import * as Cesium from 'cesium'; -import { - createLocalGeoJsonLayer, - mapAnalystRecord, -} from './localGeojson.js'; +import { createLocalGeoJsonLayer, mapAnalystRecord } from './localGeojson.js'; const DC_RAW = { id: '1176042553', @@ -63,12 +60,15 @@ test('infra analyst record: dam maps name, operator, river, output; names stay u }); test('infra analyst record: unnamed feature falls back to source id', () => { - const r = mapAnalystRecord({ - id: 'dc-42', - lat: 30.2, - lon: -97.7, - properties: { tags: { operator: 'Example Cloud' } }, - }, 'local-datacenters'); + const r = mapAnalystRecord( + { + id: 'dc-42', + lat: 30.2, + lon: -97.7, + properties: { tags: { operator: 'Example Cloud' } }, + }, + 'local-datacenters', + ); assert.equal(r.id, 'dc-42'); assert.equal(r.name, null); assert.equal(r.operator, 'Example Cloud'); @@ -79,16 +79,20 @@ test('infra analyst record: empty record yields nulls, never NaN/undefined', () assert.equal(r.id, 'Dam'); for (const [key, value] of Object.entries(r)) { assert.notEqual(value, undefined, `${key} must not be undefined`); - if (typeof value === 'number') assert.ok(Number.isFinite(value), `${key} must not be NaN`); + if (typeof value === 'number') + assert.ok(Number.isFinite(value), `${key} must not be NaN`); } }); test('infra analyst record: output is JSON-safe (no Cesium types leak)', () => { - const r = mapAnalystRecord({ - ...DAM_RAW, - entity: {}, - position: { x: 1 }, - }, 'local-dams'); + const r = mapAnalystRecord( + { + ...DAM_RAW, + entity: {}, + position: { x: 1 }, + }, + 'local-dams', + ); assert.deepEqual(JSON.parse(JSON.stringify(r)), r); assert.equal('entity' in r, false); assert.equal('position' in r, false); @@ -112,25 +116,37 @@ test('infra getAnalystRecords: enabled layer snapshots loaded stems; disable ret globalThis.fetch = async () => ({ ok: true, status: 200, - text: async () => JSON.stringify({ - type: 'Feature', - id: 'runtime-dam', - properties: { - name: 'Runtime Dam', - output: '12 MW', - tags: { associated_river: 'Test River', operator: 'Test Hydro' }, - }, - geometry: { - type: 'Polygon', - coordinates: [[[-97.70, 30.20], [-97.69, 30.20], [-97.69, 30.21], [-97.70, 30.20]]], - }, - }), + text: async () => + JSON.stringify({ + type: 'Feature', + id: 'runtime-dam', + properties: { + name: 'Runtime Dam', + output: '12 MW', + tags: { associated_river: 'Test River', operator: 'Test Hydro' }, + }, + geometry: { + type: 'Polygon', + coordinates: [ + [ + [-97.7, 30.2], + [-97.69, 30.2], + [-97.69, 30.21], + [-97.7, 30.2], + ], + ], + }, + }), }); const viewer = { selectedEntity: undefined, dataSources: { - add(dataSource) { return dataSource; }, - remove() { return true; }, + add(dataSource) { + return dataSource; + }, + remove() { + return true; + }, }, camera: { positionWC: Cesium.Cartesian3.fromDegrees(-97.695, 30.205, 100_000), @@ -142,9 +158,13 @@ test('infra getAnalystRecords: enabled layer snapshots loaded stems; disable ret canvas: { clientWidth: 800, clientHeight: 600 }, preRender: new MockLayerEvent(), sampleHeightSupported: false, - sampleHeight() { return undefined; }, + sampleHeight() { + return undefined; + }, screenSpaceCameraController: { enableInputs: true }, - pick() { return null; }, + pick() { + return null; + }, requestRender() {}, }, }; @@ -155,10 +175,17 @@ test('infra getAnalystRecords: enabled layer snapshots loaded stems; disable ret color: '#0088ff', overlayHost: { setVisible() {}, setEntries() {}, clearSource() {} }, projectToWindow: () => ({ x: 400, y: 300 }), - screenSpaceEventHandlerFactory: () => ({ setInputAction() {}, destroy() {} }), + screenSpaceEventHandlerFactory: () => ({ + setInputAction() {}, + destroy() {}, + }), }); try { - assert.deepEqual(layer.getAnalystRecords(), [], 'unenabled layer has no analyst records'); + assert.deepEqual( + layer.getAnalystRecords(), + [], + 'unenabled layer has no analyst records', + ); await layer.enable(viewer); const rows = layer.getAnalystRecords(); assert.equal(rows.length, 1); @@ -169,13 +196,25 @@ test('infra getAnalystRecords: enabled layer snapshots loaded stems; disable ret assert.equal(rows[0].output, '12 MW'); assert.ok(Number.isFinite(rows[0].lat) && Number.isFinite(rows[0].lon)); assert.deepEqual(JSON.parse(JSON.stringify(rows[0])), rows[0]); - assert.equal(layer.getAnalystRecords(0).length, 1, 'non-finite/zero cap still returns at least one'); + assert.equal( + layer.getAnalystRecords(0).length, + 1, + 'non-finite/zero cap still returns at least one', + ); layer.disable(viewer); - assert.deepEqual(layer.getAnalystRecords(), [], 'disable keeps stems but analyst snapshot is empty'); + assert.deepEqual( + layer.getAnalystRecords(), + [], + 'disable keeps stems but analyst snapshot is empty', + ); } finally { layer.destroy(viewer); - assert.deepEqual(layer.getAnalystRecords(), [], 'destroy releases analyst records'); + assert.deepEqual( + layer.getAnalystRecords(), + [], + 'destroy releases analyst records', + ); globalThis.fetch = originalFetch; if (originalWindow === undefined) delete globalThis.window; else globalThis.window = originalWindow; diff --git a/src/data/satellites.analyst.test.mjs b/src/data/satellites.analyst.test.mjs index 708781422..9f1e9bd3f 100644 --- a/src/data/satellites.analyst.test.mjs +++ b/src/data/satellites.analyst.test.mjs @@ -11,8 +11,10 @@ import satellitesLayer, { const ISS_NORAD = 25544; -const ISS_L1 = '1 25544U 98067A 08264.51782528 -.00002182 00000-0 -11606-4 0 2927'; -const ISS_L2 = '2 25544 51.6416 247.4627 0006703 130.5360 325.0288 15.72125391563537'; +const ISS_L1 = + '1 25544U 98067A 08264.51782528 -.00002182 00000-0 -11606-4 0 2927'; +const ISS_L2 = + '2 25544 51.6416 247.4627 0006703 130.5360 325.0288 15.72125391563537'; const FULL_RAW = { noradId: 25544, @@ -70,12 +72,17 @@ test('satellite analyst record: empty record yields nulls, never NaN/undefined', assert.equal(r.satelliteClass, null); for (const [key, value] of Object.entries(r)) { assert.notEqual(value, undefined, `${key} must not be undefined`); - if (typeof value === 'number') assert.ok(Number.isFinite(value), `${key} must not be NaN`); + if (typeof value === 'number') + assert.ok(Number.isFinite(value), `${key} must not be NaN`); } }); test('satellite analyst record: output is JSON-safe (no Cesium types leak)', () => { - const r = mapAnalystRecord({ ...FULL_RAW, position: { x: 1 }, satrec: { dummy: true } }); + const r = mapAnalystRecord({ + ...FULL_RAW, + position: { x: 1 }, + satrec: { dummy: true }, + }); assert.deepEqual(JSON.parse(JSON.stringify(r)), r); assert.equal('position' in r, false); assert.equal('satrec' in r, false); @@ -88,7 +95,9 @@ test('satellite getAnalystRecords: disabled or empty catalog returns []', () => test('satellite getAnalystRecords: core rows beat dense extras under the cap', () => { const satrec = twoline2satrec(ISS_L1, ISS_L2); - const point = { position: Cesium.Cartesian3.fromDegrees(-97.7, 30.2, 420_000) }; + const point = { + position: Cesium.Cartesian3.fromDegrees(-97.7, 30.2, 420_000), + }; _setTrackedSatelliteRefreshStateForTest({ noradId: ISS_NORAD, name: 'ISS (ZARYA)', @@ -110,22 +119,33 @@ test('satellite getAnalystRecords: core rows beat dense extras under the cap', ( name: 'GPS BIIR-2', satrec, group: 'gps-ops', - point: { position: Cesium.Cartesian3.fromDegrees(-100, 10, 20_200_000) }, + point: { + position: Cesium.Cartesian3.fromDegrees(-100, 10, 20_200_000), + }, }, ], }); try { const capped = satellitesLayer.getAnalystRecords(2); assert.equal(capped.length, 2); - assert.deepEqual(capped.map((r) => r.noradId), ['25544', '24876']); - assert.equal(capped.some((r) => r.group === 'dense'), false); + assert.deepEqual( + capped.map((r) => r.noradId), + ['25544', '24876'], + ); + assert.equal( + capped.some((r) => r.group === 'dense'), + false, + ); const all = satellitesLayer.getAnalystRecords(10); assert.equal(all.length, 3); assert.equal(all[2].noradId, '99999'); assert.equal(all[2].satelliteClass, 'COMMS ยท STARLINK'); for (const row of all) { - assert.ok(Number.isFinite(row.lat) && Number.isFinite(row.lon), `${row.id} needs a geodetic position`); + assert.ok( + Number.isFinite(row.lat) && Number.isFinite(row.lon), + `${row.id} needs a geodetic position`, + ); assert.deepEqual(JSON.parse(JSON.stringify(row)), row); } } finally {