Files
gods-eye-view/src/ui/entityContextBridge.test.mjs
T
Sameh Khamis bb3bf9858b fix(click): the card or label on top takes the click in every layer
Review fixes for #1781:

- One rule for cards: the world-overlay host hands its hit test to the
  pick registry, and every click handler reads the topmost interactive
  card or label once per click (`clickCard`, `isUnderOtherCard` in
  src/data/pickRegistry.js), so all handlers agree in any listener order.
  A layer whose own card or label is on top acts on it whatever is drawn
  under it; a layer under another layer's card neither acts nor treats
  the click as empty space (a tracked aircraft stays tracked, a selection
  stays selected); Context names nothing under a card. A selected news
  card over a vessel no longer opens the link and selects the vessel.
- With one rule, the per-owner arbitration options are no longer read
  and are removed: `passive`, `expanded` and `declinesClick` pick owners,
  `rememberClickPickActions`, `isActedOnByOtherLayer`, card backgrounds
  and `cardKeepsClick`. The dispatcher is unchanged from main.
- A drag that ends on a quake disc, label or card does nothing; opening
  the USGS page or clearing the selection needs a clean click.
- A click on the map under another layer's card opens no Street Level
  ground image.
- A CCTV card that is going away is still not the scene under it.
- Docs and changelog describe the new rule.
2026-11-18 18:23:41 -08:00

86 lines
3.0 KiB
JavaScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { createPinia } from 'pinia';
import { installEntityContext } from './entityContextBridge.js';
import { useEntityCardStore } from './stores/entityCard.js';
import { fakeInput } from '../input/testDoubles.mjs';
import {
registerPickOwner,
setClickCardHitTest,
unregisterPickOwner,
} from '../data/pickRegistry.js';
// The card or label painted on top takes the click: Context names nothing
// under it, exact or nearby, an acting owner's item or a passive one, and
// keeps its own card. On open map it names what the click found.
test('Context names nothing under a card painted on top, and keeps its card', (t) => {
const previous = globalThis.matchMedia;
globalThis.matchMedia = () => ({ matches: true });
t.after(() => {
if (previous) globalThis.matchMedia = previous;
else delete globalThis.matchMedia;
});
const fire = { set: 'test-fires:1', id: 'fire:1' };
const plane = { set: 'test-planes:1', id: 'plane:1' };
const route = { set: 'test-route:1', id: 'route:line' };
registerPickOwner('test-fires', (id) => id === fire.id);
registerPickOwner('test-planes', (id) => id === plane.id);
registerPickOwner('test-route', (id) => id.startsWith('route:'));
let cardOnTop = false;
// The card on top at a click, as the host answers the pick registry.
setClickCardHitTest(() =>
cardOnTop ? { sourceId: 'earthquake-card', entryId: 'q' } : null,
);
t.after(() => {
setClickCardHitTest(null);
unregisterPickOwner('test-fires');
unregisterPickOwner('test-planes');
unregisterPickOwner('test-route');
});
let exact = null;
let near = null;
const viewer = {
scene: {
pick: () => (exact ? { id: exact } : null),
drillPick: () => (near ? [{ id: near }] : []),
},
};
const input = fakeInput(viewer);
const pinia = createPinia();
const disconnect = installEntityContext({
viewer,
getDataManager: () => ({
isEnabled: () => true,
layers: new Map(),
getAll: () => [],
}),
pinia,
});
t.after(() => {
disconnect();
input.destroy();
});
const store = useEntityCardStore(pinia);
const named = [];
let clears = 0;
store.select = (identity) => named.push(identity.id);
store.clear = () => clears++;
const tap = (hitExact, hitNear) => {
exact = hitExact;
near = hitNear;
named.length = 0;
input.click();
return [...named];
};
assert.deepEqual(tap(null, fire), ['fire:1'], 'open map: a near fire');
assert.deepEqual(tap(route, null), ['route:line'], 'open map: a route');
cardOnTop = true;
assert.deepEqual(tap(null, fire), [], 'under a card: a near fire');
assert.deepEqual(tap(fire, fire), [], 'under a card: an exact fire');
assert.deepEqual(tap(plane, plane), [], 'under a card: an aircraft');
assert.deepEqual(tap(route, null), [], 'under a card: a route');
const cleared = clears;
tap(null, null);
assert.equal(clears, cleared, 'a card over open map is not open map');
});