Files
gods-eye-view/src/maps/imageryHost.test.mjs
T
Sameh Khamis ae4fbb5053 Load the default renderer as the page starts, and follow through the camera port in tests
- The standalone page starts loading the default renderer as it starts
  (loadDefaultRenderer), so Cesium arrives beside the page's own setup,
  not after it; the scene takes a plugin or a promise of one.
- Where a follow target's layer has no display position yet, the followed
  position is the target's own position at the frame port's scene time.
- The globe engine's photoreal base that fails to come back is off again
  and the globe shown; a later switch tries again. The draped-imagery host
  asks the map engine whether the globe is shown where the renderer cannot
  say. The scene resizes the renderer with its container.
- Cockpit and voice tests follow through the camera port (followEntity),
  not by setting the viewer's tracked entity; the fake frame port has a
  scene time.
2026-11-10 17:44:29 -08:00

62 lines
2.4 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { NO_IMAGERY_HOST, resolveImageryHost } from './imageryHost.js';
import { bindRenderer } from '../render/rendererOf.js';
import { createStubRenderer } from '../render/stub/index.js';
import { globeMapEngine } from './globeEngine.js';
/** A scene object bound to a stub renderer, its globe shown or hidden. */
function scene({ globeShown, capabilities } = {}) {
const renderer = createStubRenderer(
capabilities ? { capabilities } : undefined,
);
if (globeShown !== undefined) renderer.globe.setGlobeVisible(globeShown);
const viewer = {};
bindRenderer(viewer, renderer);
return { viewer, renderer };
}
test('a shown globe hosts imagery on the globe port', () => {
const { viewer, renderer } = scene({ globeShown: true });
const host = resolveImageryHost({ viewer, tileset: { id: 'tiles' } });
assert.deepEqual(host, { collection: renderer.globe.imagery, kind: 'globe' });
});
test('a hidden globe hands imagery to the shown base tileset', () => {
const { viewer } = scene({ globeShown: false });
const tileset = { id: 'tiles', isDestroyed: () => false };
const host = resolveImageryHost({ viewer, tileset });
assert.deepEqual(host, { collection: tileset, kind: 'tileset' });
});
test('without globe visibility, the map engine says whether the globe is shown', () => {
const { viewer, renderer } = scene({ capabilities: [] });
assert.equal(renderer.globe.isGlobeVisible, undefined);
const tileset = { id: 'tiles' };
globeMapEngine.setGlobeShown(viewer, false);
assert.deepEqual(resolveImageryHost({ viewer, tileset }), {
collection: tileset,
kind: 'tileset',
});
// A globe stack shows the globe: a tileset kept from startup is not the host.
globeMapEngine.setGlobeShown(viewer, true);
assert.deepEqual(resolveImageryHost({ viewer, tileset }), {
collection: renderer.globe.imagery,
kind: 'globe',
});
});
test('no globe and no tileset means nowhere to drape', () => {
const { viewer } = scene({ globeShown: false });
assert.deepEqual(resolveImageryHost({ viewer, tileset: null }), {
collection: null,
kind: 'none',
});
assert.deepEqual(resolveImageryHost({}), { collection: null, kind: 'none' });
assert.deepEqual(
resolveImageryHost({ viewer, tileset: { isDestroyed: () => true } }),
{ collection: null, kind: 'none' },
);
assert.match(NO_IMAGERY_HOST, /globe map/);
});