Files
gods-eye-view/src/app/navaraScene.test.mjs
T
German Khokhlov ac081a008d feat(globe): Navara's cinematic look by default
navaraScenePlan gains a pure `cinematic` plan, now the default of the app's
Navara mode (`?look=photoreal|minimal` picks the others): photoreal plus
volumetric clouds (low quality, layers from 1,500 m, no ground shadows),
ACES tone mapping, brighter stars and no sun shadow maps. From space, at
rest, the aerial perspective lights the globe from the atmosphere for a
real night side and terminator; it switches off below 1,000 km so the
Google tiles keep their baked light.

look.js builds the plan and keeps it current on frames Navara draws
anyway: the atmosphere's sun date follows the wall clock (the HUD's SUN
elevation), and the clouds hide above 4 km or over high ground in view,
parking their last image so the aerial perspective shows no ghosts.
2026-10-16 02:29:46 +04:00

174 lines
5.6 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { createApplicationScene } from './scene.js';
import { createFakeEngine } from '../globe/testing/fakeEngine.js';
import {
installRenderGovernor,
isRenderGovernorInstalled,
} from '../renderGovernor.js';
// The scene's Navara branch in Node: the globe loader is a seam, so the fake
// engine stands in for Navara and nothing Cesium is built.
function installDom() {
const saved = {
window: globalThis.window,
document: globalThis.document,
CustomEvent: globalThis.CustomEvent,
location: globalThis.location,
};
const container = { id: 'cesiumContainer' };
const appended = [];
globalThis.document = {
getElementById: (id) => (id === 'cesiumContainer' ? container : null),
querySelector: () => null,
querySelectorAll: () => [],
createElement: () => {
throw new Error('the Navara scene creates no Cesium credit container');
},
body: { appendChild: (node) => appended.push(node) },
};
globalThis.location = { search: '?engine=navara&look=photoreal' };
const events = [];
globalThis.window = {
dispatchEvent: (event) => events.push(event),
addEventListener() {},
removeEventListener() {},
};
globalThis.CustomEvent ??= class {
constructor(type, { detail } = {}) {
this.type = type;
this.detail = detail;
}
};
const restore = () => {
for (const [name, value] of Object.entries(saved)) {
if (value === undefined) delete globalThis[name];
else globalThis[name] = value;
}
};
return { container, appended, events, restore };
}
const requestServices = {
terrain: { getHeights: async () => [] },
regional: { getBrief: async () => null },
weather: { getConditions: async () => null },
summary: { summarize: async () => null },
features: Object.fromEntries(
[
'getAdministrativeAreas',
'getAreaGeometry',
'getEnclosingAreas',
'getFocusFootprints',
'getFootprints',
'getMonuments',
'getNeighborhoodAreas',
'getStreetAreas',
'getStreetLines',
].map((name) => [name, async () => []]),
),
};
// Tests end with run.teardown (the scene's cleanups, then the DOM stand-ins).
async function startScene(options = {}) {
const dom = installDom();
const cleanups = [];
const loads = [];
const engine = createFakeEngine({ kind: 'navara' });
let globeDestroyed = 0;
const loaderStatus = { textContent: '' };
const scene = await createApplicationScene({
engineKind: 'navara',
requestServices,
googleApiKey: 'google-test',
credits: [
{ key: 'opensky', html: 'Flights credit' },
{ key: 'photon-geocoder', html: 'Search credit' },
{ key: 'openstreetmap', html: 'OSM credit' },
{ key: 'reearth-terrain', html: 'Terrain credit' },
],
loaderStatus,
signal: new AbortController().signal,
defer: (dispose) => cleanups.push(dispose),
loadNavaraGlobe: async () => async (globeOptions) => {
loads.push(globeOptions);
return {
engine,
destroy() {
globeDestroyed += 1;
engine.destroy();
},
};
},
...options,
});
const teardown = async () => {
while (cleanups.length) await cleanups.pop()();
dom.restore();
};
return {
scene,
engine,
loads,
dom,
loaderStatus,
teardown,
globeDestroyed: () => globeDestroyed,
};
}
test('the Navara scene builds the engine on the app container and no viewer', async (t) => {
const run = await startScene();
t.after(run.teardown);
assert.equal(run.scene.viewer, null);
assert.equal(run.scene.tileset, null);
assert.equal(run.scene.engine, run.engine);
assert.equal(run.scene.engine.kind, 'navara');
assert.equal(run.loads.length, 1);
assert.equal(run.loads[0].container, run.dom.container);
// The globe picks its look from the page's ?look= (cinematic by default).
assert.equal(run.loads[0].search, '?engine=navara&look=photoreal');
assert.ok(run.scene.operations.searchAndFlyTo);
assert.equal(globalThis.window.__GOOGLE_MAPS_API_KEY__, 'google-test');
// Data layers are off: only the credits of what the shell itself uses
// (place search, its OSM data, keyless terrain) go to the engine's credits.
assert.deepEqual(
run.engine.fake.credits.map(({ html }) => html),
['Search credit', 'OSM credit', 'Terrain credit'],
);
});
test('the Navara scene opens Google 3D through the engine', async (t) => {
const run = await startScene();
t.after(run.teardown);
const { mapStackController } = run.scene;
assert.equal(mapStackController.getActiveId(), 'photoreal');
assert.equal(mapStackController.isStackAvailable('bing-aerial'), false);
const [tiles] = run.engine.fake.callsOf('maps.setPhotorealTiles')[0].args;
assert.equal(tiles.kind, 'photoreal');
});
test('without a browser key the Navara scene opens on base imagery', async (t) => {
const run = await startScene({ googleApiKey: '' });
t.after(run.teardown);
assert.equal(run.scene.mapStackController.getActiveId(), 'esri-imagery');
assert.equal(
run.engine.fake.callsOf('maps.setBaseImagery')[0].args[0].kind,
'esri-imagery',
);
});
test('the Navara scene tears down the controller, then the globe', async (t) => {
const run = await startScene();
// The tools install the governor on the engine (src/app/tools.js); the
// scene removes it before the engine goes.
installRenderGovernor(run.engine);
const view = globalThis.window;
await run.teardown();
assert.equal(run.globeDestroyed(), 1);
assert.equal(run.engine.isDestroyed(), true);
assert.equal(isRenderGovernorInstalled(run.engine), false);
assert.equal(view.__GOOGLE_MAPS_API_KEY__, undefined);
});