Files
gods-eye-view/src/render/creditMarkup.test.mjs
T
Sameh Khamis 979e2213b9 Give the Cesium renderer the contract's credits port
The shared Cesium ports gain credits, on both the conformance renderer and
the application's. list() reports what Cesium owes as plain data: its logo,
its static credits and the last drawn frame's imagery, terrain and tile
credits, read from the credit display through internals.js, with the
credits the app adds listed as given where the display shows them. addStatic
shows a credit through Cesium's display, as markup built from the plain
data with every value escaped and only web links kept, so attribution stays
on screen. change fires when the app adds or removes a credit, and after a
drawn frame whose Cesium credits differ from the last one's.

src/render/creditMarkup.js reads markup credits as plain data. The credits
listener check moves out of renderer.listenerRules into its own check, so a
renderer without every port can run it; it and the credits check now run on
Cesium.
2026-11-06 16:32:17 -08:00

56 lines
1.8 KiB
JavaScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { creditFromMarkup } from './creditMarkup.js';
test('text, the first link and the first logo are read from markup', () => {
assert.deepEqual(
creditFromMarkup(
'Map data <a href="https://www.openstreetmap.org/copyright" target="_blank">&copy; OpenStreetMap</a> (<a href="https://opendatacommons.org/">ODbL</a>)',
),
{
text: 'Map data © OpenStreetMap (ODbL)',
href: 'https://www.openstreetmap.org/copyright',
},
);
assert.deepEqual(
creditFromMarkup(
'<a href=\'https://cesium.com/\'><img src="/ion.png" title="Cesium ion"/></a>',
),
{ text: 'Cesium ion', href: 'https://cesium.com/', logoUrl: '/ion.png' },
);
assert.deepEqual(creditFromMarkup('<img src=x.png alt="Logo">'), {
text: 'Logo',
logoUrl: 'x.png',
});
});
test('character references decode; tags, comments and scripts drop', () => {
assert.deepEqual(
creditFromMarkup(
' A&nbsp;&amp;&#39;B&#x2014;&unknown; <!-- c --><script>x</script>\n <b>C</b>',
),
{ text: "A &'B—&unknown; C" },
);
assert.deepEqual(creditFromMarkup('<a data-href="no" href="yes">x</a>'), {
text: 'x',
href: 'yes',
});
assert.deepEqual(
creditFromMarkup(
'<a title="A > B" href="https://example.com/?q=>">Provider</a>',
),
{ text: 'Provider', href: 'https://example.com/?q=>' },
);
assert.deepEqual(
creditFromMarkup(
'<a href="javascript:alert(1)"><img src="javascript:x" alt="L"></a>',
),
{ text: 'L' },
);
assert.deepEqual(creditFromMarkup('<img src="data:text/html,x" alt="L">'), {
text: 'L',
});
assert.deepEqual(creditFromMarkup(''), { text: '' });
assert.deepEqual(creditFromMarkup(undefined), { text: '' });
});