Files
gods-eye-view/src/ui/creditLineHeight.test.mjs
T
Sameh KhamisandManjunath Paparaju c69a421678 Keep the HUD corners, the dock and a wrapped credit line apart at every width
The credit line now wraps at every width instead of running under the
corner row, and right to left it takes the bottom right at every width. A
small watcher keeps its height in --credit-line-height, so the coordinates
(and, right to left, the Tactical readout) stay above it however many lines
it wraps onto, and the dock and World Timeline rise when it is taller than
their usual clearance. Narrower than 1120px the dock leaves no room between
the bottom corners, so the coordinates and the readout sit above the dock
instead of under it. Outside the Omnibar layout, the coordinate rule meant
for 981 to 1199px no longer overrides the two-row dock's placement at 980px
and below.

Co-authored-by: Manjunath Paparaju <[email protected]>
2026-11-18 19:45:47 -08:00

80 lines
2.4 KiB
JavaScript

import '../testSupport/registerDom.mjs';
import test from 'node:test';
import assert from 'node:assert/strict';
import { trackCreditLineHeight } from './creditLineHeight.js';
/** A ResizeObserver the test drives, with each line's height set by hand. */
function fakeResizing() {
const observers = [];
const window = document.defaultView;
const original = window.ResizeObserver;
window.ResizeObserver = class {
constructor(callback) {
this.callback = callback;
this.targets = new Set();
observers.push(this);
}
observe(target) {
this.targets.add(target);
}
disconnect() {
this.targets.clear();
}
};
return {
resize(element, height) {
element.getBoundingClientRect = () => ({ height });
for (const observer of observers)
if (observer.targets.has(element)) observer.callback([]);
},
restore() {
window.ResizeObserver = original;
},
};
}
test("the credit line's height follows it as it wraps, for either renderer's line", () => {
const resizing = fakeResizing();
try {
for (const markup of [
'<div id="gev-credits"></div>',
'<div id="cesium-credits"><div class="cesium-widget-credits"></div></div>',
]) {
document.body.innerHTML = markup;
const line = document.querySelector(
'#gev-credits, #cesium-credits .cesium-widget-credits',
);
line.getBoundingClientRect = () => ({ height: 28 });
const stop = trackCreditLineHeight(document);
const root = document.documentElement.style;
assert.equal(root.getPropertyValue('--credit-line-height'), '28px');
resizing.resize(line, 66.4);
assert.equal(root.getPropertyValue('--credit-line-height'), '67px');
// Hidden, it holds no room.
resizing.resize(line, 0);
assert.equal(root.getPropertyValue('--credit-line-height'), '');
resizing.resize(line, 28);
stop();
assert.equal(root.getPropertyValue('--credit-line-height'), '');
}
} finally {
resizing.restore();
document.body.replaceChildren();
}
});
test('without a credit line nothing is followed', () => {
const resizing = fakeResizing();
try {
document.body.replaceChildren();
const stop = trackCreditLineHeight(document);
assert.equal(
document.documentElement.style.getPropertyValue('--credit-line-height'),
'',
);
stop();
} finally {
resizing.restore();
}
});