mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 01:02:23 +00:00
Each layer now has one render/display.js on the globe contract, the same factory on both engines; its render/cesium* and render/navara* files go. Cesium's behaviour is the reference, and the logic that was written twice is written once: - AIS vessels: atlas chevrons and engine.lines trails. The display registers the gev-trail pick claim itself and its trailing visibility pass now also runs on Navara. - Satellites: point banks per look, orbit rings as lines turned by their model matrix, and selection and follow through engine.camera.follow. The emulated _viewer is gone, and the tracked readout republishes card text on Navara too. - Space Missions: dots, reticle, trajectories and tactical orbits as movers and lines. The layer keeps its own records instead of Entities and DataSources, and camera work goes through engine.camera. Clicks go through the selection dispatcher, and hover keeps Cesium's throttle. The pad zone is its rim only: the contract has no surface fill yet. - ALPR, bikeshare and OSM Places: one display and, for bikeshare, one style module each; clicks through engine.input, no ScreenSpaceEventHandler or EntityCluster. ALPR keeps Navara's horizon cull, and OSM Places points sample the surface where Cesium clamped them. Coupling: layer renderer lines fall from 4546/11106 to 2638/8735 (Cesium/Navara), `viewer` lines from 2209 to 2014, ScreenSpaceEventHandler files from 20 to 15.
209 lines
7.1 KiB
JavaScript
209 lines
7.1 KiB
JavaScript
import { DEFAULT_AIS_RUNTIME } from './policy.js';
|
|
|
|
export function createTesting({
|
|
vesselState,
|
|
services,
|
|
parts: components,
|
|
layer,
|
|
options,
|
|
}) {
|
|
const { state } = vesselState;
|
|
const aisLiveVesselsLayer = layer;
|
|
|
|
/**
|
|
* Bind the production interaction callbacks to mockable viewer/handler
|
|
* surfaces. Test-only seam; behavior is shared with installInteraction().
|
|
* @param {Object} viewer - Viewer-like object with scene.pick().
|
|
* @param {Object} handler - Handler-like object with setInputAction().
|
|
* @param {Object} keyTarget - EventTarget-like object with add/removeEventListener().
|
|
* @returns {void}
|
|
*/
|
|
|
|
function _bindVesselInteractionForTest(viewer, handler, keyTarget) {
|
|
components.selection.bindVesselInteraction(viewer, handler, keyTarget);
|
|
}
|
|
|
|
/**
|
|
* Prime the minimum live state needed by interaction/lifecycle wire tests.
|
|
* @param {Object} [options={}] - Test state values; `renderer` is the
|
|
* test's renderer factory `({ viewer, billboardCollection }) => renderer`.
|
|
* @returns {void}
|
|
*/
|
|
|
|
function _setVesselStateForTest(options = {}) {
|
|
components.lifecycle.resetState();
|
|
const records = Array.isArray(options.records) ? options.records : [];
|
|
state.viewer = options.viewer || null;
|
|
state.feed.enabled = options.enabled !== false;
|
|
state.feed.loaded = options.loaded === true;
|
|
state.feed.loading = options.loading === true;
|
|
state.feed.stale = options.stale === true;
|
|
state.feed.partial = options.partial === true;
|
|
state.feed.error = options.error || null;
|
|
state.feed.lastUpdate = options.lastUpdate ?? null;
|
|
state.records.all = records;
|
|
state.feed.count = records.length;
|
|
state.records.byMmsi = new Map(
|
|
records
|
|
.filter((record) => record?.mmsi)
|
|
.map((record) => [record.mmsi, record]),
|
|
);
|
|
state.selectedRecord = options.selectedRecord || null;
|
|
// The test's renderer over its viewer and collection
|
|
// (testSupport/vesselViewerRenderer), else the layer's for `engine`.
|
|
state.renderer =
|
|
typeof options.renderer === 'function'
|
|
? options.renderer({
|
|
viewer: state.viewer,
|
|
billboardCollection: options.billboardCollection || {
|
|
remove() {},
|
|
},
|
|
})
|
|
: (services.renderer?.create({
|
|
viewer: state.viewer,
|
|
engine: options.engine ?? null,
|
|
}) ?? null);
|
|
state.trail = options.trail || null;
|
|
state.trailMmsi = options.trailMmsi || null;
|
|
state.trailPositions = Array.isArray(options.trailPositions)
|
|
? [...options.trailPositions]
|
|
: [];
|
|
state.feed.transportStatus = options.transportStatus || null;
|
|
state.feed.lastMessageAt = options.lastMessageAt ?? null;
|
|
state.feed.rawRowCount = Number.isFinite(options.rawRowCount)
|
|
? options.rawRowCount
|
|
: 0;
|
|
state.feed.acceptedRowCount = Number.isFinite(options.acceptedRowCount)
|
|
? options.acceptedRowCount
|
|
: records.length;
|
|
state.feed.firstConnectPhase = options.firstConnectPhase || 'idle';
|
|
state.feed.firstConnectStartedAt = options.firstConnectStartedAt ?? null;
|
|
state.feed.firstConnectDeadline = options.firstConnectDeadline ?? null;
|
|
state.interactionHandlerFactory = options.interactionHandlerFactory || null;
|
|
state.interactionKeyTarget = options.interactionKeyTarget || null;
|
|
}
|
|
|
|
/** Inject a host recorder for lifecycle/contract tests; null restores production. */
|
|
|
|
function _setVesselOverlayHostForTest(host = null) {
|
|
vesselState._vesselOverlayHost =
|
|
host || vesselState.DEFAULT_VESSEL_OVERLAY_HOST;
|
|
}
|
|
|
|
/** Exercise the production selector/publisher through a test-owned state. */
|
|
|
|
function _updateVesselCardsForTest(records = []) {
|
|
components.rendering.updateClusteredLabels(records);
|
|
}
|
|
|
|
/**
|
|
* Reconcile AIS rows through the production lifecycle. Test-only seam.
|
|
* @param {Object} viewer - Viewer-like object.
|
|
* @param {Array<Object>} rows - Raw AIS rows.
|
|
* @returns {void}
|
|
*/
|
|
|
|
function _reconcileVesselsForTest(viewer, rows) {
|
|
components.snapshots.reconcileVessels(viewer, rows);
|
|
}
|
|
|
|
/** Apply one server snapshot through the production pre-reconcile health gate. */
|
|
|
|
function _applyAisFeedSnapshotForTest(viewer, payload) {
|
|
return components.ingestion.applyAisFeedSnapshot(viewer, payload);
|
|
}
|
|
|
|
/** Exercise the request-owned live loader with a test-controlled fetch. */
|
|
|
|
function _loadLivePositionsForTest(viewer) {
|
|
return components.ingestion.loadLivePositions(viewer);
|
|
}
|
|
|
|
/** Start the production first-connect grace state without installing UI. */
|
|
|
|
function _beginAisSessionForTest() {
|
|
components.lifecycle.beginAisSession();
|
|
}
|
|
|
|
/** Inject a deterministic clock/scheduler; null restores production runtime. */
|
|
|
|
function _setAisRuntimeForTest(runtime = null) {
|
|
components.lifecycle.clearFirstConnectTimer();
|
|
vesselState._aisRuntime = runtime
|
|
? {
|
|
now: runtime.now,
|
|
setTimeout: runtime.setTimeout,
|
|
clearTimeout: runtime.clearTimeout,
|
|
}
|
|
: DEFAULT_AIS_RUNTIME;
|
|
}
|
|
|
|
/** Read feed-health fields without exposing mutable production state. */
|
|
|
|
function _getVesselFeedStateForTest() {
|
|
const stats = aisLiveVesselsLayer.getStats();
|
|
return {
|
|
count: state.feed.count,
|
|
loaded: state.feed.loaded,
|
|
loading: stats.loading,
|
|
loadingLabel: stats.loadingLabel,
|
|
stale: state.feed.stale,
|
|
error: state.feed.error,
|
|
status: stats.status,
|
|
lastUpdate: state.feed.lastUpdate,
|
|
transportStatus: state.feed.transportStatus,
|
|
lastMessageAt: state.feed.lastMessageAt,
|
|
rawRowCount: state.feed.rawRowCount,
|
|
acceptedRowCount: state.feed.acceptedRowCount,
|
|
selectedMmsi: state.selectedRecord?.mmsi || null,
|
|
trailMmsi: state.trailMmsi,
|
|
trailPositionCount: state.trailPositions.length,
|
|
sessionId: state.feed.sessionId,
|
|
firstConnectPhase: state.feed.firstConnectPhase,
|
|
firstConnectStartedAt: state.feed.firstConnectStartedAt,
|
|
firstConnectDeadline: state.feed.firstConnectDeadline,
|
|
};
|
|
}
|
|
|
|
/** Run one preRender visibility/focus pass. Test-only seam. */
|
|
|
|
function _runVisibilityPassForTest(force = false) {
|
|
components.rendering.updateVisibility(force);
|
|
}
|
|
|
|
/** True while a trailing visibility frame is scheduled. Test-only seam. */
|
|
|
|
function _hasTrailingVisibilityPassForTest() {
|
|
return state.trailingVisibilityTimer !== null;
|
|
}
|
|
|
|
/**
|
|
* Read lifecycle ownership state without exposing the mutable state object.
|
|
* Test-only seam.
|
|
* @returns {{trailMmsi: string|null, trailPositionCount: number, vesselCount: number}}
|
|
*/
|
|
|
|
function _getVesselStateForTest() {
|
|
return {
|
|
trailMmsi: state.trailMmsi,
|
|
trailPositionCount: state.trailPositions.length,
|
|
vesselCount: state.records.byMmsi.size,
|
|
};
|
|
}
|
|
return {
|
|
_bindVesselInteractionForTest,
|
|
_setVesselStateForTest,
|
|
_setVesselOverlayHostForTest,
|
|
_updateVesselCardsForTest,
|
|
_reconcileVesselsForTest,
|
|
_applyAisFeedSnapshotForTest,
|
|
_loadLivePositionsForTest,
|
|
_beginAisSessionForTest,
|
|
_setAisRuntimeForTest,
|
|
_getVesselFeedStateForTest,
|
|
_getVesselStateForTest,
|
|
_runVisibilityPassForTest,
|
|
_hasTrailingVisibilityPassForTest,
|
|
};
|
|
}
|