mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Preserve the camera, map source and layer selection across engine sessions. Restore the previous engine if startup fails and retain local history navigation.
230 lines
8.3 KiB
JavaScript
230 lines
8.3 KiB
JavaScript
import { test } from 'node:test';
|
||
import assert from 'node:assert/strict';
|
||
import { DATA_CREDITS, NYC_DOT_DISCLAIMER } from './dataCredits.js';
|
||
|
||
test('every credit carries a unique key and some markup to render', () => {
|
||
const keys = DATA_CREDITS.map((entry) => entry.key);
|
||
assert.equal(
|
||
new Set(keys).size,
|
||
keys.length,
|
||
'a duplicate key would silently shadow one provider’s credit',
|
||
);
|
||
for (const entry of DATA_CREDITS) {
|
||
assert.ok(entry.key, 'a credit without a key cannot be registered');
|
||
assert.ok(
|
||
entry.html && entry.html.trim().length > 0,
|
||
`credit ${entry.key} has nothing to show`,
|
||
);
|
||
}
|
||
});
|
||
|
||
test('adsbdb is credited and carries its published route-data restriction', () => {
|
||
const credit = DATA_CREDITS.find((entry) => entry.key === 'adsbdb');
|
||
assert.ok(
|
||
credit,
|
||
'adsbdb supplies aircraft type and routes and must be credited',
|
||
);
|
||
// adsbdb publishes this restriction for its route data. Pin the provider's
|
||
// credits and restriction here so a later edit cannot silently remove them.
|
||
assert.match(credit.html, /David Taylor, Edinburgh/);
|
||
assert.match(credit.html, /Jim Mason, Glasgow/);
|
||
assert.match(
|
||
credit.html,
|
||
/may not be\s+copied, published, or incorporated into other databases/,
|
||
);
|
||
assert.match(credit.html, /explicit permission of David J Taylor, Edinburgh/);
|
||
assert.match(credit.html, /PlaneBase/);
|
||
assert.match(credit.html, /Guillaume Michel/);
|
||
assert.match(credit.html, /href="https:\/\/www\.adsbdb\.com"/);
|
||
});
|
||
|
||
test('OpenStreetMap has one generic data credit with separate tile and names distributors', () => {
|
||
const osm = DATA_CREDITS.filter((entry) =>
|
||
entry.html.includes('openstreetmap.org/copyright'),
|
||
);
|
||
assert.equal(osm.length, 1);
|
||
assert.equal(osm[0].key, 'openstreetmap');
|
||
assert.match(osm[0].html, /Map and place data/);
|
||
assert.match(osm[0].html, /© OpenStreetMap contributors/);
|
||
assert.match(
|
||
DATA_CREDITS.find((entry) => entry.key === 'openfreemap').html,
|
||
/Vector tiles:/,
|
||
);
|
||
assert.match(
|
||
DATA_CREDITS.find((entry) => entry.key === 'overture-military-names').html,
|
||
/Overture Maps Foundation/,
|
||
);
|
||
});
|
||
|
||
test('inline OSM attribution persists until its last display owner leaves', async (t) => {
|
||
const { showOsmCredit, hideOsmCredit } = await import('./dataCredits.js');
|
||
t.mock.timers.enable({ apis: ['setTimeout'] });
|
||
const visible = new Set();
|
||
const viewer = {
|
||
creditDisplay: {
|
||
addStaticCredit: (c) => visible.add(c),
|
||
removeStaticCredit: (c) => visible.delete(c),
|
||
},
|
||
scene: { requestRender() {} },
|
||
};
|
||
assert.equal(showOsmCredit(viewer, 'alpr'), true);
|
||
assert.equal(showOsmCredit(viewer, 'alpr'), false);
|
||
assert.equal(visible.size, 1);
|
||
assert.match(
|
||
[...visible][0].html,
|
||
/href="https:\/\/www.openstreetmap.org\/copyright"/,
|
||
);
|
||
assert.match([...visible][0].html, />© OpenStreetMap</);
|
||
assert.ok([...visible][0].showOnScreen);
|
||
t.mock.timers.tick(60000);
|
||
assert.equal(visible.size, 1);
|
||
showOsmCredit(viewer, 'traffic', { openMapTiles: true });
|
||
assert.equal(visible.size, 2);
|
||
hideOsmCredit(viewer, 'alpr');
|
||
assert.equal(visible.size, 2, 'traffic still owns both credits');
|
||
showOsmCredit(viewer, 'datacenters');
|
||
hideOsmCredit(viewer, 'traffic');
|
||
assert.equal(
|
||
visible.size,
|
||
1,
|
||
'bundled data does not retain the tile distributor',
|
||
);
|
||
hideOsmCredit(viewer, 'datacenters');
|
||
assert.equal(visible.size, 0);
|
||
assert.equal(hideOsmCredit(viewer, 'datacenters'), false);
|
||
showOsmCredit(viewer, 'alpr');
|
||
assert.equal(visible.size, 1, 'reenabling restores the short credit');
|
||
});
|
||
|
||
test('tile attribution follows source changes and viewers have independent ownership', async () => {
|
||
const { showOsmCredit, hideOsmCredit } = await import('./dataCredits.js');
|
||
const create = () => {
|
||
const credits = new Set();
|
||
return {
|
||
credits,
|
||
creditDisplay: {
|
||
addStaticCredit: (c) => credits.add(c),
|
||
removeStaticCredit: (c) => credits.delete(c),
|
||
},
|
||
};
|
||
};
|
||
const a = create(),
|
||
b = create();
|
||
showOsmCredit(a, 'installations', { openMapTiles: true });
|
||
showOsmCredit(b, 'installations');
|
||
assert.equal(a.credits.size, 2);
|
||
assert.equal(b.credits.size, 1);
|
||
showOsmCredit(a, 'installations');
|
||
assert.equal(a.credits.size, 1, 'wide names no longer use tiles');
|
||
hideOsmCredit(a, 'installations');
|
||
assert.equal(a.credits.size, 0);
|
||
assert.equal(b.credits.size, 1);
|
||
});
|
||
|
||
test('data credits go through the globe engine credits', async () => {
|
||
const {
|
||
registerDataCredits,
|
||
registerDynamicCredit,
|
||
showOsmCredit,
|
||
hideOsmCredit,
|
||
} = await import('./dataCredits.js');
|
||
const { createFakeEngine } = await import('../globe/testing/fakeEngine.js');
|
||
const engine = createFakeEngine();
|
||
registerDataCredits(engine, [{ html: 'A' }, { html: 'B' }]);
|
||
assert.deepEqual(engine.fake.credits, [
|
||
{ html: 'A', onScreen: false },
|
||
{ html: 'B', onScreen: false },
|
||
]);
|
||
assert.equal(
|
||
registerDynamicCredit(engine, { key: 'engine-dyn', html: 'D' }),
|
||
true,
|
||
);
|
||
assert.equal(
|
||
registerDynamicCredit(engine, { key: 'engine-dyn', html: 'D' }),
|
||
true,
|
||
);
|
||
assert.equal(
|
||
engine.fake.credits.filter(({ html }) => html === 'D').length,
|
||
1,
|
||
);
|
||
engine.fake.resetCalls();
|
||
assert.equal(showOsmCredit(engine, 'alpr', { openMapTiles: true }), true);
|
||
const inline = engine.fake.credits.filter(({ onScreen }) => onScreen);
|
||
assert.equal(inline.length, 2);
|
||
assert.match(inline[0].html, /© OpenStreetMap/);
|
||
assert.ok(engine.fake.callsOf('render.request').length > 0);
|
||
assert.equal(hideOsmCredit(engine, 'alpr'), true);
|
||
assert.equal(
|
||
engine.fake.credits.filter(({ onScreen }) => onScreen).length,
|
||
0,
|
||
);
|
||
});
|
||
|
||
test('Google Places attribution is visible only while a layer displays Places data', async () => {
|
||
const { showGooglePlacesCredit, hideGooglePlacesCredit } =
|
||
await import('./dataCredits.js');
|
||
const { createFakeEngine } = await import('../globe/testing/fakeEngine.js');
|
||
const engine = createFakeEngine();
|
||
assert.equal(showGooglePlacesCredit(engine, 'installations'), true);
|
||
assert.equal(showGooglePlacesCredit(engine, 'installations'), false);
|
||
assert.equal(showGooglePlacesCredit(engine, 'other-layer'), true);
|
||
const visible = engine.fake.credits.filter(({ onScreen }) => onScreen);
|
||
assert.equal(visible.length, 1);
|
||
assert.match(visible[0].html, /Google Maps Places/);
|
||
assert.match(
|
||
visible[0].html,
|
||
/developers\.google\.com\/maps\/documentation\/places/,
|
||
);
|
||
assert.ok(engine.fake.callsOf('render.request').length > 0);
|
||
assert.equal(hideGooglePlacesCredit(engine, 'installations'), true);
|
||
assert.equal(
|
||
engine.fake.credits.filter(({ onScreen }) => onScreen).length,
|
||
1,
|
||
);
|
||
assert.equal(hideGooglePlacesCredit(engine, 'other-layer'), true);
|
||
assert.equal(hideGooglePlacesCredit(engine, 'installations'), false);
|
||
assert.equal(
|
||
engine.fake.credits.filter(({ onScreen }) => onScreen).length,
|
||
0,
|
||
);
|
||
});
|
||
|
||
test('without a viewer or engine the OSM and dynamic credits skip cleanly', async () => {
|
||
const {
|
||
registerDataCredits,
|
||
registerDynamicCredit,
|
||
showOsmCredit,
|
||
hideOsmCredit,
|
||
showGooglePlacesCredit,
|
||
hideGooglePlacesCredit,
|
||
} = await import('./dataCredits.js');
|
||
// The Navara mode has no viewer; a layer-side call with it must not throw.
|
||
assert.doesNotThrow(() => registerDataCredits(null, [{ html: 'A' }]));
|
||
assert.equal(showOsmCredit(null, 'owner'), false);
|
||
assert.equal(hideOsmCredit(null, 'owner'), false);
|
||
assert.equal(showGooglePlacesCredit(null, 'owner'), false);
|
||
assert.equal(hideGooglePlacesCredit(null, 'owner'), false);
|
||
assert.equal(registerDynamicCredit(null, { key: 'k', html: 'K' }), false);
|
||
});
|
||
|
||
test('the NYC camera credit carries NYC DOT’s requested disclaimer', () => {
|
||
const credit = DATA_CREDITS.find((entry) => entry.key === 'nyc-cctv');
|
||
assert.ok(credit, 'NYC DOT camera frames must be credited');
|
||
assert.ok(credit.html.includes(NYC_DOT_DISCLAIMER));
|
||
assert.match(credit.html, /make no representation as to the accuracy/);
|
||
assert.match(credit.html, /observe posted signage/);
|
||
});
|
||
|
||
test('every Street Level imagery source is in the attribution lightbox', () => {
|
||
for (const key of [
|
||
'mapillary',
|
||
'google-street-view',
|
||
'kartaview',
|
||
'panoramax',
|
||
])
|
||
assert.ok(
|
||
DATA_CREDITS.some((entry) => entry.key === key),
|
||
`${key} has no credit`,
|
||
);
|
||
});
|