Files
gods-eye-view/src/layers/installations/lifecycle.test.mjs
T
Sameh Khamis cf915e8c16 Add layer and map credits through the renderer's credits port
The street-level provider credits, the map source credit, the shared
inline OpenStreetMap and OpenMapTiles credits and the ALPR provider credit
go through the renderer's credits port instead of Cesium's credit display.
Their markup has one link each and is read as the port's plain data; the
ALPR credit is built as plain data, which the port escapes. src/maps/credits.js
and src/layers/streetLevel/credits.js no longer reach Cesium and leave the
allow-list.

findCredits finds the port as findCamera finds the camera: a Cesium viewer
of a consumer's own, with no renderer bound, gets a credits port over its
own credit display, so the public entries keep their attribution. A port
built that way is released, not disposed, when a renderer binds later, and
a credit let go after its viewer is destroyed leaves the display alone.

The per-layer data credits and the transit and event credits stay on
Cesium's display: their markup carries several links each, which the
contract's credit cannot hold.
2026-11-06 16:32:23 -08:00

84 lines
2.6 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import * as credits from '../../data/dataCredits.js';
import { createLifecycle } from './lifecycle.js';
import { LAYER_ID } from './policy.js';
import { bindFakeCesiumCredits } from '../../testSupport/fakeCreditsPort.mjs';
for (const source of [
{ name: 'OpenStreetMap', id: 'tile:base' },
{ name: 'OpenStreetMap', id: 'way:123' },
{ name: 'Google Places', id: 'place:base' },
null,
]) {
test(`enable restores cached installation credits before a refresh: ${source?.id || 'empty'}`, () => {
const visibleCredits = new Set();
const noop = () => {};
const viewer = bindFakeCesiumCredits({
camera: {},
creditDisplay: {
addStaticCredit: (credit) => visibleCredits.add(credit),
removeStaticCredit: (credit) => visibleCredits.delete(credit),
},
});
const state = {
viewer,
records: source ? [{ id: 'base', sources: [source] }] : [],
recordById: new Map(),
dataSource: { show: false },
};
let markersVisible = false;
const parts = {
namedMarkers: {
enable: () => {
markersVisible = true;
},
sync: noop,
hide: () => {
markersVisible = false;
},
},
rendering: {},
viewport: { clearUnavailableRetry: noop },
ingestion: { setInstallationStatus: noop },
};
const lifecycle = createLifecycle({
state,
services: {
credits,
picking: { registerPickOwner: noop, unregisterPickOwner: noop },
context: { clearSelectedEntityContextForLayer: noop },
},
parts,
source: {},
}).methods;
const expected =
source?.name === 'OpenStreetMap'
? source.id.startsWith('tile:')
? 2
: 1
: 0;
try {
for (let cycle = 0; cycle < 2; cycle++) {
lifecycle.enable();
assert.equal(state.dataSource.show, true);
assert.equal(markersVisible, true);
// No renderRecords or successful fetch occurs between toggles.
assert.equal(visibleCredits.size, expected);
lifecycle.disable();
assert.equal(state.dataSource.show, false);
assert.equal(markersVisible, false);
assert.equal(visibleCredits.size, 0);
}
credits.showOsmCredit(viewer, 'another-layer');
lifecycle.enable();
lifecycle.disable();
assert.equal(visibleCredits.size, 1, 'another owner retains its credit');
assert.equal(credits.hideOsmCredit(viewer, LAYER_ID), false);
} finally {
lifecycle.disable();
credits.hideOsmCredit(viewer, 'another-layer');
}
});
}