Undo the reformatting of four camera-slice tests

The camera-port commits ran prettier over four test files that were
never prettier-formatted. Restore their earlier text and keep only the
camera-port edits.
This commit is contained in:
Sameh Khamis committed 2026-11-06 09:55:05 -08:00
1 parent bc69e8a4ee
commit 68855b2089
4 files changed
+804 -2266

No files matched your search

+146 -320
View File
@@ -1,13 +1,7 @@
import { LayerBindings } from './ui/layerBindings.js';
import {
readShellSource,
shellMethod,
} from './testSupport/readShellSource.mjs';
import { readShellSource, shellMethod } from './testSupport/readShellSource.mjs';
import { readLayerSource } from './testSupport/readLayerSource.mjs';
import {
enter as cockpitEnter,
navigateContext,
} from './ui/cockpitTrackingController.js';
import { enter as cockpitEnter, navigateContext } from './ui/cockpitTrackingController.js';
import { CockpitViewController } from './ui/cockpitController.js';
import assert from 'node:assert/strict';
import fs from 'node:fs';
@@ -17,24 +11,11 @@ import { fileURLToPath } from 'node:url';
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const ui = readShellSource();
const firms = readLayerSource(
path.join(ROOT, 'src', 'data', 'firmsHeatmap.js'),
);
const vessels = readLayerSource(
path.join(ROOT, 'src', 'data', 'aisLiveVessels.js'),
);
const voice = fs.readFileSync(
path.join(ROOT, 'src', 'voice', 'gevActions.js'),
'utf8',
);
const cameraVerbs = fs.readFileSync(
path.join(ROOT, 'src', 'cameraVerbs.js'),
'utf8',
);
const cockpitTracking = fs.readFileSync(
path.join(ROOT, 'src', 'cockpitTracking.js'),
'utf8',
);
const firms = readLayerSource(path.join(ROOT, 'src', 'data', 'firmsHeatmap.js'));
const vessels = readLayerSource(path.join(ROOT, 'src', 'data', 'aisLiveVessels.js'));
const voice = fs.readFileSync(path.join(ROOT, 'src', 'voice', 'gevActions.js'), 'utf8');
const cameraVerbs = fs.readFileSync(path.join(ROOT, 'src', 'cameraVerbs.js'), 'utf8');
const cockpitTracking = fs.readFileSync(path.join(ROOT, 'src', 'cockpitTracking.js'), 'utf8');
function body(source, pattern, label) {
const name = pattern.source.match(/^(\w+)/)?.[1];
@@ -50,14 +31,8 @@ function body(source, pattern, label) {
function ordered(source, needles, label) {
let previous = -1;
for (const needle of needles) {
const match =
needle instanceof RegExp ? needle.exec(source.slice(previous + 1)) : null;
const index =
needle instanceof RegExp
? match
? previous + 1 + match.index
: -1
: source.indexOf(needle, previous + 1);
const match = needle instanceof RegExp ? needle.exec(source.slice(previous + 1)) : null;
const index = needle instanceof RegExp ? (match ? previous + 1 + match.index : -1) : source.indexOf(needle, previous + 1);
assert.ok(index >= 0, `${label}: missing ${needle}`);
assert.ok(index > previous, `${label}: ${needle} is out of order`);
previous = index;
@@ -66,16 +41,12 @@ function ordered(source, needles, label) {
test('Cockpit takeover invalidates deferred work before camera cancellation', () => {
const enter = cockpitEnter.toString();
ordered(
enter,
[
'if (!info || !entity?.position) return false;',
'this.onCameraTakeover?.();',
'cameraOf(this.viewer).cancelFlight();',
'this.viewer.trackedEntity = undefined;',
],
'Cockpit takeover',
);
ordered(enter, [
'if (!info || !entity?.position) return false;',
'this.onCameraTakeover?.();',
'cameraOf(this.viewer).cancelFlight();',
'this.viewer.trackedEntity = undefined;',
], 'Cockpit takeover');
assert.match(
ui,
/onCameraTakeover: \(\) =>\s*this\._stampNavigation\(\{\s*cancelPendingSelection: false,?\s*\}\),/,
@@ -109,23 +80,11 @@ test('navigation clears dormant tracker IDs without aborting unrelated layer res
);
assert.doesNotMatch(stamp, /cancelPendingRestores\(\)/);
assert.match(stamp, /flightsLayer\.cancelPendingTrackingRestore\?\.\(\)/);
assert.match(
stamp,
/militaryFlightsLayer\.cancelPendingTrackingRestore\?\.\(\)/,
);
assert.match(stamp, /militaryFlightsLayer\.cancelPendingTrackingRestore\?\.\(\)/);
assert.match(stamp, /satellitesLayer\.cancelPendingTrackingRestore\?\.\(\)/);
assert.match(
stamp,
/if \(\s*!passivelyClearedShareSelection\s*&&\s*!flightsLayer\.getTrackedInfo\?\.\(\)\s*\)[\s\S]*?selectedFlightsTrackingId: null/,
);
assert.match(
stamp,
/if \(\s*!passivelyClearedShareSelection\s*&&\s*!militaryFlightsLayer\.getTrackedInfo\?\.\(\)\s*\)[\s\S]*?selectedMilitaryTrackingId: null/,
);
assert.match(
stamp,
/if \(\s*!passivelyClearedShareSelection\s*&&\s*!satellitesLayer\.getTrackedInfo\?\.\(\)\s*\)[\s\S]*?selectedSatTrackingId: null/,
);
assert.match(stamp, /if \(\s*!passivelyClearedShareSelection\s*&&\s*!flightsLayer\.getTrackedInfo\?\.\(\)\s*\)[\s\S]*?selectedFlightsTrackingId: null/);
assert.match(stamp, /if \(\s*!passivelyClearedShareSelection\s*&&\s*!militaryFlightsLayer\.getTrackedInfo\?\.\(\)\s*\)[\s\S]*?selectedMilitaryTrackingId: null/);
assert.match(stamp, /if \(\s*!passivelyClearedShareSelection\s*&&\s*!satellitesLayer\.getTrackedInfo\?\.\(\)\s*\)[\s\S]*?selectedSatTrackingId: null/);
});
test('voice Cockpit entry reaches the camera only through stamping seams', () => {
@@ -145,14 +104,10 @@ test('voice Cockpit entry reaches the camera only through stamping seams', () =>
/export function enterCockpitWithTracking\(\{[\s\S]*?\n\}\) \{([\s\S]*?)\n\}\n/,
'Cockpit entry transaction',
);
ordered(
transaction,
[
/if \(\s*!selectedLayer\.trackById\?\.\(selectedTarget\.id, \{\s*origin: selectionOrigin,?\s*\}\)\s*\) \{/,
'if (!entryError) entered = Boolean(cockpitView.enter());',
],
'Cockpit entry transaction',
);
ordered(transaction, [
/if \(\s*!selectedLayer\.trackById\?\.\(selectedTarget\.id, \{\s*origin: selectionOrigin,?\s*\}\)\s*\) \{/,
'if (!entryError) entered = Boolean(cockpitView.enter());',
], 'Cockpit entry transaction');
// No direct camera control: every mutation goes through a layer tracker or
// the cockpit controller, both of which stamp.
assert.doesNotMatch(transaction, /\b(?:viewer\.)?camera\s*(?:\.|\[|=)/);
@@ -191,41 +146,27 @@ test('voice Cockpit next/previous shares the manual Context navigation path', ()
/this\._listen\(this\.contextNext, 'click', \(\) =>\s*this\.navigateContext\(1, \{ origin: 'user' \}\),?\s*\);/,
);
const funnel = navigateContext.toString();
assert.match(
funnel,
/const navigationOptions = wasActive\s*\? \{ \.\.\.options, aircraftOnly: true \}\s*: options;/,
);
ordered(
funnel,
[
"const method = direction < 0 ? 'navigatePrevious' : 'navigateNext';",
'const navigationOptions = wasActive',
'militaryAwarenessLayer?.[method]?.(navigationOptions)',
'this._adoptTrackedEntity(performance.now());',
],
'Cockpit Context navigation funnel',
);
assert.match(funnel, /const navigationOptions = wasActive\s*\? \{ \.\.\.options, aircraftOnly: true \}\s*: options;/);
ordered(funnel, [
"const method = direction < 0 ? 'navigatePrevious' : 'navigateNext';",
'const navigationOptions = wasActive',
'militaryAwarenessLayer?.[method]?.(navigationOptions)',
'this._adoptTrackedEntity(performance.now());',
], 'Cockpit Context navigation funnel');
const navigate = body(
ui,
/if \(normalized === 'next' \|\| normalized === 'previous'\) \{([\s\S]*?)\n \}/,
'controlCockpit navigation branch',
);
ordered(
navigate,
['this.cockpitView.navigateContext(', "normalized === 'next' ? 1 : -1,"],
'controlCockpit navigation branch',
);
ordered(navigate, [
'this.cockpitView.navigateContext(',
"normalized === 'next' ? 1 : -1,",
], 'controlCockpit navigation branch');
// No private camera route around the awareness layer.
assert.doesNotMatch(
navigate,
/flyTo|camera|trackById|_runExplicitNavigation/,
);
assert.doesNotMatch(navigate, /flyTo|camera|trackById|_runExplicitNavigation/);
// An exhausted cohort is an honest failure, not a silent success.
assert.match(navigate, /ok: changed,/);
assert.match(
navigate,
/error: changed \? null : 'No further context target was available',/,
);
assert.match(navigate, /error: changed \? null : 'No further context target was available',/);
});
test('accepted navigation releases through PR15-aware ownership before flight', () => {
@@ -234,69 +175,37 @@ test('accepted navigation releases through PR15-aware ownership before flight',
/_runExplicitNavigation\(noun, navigate, releaseOptions = undefined\) \{([\s\S]*?)\n \}/,
'explicit navigation',
);
ordered(
run,
[
'cockpitActive: this.isCockpitActive()',
'stamp: () => this._stampNavigation()',
'release: () => this._releaseFollowCamera(releaseOptions)',
'navigate,',
],
'explicit navigation',
);
ordered(run, [
'cockpitActive: this.isCockpitActive()',
'stamp: () => this._stampNavigation()',
'release: () => this._releaseFollowCamera(releaseOptions)',
'navigate,',
], 'explicit navigation');
const release = body(
ui,
/_releaseFollowCamera\(\{[\s\S]*?\} = \{\}\) \{([\s\S]*?)\n \}/,
'follow release',
);
ordered(
release,
[
'origin: trackingOrigin',
'satellitesLayer.stopTracking?.({ origin: trackingOrigin })',
'rocketLaunchesLayer.releaseCameraOwnership?.()',
'this.viewer.trackedEntity = undefined;',
"interruptCameraMotion('explicit-navigation')",
'this.viewer.camera.cancelFlight();',
'this.viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);',
],
'follow release',
);
assert.match(
release,
/flightsLayer\.stopTracking\?\.\(\{ origin: trackingOrigin \}\)/,
);
assert.match(
release,
/militaryFlightsLayer\.stopTracking\?\.\(\{ origin: trackingOrigin \}\)/,
);
ordered(release, [
'origin: trackingOrigin',
'satellitesLayer.stopTracking?.({ origin: trackingOrigin })',
'rocketLaunchesLayer.releaseCameraOwnership?.()',
'this.viewer.trackedEntity = undefined;',
"interruptCameraMotion('explicit-navigation')",
'this.viewer.camera.cancelFlight();',
'this.viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);',
], 'follow release');
assert.match(release, /flightsLayer\.stopTracking\?\.\(\{ origin: trackingOrigin \}\)/);
assert.match(release, /militaryFlightsLayer\.stopTracking\?\.\(\{ origin: trackingOrigin \}\)/);
});
test('validated voice camera destinations share the UI navigation authority facade', () => {
assert.match(
ui,
/runImmediateNavigation\(noun, navigate, releaseOptions = undefined\) \{\s*return this\._runExplicitNavigation\(noun, navigate, releaseOptions\);/,
);
assert.match(
voice,
/runManagedVoiceNavigation\(\s*styleManager,\s*'camera',\s*'move_camera',\s*navigate,\s*releaseOptions/,
);
assert.match(
voice,
/runManagedVoiceNavigation\(\s*styleManager,\s*'route',\s*'fly_route',\s*navigate/,
);
assert.match(
voice,
/runManagedVoiceNavigation\(\s*styleManager,\s*'fire',\s*'track_entity'/,
);
assert.match(
voice,
/runManagedVoiceNavigation\(\s*styleManager,\s*family\.kind,\s*'track_entity'/,
);
assert.match(
voice,
/runManagedVoiceNavigation\(\s*styleManager,\s*'frame',\s*'frame_overhead'/,
);
assert.match(ui, /runImmediateNavigation\(noun, navigate, releaseOptions = undefined\) \{\s*return this\._runExplicitNavigation\(noun, navigate, releaseOptions\);/);
assert.match(voice, /runManagedVoiceNavigation\(\s*styleManager,\s*'camera',\s*'move_camera',\s*navigate,\s*releaseOptions/);
assert.match(voice, /runManagedVoiceNavigation\(\s*styleManager,\s*'route',\s*'fly_route',\s*navigate/);
assert.match(voice, /runManagedVoiceNavigation\(\s*styleManager,\s*'fire',\s*'track_entity'/);
assert.match(voice, /runManagedVoiceNavigation\(\s*styleManager,\s*family\.kind,\s*'track_entity'/);
assert.match(voice, /runManagedVoiceNavigation\(\s*styleManager,\s*'frame',\s*'frame_overhead'/);
const trackedVoice = voice.slice(
voice.indexOf('async function trackEntity'),
voice.indexOf('async function frameOverhead'),
@@ -313,80 +222,47 @@ test('validated voice camera destinations share the UI navigation authority faca
/export function moveCamera\(args = \{\}, runNavigation = null\) \{([\s\S]*?)\n\}/,
'move camera',
);
ordered(
move,
[
"if (!['orbit', 'pan', 'tilt', 'rotate', 'rotate_globe'].includes(motion))",
'const start = () => {',
/const preserveCameraFlight =\s*motion === 'orbit'/,
'runNavigation(start, { preserveCameraFlight })',
],
'move validation before handoff',
);
ordered(move, [
"if (!['orbit', 'pan', 'tilt', 'rotate', 'rotate_globe'].includes(motion))",
'const start = () => {',
/const preserveCameraFlight =\s*motion === 'orbit'/,
'runNavigation(start, { preserveCameraFlight })',
], 'move validation before handoff');
const route = body(
cameraVerbs,
/export function flyRoute\(\s*annoList,\s*args = \{\},\s*floorFn = null,\s*runNavigation = null,\s*warmFn = null,?\s*\) \{([\s\S]*?)\n\}/,
'fly route',
);
ordered(
route,
[
'if (!routes.length)',
'const pts = route.path.map',
'const start = () => {',
/return typeof runNavigation === 'function'\s*\? runNavigation\(start\)\s*: start\(\);/,
],
'route validation before handoff',
);
ordered(route, [
'if (!routes.length)',
'const pts = route.path.map',
'const start = () => {',
/return typeof runNavigation === 'function'\s*\? runNavigation\(start\)\s*: start\(\);/,
], 'route validation before handoff');
// The corridor warm is injected the same way the floor READ is — the dolly
// never reaches into the data layer itself, and the voice dispatch is the one
// place that binds both.
assert.match(
voice,
/\(lat, lon\) => floorServices\.cachedGroundFloor\(lat, lon\),[\s\S]{0,200}?\(cells\) => floorServices\.warmGroundFloor\(cells\),/,
);
assert.match(voice, /\(lat, lon\) => floorServices\.cachedGroundFloor\(lat, lon\),[\s\S]{0,200}?\(cells\) => floorServices\.warmGroundFloor\(cells\),/);
});
test('deferred search releases only after its final authority check', () => {
const search = fs.readFileSync(
path.join(ROOT, 'src', 'ui', 'locationSearch.js'),
'utf8',
);
ordered(
search,
[
'const authority = this.begin();',
'this.onStart?.(authority);',
'await this.search(query',
'beforeFly: () => current() && this.beforeFly(authority)',
'if (!current() || controller.signal.aborted) return;',
'destination?.cancelled',
'finally',
'this.onSettled?.(authority)',
],
'deferred search component',
);
assert.match(
ui,
/begin: \(\) => this\._beginDeferredNavigation\('location'\)/,
);
assert.match(
ui,
/beforeFly: \(generation\) => this\._reassertNavigationHandoff\(generation\)/,
);
assert.match(
ui,
/isCurrent: \(generation\) =>\s*!this\._disposed && generation === this\._navigationGeneration/,
);
assert.match(
ui,
/change\.type === 'settled'\)\s*this\._settleLocationSearchUi\(change\.generation, \{\s*keepQuery: state\.status === 'missing' \|\| state\.status === 'failed',?\s*\}\)/,
);
assert.doesNotMatch(
search.slice(0, search.indexOf('await this.search')),
/_releaseFollowCamera/,
);
const search = fs.readFileSync(path.join(ROOT, 'src', 'ui', 'locationSearch.js'), 'utf8');
ordered(search, [
'const authority = this.begin();',
'this.onStart?.(authority);',
'await this.search(query',
'beforeFly: () => current() && this.beforeFly(authority)',
'if (!current() || controller.signal.aborted) return;',
'destination?.cancelled',
'finally',
'this.onSettled?.(authority)',
], 'deferred search component');
assert.match(ui, /begin: \(\) => this\._beginDeferredNavigation\('location'\)/);
assert.match(ui, /beforeFly: \(generation\) => this\._reassertNavigationHandoff\(generation\)/);
assert.match(ui, /isCurrent: \(generation\) =>\s*!this\._disposed && generation === this\._navigationGeneration/);
assert.match(ui, /change\.type === 'settled'\)\s*this\._settleLocationSearchUi\(change\.generation, \{\s*keepQuery: state\.status === 'missing' \|\| state\.status === 'failed',?\s*\}\)/);
assert.doesNotMatch(search.slice(0, search.indexOf('await this.search')), /_releaseFollowCamera/);
});
test('a direct globe gesture retires delayed camera and selection restore only', () => {
@@ -411,115 +287,77 @@ test('a direct globe gesture retires delayed camera and selection restore only',
/_stampNavigation\(\{ cancelPendingSelection = true[^)]*\} = \{\}\) \{([\s\S]*?)\n \}/,
'navigation stamp',
);
assert.match(
stamp,
/if \(cancelPendingSelection\) \{[\s\S]*?cancelPendingTrackingRestore/,
);
assert.match(stamp, /if \(cancelPendingSelection\) \{[\s\S]*?cancelPendingTrackingRestore/);
assert.doesNotMatch(stamp, /cancelPendingRestores\(\)/);
});
test('newer navigation, reset, Cockpit, and teardown share one generation', () => {
assert.equal((ui.match(/_navigationGeneration \+= 1/g) || []).length, 1);
const reset = body(ui, /resetToGlobeView\(\) \{([\s\S]*?)\n \}/, 'reset');
ordered(
reset,
[
'if (this._globeResetPromise) return this._globeResetPromise;',
'this._stampNavigation();',
"interruptCameraMotion('reset-globe')",
],
'reset supersession',
);
ordered(reset, [
'if (this._globeResetPromise) return this._globeResetPromise;',
'this._stampNavigation();',
"interruptCameraMotion('reset-globe')",
], 'reset supersession');
const dispose = body(ui, /async dispose\(\) \{([\s\S]*?)\n \}/, 'dispose');
ordered(
dispose,
[
'this._disposed = true;',
'this._layerBindings.stop();',
'this._navigation.destroy();',
'await this._contextControls.restoreForDisposal();',
],
'dispose invalidation',
);
ordered(dispose, [
'this._disposed = true;',
'this._layerBindings.stop();',
'this._navigation.destroy();',
'await this._contextControls.restoreForDisposal();',
], 'dispose invalidation');
assert.match(shellMethod('destroy').toString(), /this\._stampNavigation\(\)/);
});
test('teardown synchronously closes immediate camera entry points', () => {
const dispose = body(ui, /async dispose\(\) \{([\s\S]*?)\n \}/, 'dispose');
ordered(
dispose,
[
'this._disposed = true;',
'this._layerBindings.stop();',
'await this._contextControls.restoreForDisposal();',
],
'synchronous teardown barrier',
);
ordered(
LayerBindings.prototype.stop.toString(),
[
'this._disposed = true;',
'this._removeCctvRequestFocusListener?.();',
'this._removeWorldRequestFocusListener?.();',
'this._navigationOwnerChangedRemover?.();',
],
'camera bindings close synchronously',
);
ordered(dispose, [
'this._disposed = true;',
'this._layerBindings.stop();',
'await this._contextControls.restoreForDisposal();',
], 'synchronous teardown barrier');
ordered(LayerBindings.prototype.stop.toString(), [
'this._disposed = true;',
'this._removeCctvRequestFocusListener?.();',
'this._removeWorldRequestFocusListener?.();',
'this._navigationOwnerChangedRemover?.();',
], 'camera bindings close synchronously');
const navigation = body(
ui,
/_runExplicitNavigation\(noun, navigate, releaseOptions = undefined\) \{([\s\S]*?)\n \}/,
'explicit navigation',
);
ordered(
navigation,
[
'disposed: this._disposed',
'release: () => this._releaseFollowCamera(releaseOptions)',
'navigate,',
],
'disposed navigation guard',
);
ordered(navigation, [
'disposed: this._disposed',
'release: () => this._releaseFollowCamera(releaseOptions)',
'navigate,',
], 'disposed navigation guard');
const cctvFocus = body(
ui,
/_runExplicitCctvFocus\(activate, focus\) \{([\s\S]*?)\n \}/,
'explicit CCTV focus',
);
ordered(
cctvFocus,
['if (this._disposed) return false;', 'const cameraId = activate();'],
'disposed CCTV activation guard',
);
ordered(cctvFocus, [
'if (this._disposed) return false;',
'const cameraId = activate();',
], 'disposed CCTV activation guard');
});
test('teardown refuses deferred location work before geocoding begins', () => {
const deferred = body(
ui,
/_beginDeferredNavigation\(noun = 'location', \{ cancelPendingSelection = true \} = \{\}\) \{([\s\S]*?)\n \}/,
'deferred navigation',
);
const deferred = body(ui, /_beginDeferredNavigation\(noun = 'location', \{ cancelPendingSelection = true \} = \{\}\) \{([\s\S]*?)\n \}/, 'deferred navigation');
assert.match(deferred, /disposed: this\._disposed/);
const search = fs.readFileSync(
path.join(ROOT, 'src', 'ui', 'locationSearch.js'),
'utf8',
);
ordered(
search,
[
'if (!query || this.destroyed) return;',
'const authority = this.begin();',
'if (authority === false)',
'this.input?.blur();',
'this.onStart?.(authority);',
'await this.search(query',
],
'disposed search refusal',
);
assert.match(
search,
/if \(authority === false\) \{[\s\S]*?return;[\s\S]*?\}\s*this\.controller/,
);
const search = fs.readFileSync(path.join(ROOT, 'src', 'ui', 'locationSearch.js'), 'utf8');
ordered(search, [
'if (!query || this.destroyed) return;',
'const authority = this.begin();',
'if (authority === false)',
'this.input?.blur();',
'this.onStart?.(authority);',
'await this.search(query',
], 'disposed search refusal');
assert.match(search, /if \(authority === false\) \{[\s\S]*?return;[\s\S]*?\}\s*this\.controller/);
});
test('refused canned destinations commit no location or POI state', () => {
@@ -528,15 +366,11 @@ test('refused canned destinations commit no location or POI state', () => {
['poi', /_onPoiClick\(cityId, poiIndex\) \{([\s\S]*?)\n \}/],
]) {
const handler = body(ui, pattern, name);
ordered(
handler,
[
'this._flyWithTransition(',
'if (result === false) return;',
'this._setActiveLocation(cityId);',
],
name,
);
ordered(handler, [
'this._flyWithTransition(',
'if (result === false) return;',
'this._setActiveLocation(cityId);',
], name);
}
});
@@ -558,15 +392,11 @@ test('vessel and fire layers announce valid clicks and never fly cameras', () =>
/inputFor\(viewer\)\.onClick\(\(event\) => \{([\s\S]*?)\n \}\);/,
'vessel click',
);
ordered(
vesselClick,
[
"isOwnedByOtherLayer('ais-live-vessels', pickedId)",
'_vesselOverlayHost.hitTest?.(',
'selectAndFocusVessel(record)',
],
'vessel sibling ownership',
);
ordered(vesselClick, [
"isOwnedByOtherLayer('ais-live-vessels', pickedId)",
'_vesselOverlayHost.hitTest?.(',
'selectAndFocusVessel(record)',
], 'vessel sibling ownership');
const vesselFocus = body(
vessels,
/function selectAndFocusVessel\(record\) \{([\s\S]*?)\n \}/,
@@ -578,13 +408,9 @@ test('vessel and fire layers announce valid clicks and never fly cameras', () =>
/input\.onClick\(\(event\) => \{([\s\S]*?)\n \}\);/,
'fire click',
);
ordered(
fireClick,
[
'isOwnedByOtherLayer(id, pickedId)',
'overlayHost.hitTest?.(',
'selectAndFocusFire(carded)',
],
'fire sibling ownership',
);
ordered(fireClick, [
'isOwnedByOtherLayer(id, pickedId)',
'overlayHost.hitTest?.(',
'selectAndFocusFire(carded)',
], 'fire sibling ownership');
});
File diff suppressed because it is too large. Load diff
+464 -1166
View File
File diff suppressed because it is too large. Load diff
+30 -123
View File
@@ -22,28 +22,16 @@ function stubCamera() {
return {
calls,
heading: Cesium.Math.toRadians(45),
cancelFlight() {
calls.cancelFlight += 1;
},
flyToBoundingSphere(sphere, options) {
calls.flights.push({ sphere, options });
},
cancelFlight() { calls.cancelFlight += 1; },
flyToBoundingSphere(sphere, options) { calls.flights.push({ sphere, options }); },
};
}
test('a focus request carries the clicked target to any registered listener', () => {
const target = new EventTarget();
const seen = [];
const dispose = registerWorldFocusRequestListener(target, (event) =>
seen.push(event.detail),
);
assert.equal(
requestWorldFocus(
{ kind: 'vessel', position: POSITION, id: '123' },
target,
),
true,
);
const dispose = registerWorldFocusRequestListener(target, (event) => seen.push(event.detail));
assert.equal(requestWorldFocus({ kind: 'vessel', position: POSITION, id: '123' }, target), true);
assert.equal(seen.length, 1);
assert.equal(seen[0].kind, 'vessel');
assert.equal(seen[0].id, '123');
@@ -57,9 +45,7 @@ test('a focus request carries the clicked target to any registered listener', ()
test('requests without a kind or a position are dropped, never dispatched', () => {
const target = new EventTarget();
let count = 0;
target.addEventListener(WORLD_FOCUS_REQUEST_EVENT, () => {
count += 1;
});
target.addEventListener(WORLD_FOCUS_REQUEST_EVENT, () => { count += 1; });
assert.equal(requestWorldFocus({ position: POSITION }, target), false);
assert.equal(requestWorldFocus({ kind: 'vessel' }, target), false);
assert.equal(requestWorldFocus(null, target), false);
@@ -89,95 +75,51 @@ test('a refusing policy (cockpit owns the camera) never reaches the flight', ()
const result = routeWorldFocusRequest(
{ detail: { kind: 'vessel', id: '123', position: POSITION } },
() => false,
() => {
flights += 1;
},
() => { flights += 1; },
);
assert.equal(result, false);
assert.equal(flights, 0);
});
test('malformed requests are inert', () => {
assert.equal(
routeWorldFocusRequest(
null,
() => 'x',
() => 'y',
),
false,
);
assert.equal(
routeWorldFocusRequest(
{ detail: { kind: 'vessel' } },
() => 'x',
() => 'y',
),
false,
);
assert.equal(routeWorldFocusRequest(null, () => 'x', () => 'y'), false);
assert.equal(routeWorldFocusRequest({ detail: { kind: 'vessel' } }, () => 'x', () => 'y'), false);
});
// A request that cannot fly must never cost the user their tracking: the UI
// policy releases the follow camera, so validation happens BEFORE it runs.
test('an unflyable request never reaches the release policy', () => {
const unflyable = [
{ kind: 'plane', position: POSITION }, // no framing for this kind
{ kind: 'vessel', position: { x: NaN, y: 0, z: 0 } }, // malformed position
{ kind: 'vessel', position: { x: 0, y: 0 } }, // truthy but incomplete
{ kind: 'plane', position: POSITION }, // no framing for this kind
{ kind: 'vessel', position: { x: NaN, y: 0, z: 0 } }, // malformed position
{ kind: 'vessel', position: { x: 0, y: 0 } }, // truthy but incomplete
{ kind: 'vessel', id: '123', position: { x: 0, y: 0, z: 0 } }, // ECEF origin
{ kind: 'fire', id: 'fire-1', position: { x: 1, y: 1, z: 1 } }, // finite but inside Earth
{ kind: 'vessel', position: 'somewhere' },
{ kind: 'vessel', position: POSITION }, // missing owner id
{ kind: 'vessel', position: POSITION }, // missing owner id
{ position: POSITION },
];
for (const detail of unflyable) {
assert.equal(
isValidWorldFocusTarget(detail),
false,
JSON.stringify(detail),
);
assert.equal(isValidWorldFocusTarget(detail), false, JSON.stringify(detail));
let policyRuns = 0;
const result = routeWorldFocusRequest(
{ detail },
() => {
policyRuns += 1;
return 'released';
},
() => { policyRuns += 1; return 'released'; },
() => 'flew',
);
assert.equal(result, false, JSON.stringify(detail));
assert.equal(
policyRuns,
0,
`the policy must not run for ${JSON.stringify(detail)}`,
);
assert.equal(policyRuns, 0, `the policy must not run for ${JSON.stringify(detail)}`);
// Nor may such a request be dispatched in the first place.
assert.equal(requestWorldFocus(detail, new EventTarget()), false);
}
assert.equal(
isValidWorldFocusTarget({ kind: 'vessel', id: '123', position: POSITION }),
true,
);
assert.equal(
isValidWorldFocusTarget({ kind: 'fire', id: 'fire-1', position: POSITION }),
true,
);
assert.equal(isValidWorldFocusTarget({ kind: 'vessel', id: '123', position: POSITION }), true);
assert.equal(isValidWorldFocusTarget({ kind: 'fire', id: 'fire-1', position: POSITION }), true);
});
test('the transfer flight supersedes any flight in progress and keeps the operator heading', () => {
const camera = stubCamera();
assert.equal(
flyToWorldTarget(bindFakeCesiumCamera({ camera }), {
kind: 'vessel',
id: '123',
position: POSITION,
}),
true,
);
assert.equal(
camera.calls.cancelFlight,
1,
'a prior flight must be cancelled, not queued',
);
assert.equal(flyToWorldTarget(bindFakeCesiumCamera({ camera }), { kind: 'vessel', id: '123', position: POSITION }), true);
assert.equal(camera.calls.cancelFlight, 1, 'a prior flight must be cancelled, not queued');
assert.equal(camera.calls.flights.length, 1);
const { sphere, options } = camera.calls.flights[0];
assert.equal(sphere.radius, WORLD_FOCUS_FRAMING.vessel.radiusM);
@@ -190,20 +132,12 @@ test('the transfer flight supersedes any flight in progress and keeps the operat
test('fires frame wider than vessels — a fire is read by its surroundings', () => {
const camera = stubCamera();
flyToWorldTarget(bindFakeCesiumCamera({ camera }), {
kind: 'fire',
id: 'fire-1',
position: POSITION,
});
flyToWorldTarget(bindFakeCesiumCamera({ camera }), { kind: 'fire', id: 'fire-1', position: POSITION });
const { sphere, options } = camera.calls.flights[0];
assert.equal(sphere.radius, WORLD_FOCUS_FRAMING.fire.radiusM);
assert.equal(options.offset.range, WORLD_FOCUS_FRAMING.fire.rangeM);
assert.ok(
WORLD_FOCUS_FRAMING.fire.rangeM > WORLD_FOCUS_FRAMING.vessel.rangeM,
);
assert.ok(
WORLD_FOCUS_FRAMING.fire.radiusM > WORLD_FOCUS_FRAMING.vessel.radiusM,
);
assert.ok(WORLD_FOCUS_FRAMING.fire.rangeM > WORLD_FOCUS_FRAMING.vessel.rangeM);
assert.ok(WORLD_FOCUS_FRAMING.fire.radiusM > WORLD_FOCUS_FRAMING.vessel.radiusM);
});
test('every framing is a real oblique standoff, not a nadir or an inside-out sphere', () => {
@@ -212,52 +146,25 @@ test('every framing is a real oblique standoff, not a nadir or an inside-out sph
for (const kind of kinds) {
const framing = WORLD_FOCUS_FRAMING[kind];
// Looking DOWN at the target, but obliquely — a nadir drop reads as a map.
assert.ok(
framing.pitchDeg < 0,
`${kind}: pitch must look down, got ${framing.pitchDeg}`,
);
assert.ok(
framing.pitchDeg > -80,
`${kind}: pitch must stay oblique, got ${framing.pitchDeg}`,
);
assert.ok(framing.pitchDeg < 0, `${kind}: pitch must look down, got ${framing.pitchDeg}`);
assert.ok(framing.pitchDeg > -80, `${kind}: pitch must stay oblique, got ${framing.pitchDeg}`);
// Standing off outside the framed sphere, at a human-readable distance.
assert.ok(framing.radiusM > 0, `${kind}: radius must be positive`);
assert.ok(
framing.rangeM > framing.radiusM,
`${kind}: range ${framing.rangeM} must stand off outside radius ${framing.radiusM}`,
);
assert.ok(
framing.rangeM <= 10000,
`${kind}: range must stay close-in, got ${framing.rangeM}`,
);
assert.ok(framing.rangeM <= 10000, `${kind}: range must stay close-in, got ${framing.rangeM}`);
}
// Exact shipped values — a silent retune must show up as a failing test.
assert.deepEqual(
{ ...WORLD_FOCUS_FRAMING.vessel },
{ radiusM: 150, rangeM: 1200, pitchDeg: -30 },
);
assert.deepEqual(
{ ...WORLD_FOCUS_FRAMING.fire },
{ radiusM: 400, rangeM: 3000, pitchDeg: -35 },
);
assert.deepEqual({ ...WORLD_FOCUS_FRAMING.vessel }, { radiusM: 150, rangeM: 1200, pitchDeg: -30 });
assert.deepEqual({ ...WORLD_FOCUS_FRAMING.fire }, { radiusM: 400, rangeM: 3000, pitchDeg: -35 });
});
test('unknown kinds and missing viewers issue no flight', () => {
const camera = stubCamera();
assert.equal(
flyToWorldTarget(bindFakeCesiumCamera({ camera }), {
kind: 'plane',
position: POSITION,
}),
false,
);
assert.equal(
flyToWorldTarget(bindFakeCesiumCamera({ camera }), { kind: 'vessel' }),
false,
);
assert.equal(
flyToWorldTarget(null, { kind: 'vessel', position: POSITION }),
false,
);
assert.equal(flyToWorldTarget(bindFakeCesiumCamera({ camera }), { kind: 'plane', position: POSITION }), false);
assert.equal(flyToWorldTarget(bindFakeCesiumCamera({ camera }), { kind: 'vessel' }), false);
assert.equal(flyToWorldTarget(null, { kind: 'vessel', position: POSITION }), false);
assert.equal(camera.calls.flights.length, 0);
});