mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 01:02:23 +00:00
Roads the view cannot sample may keep their pending surface heights, as before the refactoring; the oblique wait now asks for current coverage, drawn traffic, finished loading and no scheduled refinement, and prints every loading field when it times out.
285 lines
8.3 KiB
JavaScript
285 lines
8.3 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import { createFakeEngine } from '../../src/globe/testing/fakeEngine.js';
|
|
import { createReticleFootprint } from '../../src/layers/traffic/footprint.js';
|
|
import {
|
|
moveTrafficCamera,
|
|
trafficReadiness,
|
|
whenTrafficSettled,
|
|
} from './traffic.mjs';
|
|
|
|
function fixture(t) {
|
|
const engine = createFakeEngine({ kind: 'cesium' });
|
|
engine.camera.setView({
|
|
destination: { x: 6379137, y: 0, z: 0 },
|
|
orientation: { heading: 0, pitch: -Math.PI / 12, roll: 0 },
|
|
});
|
|
const previousWindow = globalThis.window;
|
|
const previousDocument = globalThis.document;
|
|
globalThis.window = { __godsEyeView: { engine } };
|
|
globalThis.document = { querySelector: () => null };
|
|
t.after(() => {
|
|
if (previousWindow === undefined) delete globalThis.window;
|
|
else globalThis.window = previousWindow;
|
|
if (previousDocument === undefined) delete globalThis.document;
|
|
else globalThis.document = previousDocument;
|
|
engine.destroy();
|
|
});
|
|
return globalThis.window.__godsEyeView;
|
|
}
|
|
|
|
test('oblique fixture preserves collision and maximum flight height on Cesium', async (t) => {
|
|
const app = fixture(t);
|
|
let flight;
|
|
let cancelled = false;
|
|
app.viewer = {
|
|
scene: { screenSpaceCameraController: { enableCollisionDetection: true } },
|
|
camera: {
|
|
cancelFlight() {
|
|
cancelled = true;
|
|
},
|
|
flyTo(options) {
|
|
flight = options;
|
|
options.complete();
|
|
},
|
|
},
|
|
};
|
|
await moveTrafficCamera(
|
|
{ evaluate: (fn, ...args) => fn(...args) },
|
|
{ lon: 55.037, lat: 24.964, height: 276, pitch: -15 },
|
|
1.4,
|
|
);
|
|
assert.equal(cancelled, true);
|
|
assert.equal(
|
|
app.viewer.scene.screenSpaceCameraController.enableCollisionDetection,
|
|
false,
|
|
);
|
|
assert.ok(Math.abs(flight.maximumHeight - 1000) < 1e-6);
|
|
assert.equal(flight.duration, 1.4);
|
|
assert.equal(flight.orientation.pitch, -Math.PI / 12);
|
|
});
|
|
|
|
test('traffic readiness rejects old coverage, pending debounce and partial populations', async (t) => {
|
|
const app = fixture(t);
|
|
const stats = {
|
|
count: 0,
|
|
loading: false,
|
|
surfacePending: 0,
|
|
roadBounds: null,
|
|
};
|
|
const work = { surfaceWaiting: false };
|
|
app.dataManager = {
|
|
layers: new Map([
|
|
[
|
|
'traffic',
|
|
{
|
|
module: {
|
|
getStats: () => stats,
|
|
getLoadingDiagnostics: () => work,
|
|
},
|
|
},
|
|
],
|
|
]),
|
|
};
|
|
let calls = 0;
|
|
let disposed = 0;
|
|
await whenTrafficSettled({
|
|
evaluate: async () => {},
|
|
async waitForFunction(expression) {
|
|
const predicate = () =>
|
|
typeof expression === 'function' ? expression() : eval(expression);
|
|
if (++calls < 3) assert.equal(predicate(), true);
|
|
else {
|
|
assert.equal(
|
|
predicate(),
|
|
false,
|
|
'idle before the debounce is not loaded',
|
|
);
|
|
stats.count = 100;
|
|
stats.roadBounds = { coverage: { viewKey: 'old view' } };
|
|
assert.equal(predicate(), false, 'old roads do not cover this camera');
|
|
stats.roadBounds.coverage.viewKey =
|
|
'0.0000000,0.0000000,0.1000000,0.0000000,-0.2617994';
|
|
stats.loading = true;
|
|
assert.equal(predicate(), false, 'partial road population');
|
|
stats.loading = false;
|
|
stats.surfacePending = 1;
|
|
work.surfaceWaiting = true;
|
|
assert.equal(predicate(), false, 'scheduled surface work');
|
|
work.surfaceWaiting = false;
|
|
assert.equal(
|
|
predicate(),
|
|
true,
|
|
'unavailable heights with no more work',
|
|
);
|
|
stats.loading = true;
|
|
assert.equal(predicate(), false, 'active refinement still blocks');
|
|
stats.loading = false;
|
|
stats.surfacePending = 0;
|
|
assert.equal(predicate(), true);
|
|
}
|
|
return {
|
|
dispose: async () => {
|
|
disposed++;
|
|
},
|
|
};
|
|
},
|
|
});
|
|
assert.equal(disposed, 3);
|
|
});
|
|
|
|
test('traffic readiness accepts the layer footprint after rounding and tiny pose drift', (t) => {
|
|
const app = fixture(t);
|
|
app.engine.fake.setPose({
|
|
latitude: (30.2672 * Math.PI) / 180,
|
|
longitude: (-97.7431 * Math.PI) / 180,
|
|
height: 300,
|
|
heading: 2 * Math.PI - 1e-8,
|
|
pitch: -Math.PI / 12,
|
|
});
|
|
const stats = {
|
|
count: 100,
|
|
loading: false,
|
|
surfacePending: 0,
|
|
roadBounds: createReticleFootprint()(app.engine, 300),
|
|
};
|
|
app.dataManager = {
|
|
layers: new Map([
|
|
[
|
|
'traffic',
|
|
{
|
|
module: {
|
|
getStats: () => stats,
|
|
getLoadingDiagnostics: () => ({ surfaceWaiting: false }),
|
|
},
|
|
},
|
|
],
|
|
]),
|
|
};
|
|
assert.equal(trafficReadiness().settled, true);
|
|
app.engine.fake.setPose({
|
|
latitude: (30.2672 * Math.PI) / 180 + 2e-8,
|
|
longitude: (-97.7431 * Math.PI) / 180 - 2e-8,
|
|
height: 300.1,
|
|
heading: 1e-8,
|
|
pitch: -Math.PI / 12 + 2e-8,
|
|
});
|
|
const observed = trafficReadiness();
|
|
assert.notEqual(observed.viewKey, observed.coverageViewKey);
|
|
assert.equal(observed.settled, true);
|
|
});
|
|
|
|
test('traffic readiness rejects changed views and malformed coverage keys', (t) => {
|
|
const app = fixture(t);
|
|
const stats = {
|
|
count: 100,
|
|
loading: false,
|
|
surfacePending: 0,
|
|
roadBounds: { coverage: {} },
|
|
};
|
|
app.dataManager = {
|
|
layers: new Map([
|
|
[
|
|
'traffic',
|
|
{
|
|
module: {
|
|
getStats: () => stats,
|
|
getLoadingDiagnostics: () => ({ surfaceWaiting: false }),
|
|
},
|
|
},
|
|
],
|
|
]),
|
|
};
|
|
for (const key of [
|
|
null,
|
|
'old view',
|
|
'0,0,0.1,0',
|
|
'0,0,0.1,0,NaN',
|
|
'0,0,Infinity,0,-0.2617994',
|
|
'0.01,0,0.1,0,-0.2617994',
|
|
'0,0.01,0.1,0,-0.2617994',
|
|
'0,0,0.3,0,-0.2617994',
|
|
'0,0,0.1,0.01,-0.2617994',
|
|
'0,0,0.1,0,-0.7853982',
|
|
]) {
|
|
stats.roadBounds.coverage.viewKey = key;
|
|
assert.equal(trafficReadiness().settled, false, String(key));
|
|
}
|
|
});
|
|
|
|
test('traffic loading timeouts include both keys and pending work', async (t) => {
|
|
const app = fixture(t);
|
|
const coverageViewKey = '0.01,0,0.1,0,-0.2617994';
|
|
app.dataManager = {
|
|
layers: new Map([
|
|
[
|
|
'traffic',
|
|
{
|
|
module: {
|
|
getStats: () => ({
|
|
count: 12,
|
|
loading: true,
|
|
surfacePending: 2,
|
|
error: null,
|
|
detailError: null,
|
|
roadBounds: { coverage: { viewKey: coverageViewKey } },
|
|
}),
|
|
getLoadingDiagnostics: () => ({
|
|
fetching: false,
|
|
flowPending: 0,
|
|
surfaceRefining: true,
|
|
surfaceWaiting: false,
|
|
populationPending: false,
|
|
heightPending: true,
|
|
generation: 3,
|
|
surfaceRevision: 7,
|
|
lastPaintStage: 'Loaded full refined',
|
|
movingWaypoints: 2,
|
|
maxResidualM: 12,
|
|
}),
|
|
},
|
|
},
|
|
],
|
|
]),
|
|
};
|
|
const timeout = new Error('traffic loading timeout');
|
|
timeout.name = 'TimeoutError';
|
|
let calls = 0;
|
|
await assert.rejects(
|
|
whenTrafficSettled({
|
|
evaluate: async (fn) => (typeof fn === 'function' ? fn() : undefined),
|
|
async waitForFunction() {
|
|
if (++calls === 3) throw timeout;
|
|
return { dispose: async () => {} };
|
|
},
|
|
}),
|
|
(error) => {
|
|
assert.equal(error.cause, timeout);
|
|
assert.match(error.message, /Readiness timeout: traffic/);
|
|
assert.ok(
|
|
error.message.includes(`"coverageViewKey":"${coverageViewKey}"`),
|
|
);
|
|
assert.ok(
|
|
error.message.includes(
|
|
'"viewKey":"0.0000000,0.0000000,0.1000000,0.0000000,-0.2617994"',
|
|
),
|
|
);
|
|
assert.match(error.message, /"loading":true,"surfacePending":2/);
|
|
const observed = JSON.parse(error.message.split('; ')[1]);
|
|
assert.equal(observed.viewMatches, false);
|
|
assert.equal(observed.fetching, false);
|
|
assert.equal(observed.flowPending, 0);
|
|
assert.equal(observed.surfaceRefining, true);
|
|
assert.equal(observed.surfaceWaiting, false);
|
|
assert.equal(observed.populationPending, false);
|
|
assert.equal(observed.heightPending, true);
|
|
assert.equal(observed.generation, 3);
|
|
assert.equal(observed.surfaceRevision, 7);
|
|
assert.equal(observed.lastPaintStage, 'Loaded full refined');
|
|
assert.equal(observed.movingWaypoints, 2);
|
|
assert.equal(observed.maxResidualM, 12);
|
|
return true;
|
|
},
|
|
);
|
|
});
|