mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 18:22:25 +00:00
Main's single click rule (the card or label on top takes the click, read once per click through clickCard and isUnderOtherCard in src/data/pickRegistry.js) covers a click on a Space Missions label: a mission marker label is an interactive world-overlay entry, so the host's hit test names it as the card on top for every other layer. The per-layer label guards in CCTV, Drone Airspace, FIRMS, Ghost Maps, News, Perimeters, Shipwrecks, Vessels, Wildlife Sightings, ALPR, Local ADS-B and the cockpit orbital focus are dropped for main's versions. The mission-label tests are kept on main's API: fakeInputUnderLabel now also names the label as the card on top, and each test shows a click on the label never acts on the card, camera, vessel, fire, reader, aircraft or report under it, and leaves the selection as it is. A launches test checks that a mission label is interactive and is the card on top for every other layer. Docs, changelog and the dispatcher's `overlay` note describe the merged behaviour. Co-authored-by: Manjunath Paparaju <[email protected]>
89 lines
2.9 KiB
JavaScript
89 lines
2.9 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { VESSEL_OVERLAY_SOURCE_ID } from '../../data/vesselLabels.js';
|
|
import { clickCard } from '../../data/pickRegistry.js';
|
|
import { fakeInputUnderLabel } from '../../input/testDoubles.mjs';
|
|
import { createSelection } from './selection.js';
|
|
|
|
/** Calls on any member are recorded by name and do nothing else. */
|
|
function recorder(calls) {
|
|
return new Proxy(
|
|
{},
|
|
{
|
|
get:
|
|
(_target, name) =>
|
|
(...args) =>
|
|
calls.push([name, ...args]),
|
|
},
|
|
);
|
|
}
|
|
|
|
/** The vessel selection over a viewer whose clicks a Space Missions label
|
|
* may take, with the vessel's card under every click. */
|
|
function selectionHarness(t) {
|
|
const viewer = { scene: { canvas: {}, pick: () => null } };
|
|
const vessel = { id: 'v1', name: 'NORTHERN STAR', lat: 0, lon: 0 };
|
|
const fake = fakeInputUnderLabel(viewer, {
|
|
beneath: () => ({
|
|
sourceId: VESSEL_OVERLAY_SOURCE_ID,
|
|
entryId: `vessel:${vessel.id}`,
|
|
}),
|
|
});
|
|
t.after(() => fake.destroy());
|
|
const focused = [];
|
|
const calls = [];
|
|
const state = {
|
|
feed: { enabled: true },
|
|
records: { byId: new Map([[vessel.id, vessel]]) },
|
|
icons: { setId: 'vessels:icons', has: () => false },
|
|
selectedRecord: null,
|
|
interactionKeyTarget: new EventTarget(),
|
|
};
|
|
const vesselState = { state };
|
|
const selection = createSelection({
|
|
vesselState,
|
|
services: {
|
|
picking: { isOwnedByOtherLayer: () => false, clickCard },
|
|
worldFocus: { requestWorldFocus: (request) => focused.push(request.id) },
|
|
context: recorder(calls),
|
|
},
|
|
parts: {
|
|
queries: {
|
|
reduceVesselSelection: ({ selectedId, pickedId }) =>
|
|
pickedId
|
|
? { action: pickedId === selectedId ? 'none' : 'select' }
|
|
: { action: selectedId ? 'deselect' : 'none' },
|
|
},
|
|
rendering: recorder(calls),
|
|
cards: recorder(calls),
|
|
photos: recorder(calls),
|
|
tracking: recorder(calls),
|
|
},
|
|
layer: { source: 'AIS' },
|
|
});
|
|
selection.installInteraction(viewer);
|
|
t.after(() => selection.removeVesselInteraction());
|
|
return { fake, state, vessel, focused };
|
|
}
|
|
|
|
test("a click on a mission label over a vessel's card never selects or focuses the vessel", (t) => {
|
|
const h = selectionHarness(t);
|
|
h.fake.label.over = true;
|
|
h.fake.click();
|
|
assert.equal(h.state.selectedRecord, null);
|
|
assert.deepEqual(h.focused, [], 'the camera is not sent to the vessel');
|
|
});
|
|
|
|
test('a click on a mission label keeps the selected vessel', (t) => {
|
|
const h = selectionHarness(t);
|
|
// Off the label, a click on the card selects and focuses its vessel.
|
|
h.fake.click();
|
|
assert.equal(h.state.selectedRecord, h.vessel);
|
|
assert.deepEqual(h.focused, ['v1']);
|
|
// The label on top is its own click: the vessel stays selected.
|
|
h.fake.label.over = true;
|
|
h.fake.click();
|
|
assert.equal(h.state.selectedRecord, h.vessel);
|
|
assert.deepEqual(h.focused, ['v1']);
|
|
});
|