Files
gods-eye-view/src/ui/shellLifetime.test.mjs
T
German Khokhlov 7f478e3815 Remove always-true layer availability and leftover viewer paths
Every layer draws on both engines, so the per-engine availability
machinery always answered yes. The renderer manifest is now the id to
display map plus the wind flow backend; the catalog filter, the voice and
QA-probe refusals and the engine-kind checks go with it. The Navara
notice lists the same layers in the same words.

Paths that read the Cesium viewer behind an engine that is always there
are gone: the Recent Imagery viewer fallbacks, the shell's imagery-host
service (one shared host module remains), the engineless map controller,
viewer gates in voice actions, world packets and camera verbs, the
orientation controls' tracked-entity fallback, and the Bhote Koshi and
FIRMS Cesium-shaped paths. setCameraInputs, which nothing called, leaves
the contract; suspensions remain.

Smaller duplicates go too: one tracker-release helper for navigation and
location, the no-op frame latch, missing-engine guards, one name for the
injected display, flat bikeshare and installations displays, one overlay
host and binder, one name per world-overlay method, and stub-viewer
guards in the Cesium engine. Layers that still read the viewer keep the
shared init(viewer, context) entry.

Behaviour is unchanged on both engines. Viewer lines fall from 849 to
750 and engine-name literals from 32 to 27.
2026-11-08 17:06:01 +04:00

177 lines
6.3 KiB
JavaScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { LocationNavigation } from './locationNavigation.js';
import { createFakeEngine } from '../globe/testing/fakeEngine.js';
import { LayerBindings } from './layerBindings.js';
function replaceWindow(t, value) {
const previous = Object.getOwnPropertyDescriptor(globalThis, 'window');
Object.defineProperty(globalThis, 'window', { configurable: true, writable: true, value });
t.after(() => {
if (previous) Object.defineProperty(globalThis, 'window', previous);
else delete globalThis.window;
});
}
function location(t) {
t.mock.timers.enable({ apis: ['setTimeout'] });
replaceWindow(t, { setTimeout });
const calls = [];
let hooks;
const engine = createFakeEngine({ altitude: 20000000 });
const owner = new LocationNavigation({
engine,
services: {
OrbitController: class { stop() { calls.push('orbit-stop'); } },
GLOBE_VIEW: { heightM: 20000000 },
flyToGlobeView(_viewer, callbacks) { hooks = callbacks; return {}; },
interruptCameraMotion() {},
militaryAwarenessLayer: {}, satellitesLayer: {}, rocketLaunchesLayer: {},
trafficLayer: {
beginWorldJump() { calls.push('begin'); },
endWorldJump() { calls.push('end'); },
},
suspendDetection() { calls.push('suspend'); },
resumeDetection() { calls.push('resume'); },
},
elements: {}, navigation: {}, readCockpit: () => null,
operations: {
_stampNavigation() {}, _updateTrafficSyncChip() {},
_runExplicitNavigation(_noun, run) { return run(); },
},
});
return { owner, calls, readHooks: () => hooks };
}
test('shell disposal settles a pending globe reset once and revokes its timeout', async (t) => {
const { owner, calls, readHooks } = location(t);
const pending = owner.resetToGlobeView();
assert.equal(owner.resetToGlobeView(), pending);
owner.destroy();
assert.equal((await pending).cancelled, true);
const after = [...calls];
readHooks().onComplete();
t.mock.timers.tick(10000);
owner.destroy();
assert.deepEqual(calls, after);
assert.equal(calls.filter(c => c === 'resume').length, 1);
assert.equal((await owner.resetToGlobeView()).cancelled, true);
});
test('world jump completion cannot revive navigation after shell disposal', (t) => {
const { owner, calls } = location(t);
let complete;
owner._flyWithTransition(true, ({ onStart, onComplete }) => {
onStart(); complete = onComplete;
});
owner.destroy();
const after = [...calls];
complete();
t.mock.timers.tick(10000);
assert.deepEqual(calls, after);
assert.equal(calls.filter(c => c === 'resume').length, 1);
});
function bindings(t) {
replaceWindow(t, new EventTarget());
const events = [];
const controls = {
hud: { attachDataManager() {} },
_contextControls: { connect() {} },
_cctvControls: { connect() {} }, _radioControls: { connect() {} },
_streetLevelControls: { connects: 0, connect() { this.connects += 1; } },
};
const owner = new LayerBindings({
viewer: {}, services: {}, readControls: () => controls,
feedback: {}, shareRestoration: { connect() {} },
operations: {
_updateTrafficSyncChip() {}, _updateGlobalLoadingFeedback() {},
_syncContextModeButtons() {},
},
});
function manager(id, directions = true) {
return {
layers: new Map(directions ? [['directions', { module: {
attachShellServices(value) { events.push([id, value ? 'attach' : 'detach']); },
} }]] : []),
subscribe() { events.push([id, 'subscribe']); return () => events.push([id, 'unsubscribe']); },
};
}
return { owner, manager, events, controls };
}
test('manager replacement releases Directions even when the new manager has no route layer', (t) => {
const { owner, manager, events } = bindings(t);
owner.attachDataManager(manager('old'));
owner.attachDataManager(manager('new', false));
assert.deepEqual(events, [
['old', 'subscribe'], ['old', 'attach'], ['old', 'unsubscribe'],
['new', 'subscribe'], ['old', 'detach'],
]);
owner.stop(); owner.disconnect();
assert.deepEqual(events.at(-1), ['new', 'unsubscribe']);
const count = events.length;
owner.attachDataManager(manager('late'));
owner.stop(); owner.disconnect();
assert.equal(events.length, count);
});
test('attaching the manager reconnects Street Level, so its switch-on requests reach the panel', (t) => {
const { owner, manager, controls } = bindings(t);
owner.attachDataManager(manager('first'));
assert.equal(controls._streetLevelControls.connects, 1);
owner.stop(); owner.disconnect();
});
test('camera-entry listeners are removed before any asynchronous layer cleanup', (t) => {
const { owner } = bindings(t);
let changes = 0;
let trackedCallback;
owner.engine = { camera: { followChanged: {
addEventListener(callback) {
trackedCallback = callback;
return () => { changes += 1; };
},
} } };
owner._stampNavigation = () => { changes += 100; };
owner.observeCamera();
owner.stop();
trackedCallback({});
owner.stop();
assert.equal(changes, 1);
});
test('weather shell supplies navigation to wind and observations and releases it', (t) => {
const { owner } = bindings(t);
const attached = new Map();
const ids = ['wind', 'weather-radar', 'weather-satellite', 'weather-lightning'];
owner.attachDataManager({
layers: new Map(ids.map(id => [id, { module: {
attachShellServices(services) { attached.set(id, services); },
} }])),
subscribe: () => () => {},
});
for (const id of ids) assert.equal(typeof attached.get(id).runNavigation, 'function');
owner.disconnect();
for (const id of ids) assert.equal(attached.get(id), null);
});
test('world focus uses the engine when the shell has no Cesium viewer', async (t) => {
const { requestWorldFocus } = await import('../worldFocus.js');
replaceWindow(t, new EventTarget());
const engine = createFakeEngine();
let target;
engine.camera.flyToSphere = (sphere) => { target = sphere.center; };
const owner = new LayerBindings({
viewer: null, engine, services: {}, readControls: () => ({}),
operations: { _runExplicitWorldFocus: (_detail, fly) => fly() },
});
owner.observeCamera();
const position = { x: 6378137, y: 0, z: 0 };
requestWorldFocus({ kind: 'vessel', id: '111', position });
assert.deepEqual(target, position);
owner.stop();
});