mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 09:12:18 +00:00
The first camera-family slice. The camera port's events move into a shared module (render/camera/events.js) that the stub and the Cesium port both use: listener lists, delivery with errors reported, and the contract's per-listener `changed` measure. The Cesium port gains: - camera.on: `changed` measured per listener on every tick, where Cesium measures its single threshold (the counts match Cesium's own at each threshold); moveStart and moveEnd relayed from Cesium's camera; - camera.viewRectangle, in degrees (now in CESIUM_CHECKS); - lon and lat in pose, and NaN where Cesium has no cartographic position. Code that still holds the viewer reaches the renderer through rendererOf(viewer); the application renderer binds it on create and unbinds on destroy. The HUD reads its telemetry from the camera port and no longer imports Cesium (off the allow-list). The share link writes the hash from the pose. Its restore path stays on the viewer's camera for a later slice. Behaviour changes: - The share link listens to `changed` at its own 0.5 threshold, not at whatever global threshold layers had set, and also to moveEnd, so the hash always catches up with where the camera comes to rest. - The HUD's and share link's camera callbacks run from the port's single relay, ahead of other moveStart/moveEnd listeners, and a throw in one is reported to the renderer's error listeners instead of escaping from Cesium's render.
72 lines
2.2 KiB
JavaScript
72 lines
2.2 KiB
JavaScript
// A copied share link must not carry the sender's ?lang override: on the
|
|
// recipient's side ?lang would beat their own stored choice.
|
|
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { ShareLinkManager } from './sharelink.js';
|
|
import { resolveLocale } from './i18n/locale.js';
|
|
import { persistLocale } from './i18n/index.js';
|
|
import { bindFakeCesiumCamera } from './testSupport/fakeCameraPort.mjs';
|
|
|
|
function makeManager(href) {
|
|
globalThis.window = { location: { href, hash: new URL(href).hash } };
|
|
globalThis.history = { replaceState() {} };
|
|
const viewer = {
|
|
camera: {
|
|
changed: { addEventListener() {} },
|
|
positionCartographic: { latitude: 0, longitude: 0, height: 1000 },
|
|
heading: 0,
|
|
pitch: -Math.PI / 2,
|
|
roll: 0,
|
|
},
|
|
};
|
|
return new ShareLinkManager(bindFakeCesiumCamera(viewer));
|
|
}
|
|
|
|
function installClipboard(writeText) {
|
|
Object.defineProperty(globalThis, 'navigator', {
|
|
configurable: true,
|
|
value: { clipboard: { writeText } },
|
|
});
|
|
}
|
|
|
|
test('the copied link does not carry the sender ?lang override', async () => {
|
|
let copied = null;
|
|
installClipboard(async (url) => {
|
|
copied = url;
|
|
});
|
|
const manager = makeManager('https://gev.example/?lang=ru#v=2&lat=10&lon=20');
|
|
assert.equal(await manager.copyLink({ nowMs: 1_000_000 }), true);
|
|
const link = new URL(copied);
|
|
assert.equal(link.searchParams.get('lang'), null, `copied link: ${copied}`);
|
|
|
|
const store = new Map([['gev:locale:v1', 'es']]);
|
|
const recipient = resolveLocale({
|
|
location: { search: link.search },
|
|
storage: { getItem: (k) => store.get(k) ?? null },
|
|
languages: ['en-US'],
|
|
});
|
|
assert.equal(recipient, 'es');
|
|
});
|
|
|
|
test('with storage blocked the language picker keeps the choice in ?lang', () => {
|
|
let href = 'https://gev.example/#v=2';
|
|
const location = {
|
|
get href() {
|
|
return href;
|
|
},
|
|
};
|
|
const history = {
|
|
replaceState: (_s, _t, url) => {
|
|
href = url;
|
|
},
|
|
};
|
|
const blocked = {
|
|
setItem() {
|
|
throw new Error('blocked');
|
|
},
|
|
};
|
|
persistLocale('ru', { location, history, storage: blocked });
|
|
// Storage blocked: the choice survives only in ?lang.
|
|
assert.equal(new URL(href).searchParams.get('lang'), 'ru');
|
|
});
|