Files
gods-eye-view/src/overlays/wildlifeSightingOverlay.test.mjs
T
Yehe LiuandClaude Opus 5.5 14f88b3e08 feat: Wildlife Sightings layer from iNaturalist and Acartia
Recent community wildlife observations, as a new Wildlife group in the
layer panel.

- Server: keyless iNaturalist proxy (v2 observations with only the
  projected fields; undocumented v1 UTFGrid density tiles, decoded on the
  server) sharing one paced queue (burst 4, ~1/s, 60/min, 8,000/day budget,
  up to four in flight), in-memory caches and upstream-only cooldowns;
  Acartia Salish Sea marine-mammal feed rounded to 0.01 degrees with
  comments dropped.
- Layer: grid counts drawn as a soft view-ranked density glow; real sampled
  sightings as taxon badges at their true positions with ambient photo
  thumbnails and labels; obscured records stay privacy cells; a clicked
  sighting stays pinned through camera moves and refreshes.
- Anchored photo card per selection with the single iNaturalist link;
  attribution in the layer row and the Data attribution popover.
- Filters (CONFIRMED, taxa presets) round-trip in share links with token 9.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-05 16:17:12 -05:00

187 lines
5.5 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {
buildWildlifeSelectedLabel,
buildWildlifeThumbnailEntry,
} from '../layers/wildlifeSightings/cards.js';
import {
normalizeOverlayEntry,
paintLaneForOverlayEntry,
} from './worldOverlay.js';
import {
clearWorldOverlayTextMeasureCache,
measureOverlayEntry,
paintOverlayEntry,
} from './worldOverlayDraw.js';
import { WORLD_OVERLAY_STYLE } from './worldOverlayTokens.js';
function paintingContext(glyphWidth = 6) {
const text = [];
const fills = [];
const strokes = [];
const images = [];
return {
text,
fills,
strokes,
images,
measureText: (text) => ({ width: Array.from(text).length * glyphWidth }),
save() {},
restore() {},
beginPath() {},
roundRect() {},
moveTo() {},
lineTo() {},
fillRect() {},
fill() {
fills.push(this.fillStyle);
},
stroke() {
strokes.push(this.strokeStyle);
},
fillText(value) {
text.push(value);
},
drawImage(...args) {
images.push(args);
},
};
}
test('wildlife thumbnail titles paint a word-boundary ellipsis after normalization and width fitting', () => {
for (const [commonName, glyphWidth, expected] of [
["Bullock's Oriole", 6, "BULLOCK'S…"],
['Great Blue Heron', 11, 'GREAT…'],
['Superlongunbrokentaxon', 6, 'SUPERLONGUNBRO…'],
]) {
clearWorldOverlayTextMeasureCache();
const entry = normalizeOverlayEntry('wildlife-sightings', {
...buildWildlifeThumbnailEntry(
{
stableId: 'inat:1',
commonName,
observedAt: 0,
photo: {
square:
'https://inaturalist-open-data.s3.amazonaws.com/photos/1/square.jpg',
licence: 'cc-by',
attribution: 'Synthetic Photographer',
},
},
0,
{ image: { width: 75, height: 75 } },
),
position: { x: 1, y: 2, z: 3 },
});
const ctx = paintingContext(glyphWidth);
entry._overlayLayout = measureOverlayEntry(ctx, entry);
paintOverlayEntry(ctx, entry, {
rect: {
x: 10,
y: 20,
w: entry._overlayLayout.w,
h: entry._overlayLayout.h,
},
});
assert.equal(ctx.text[0], expected);
assert.ok(ctx.measureText(ctx.text[0]).width <= 96);
assert.ok(entry.accessibilityLabel.includes(commonName));
}
});
test('selected thumbnails retain their image in the host selected chrome and lane, without a link line', () => {
const entry = normalizeOverlayEntry('wildlife-sightings', {
...buildWildlifeThumbnailEntry(
{
stableId: 'inat:1',
commonName: 'Synthetic bird',
observedAt: 0,
uri: 'https://www.inaturalist.org/observations/1',
photo: {
square:
'https://inaturalist-open-data.s3.amazonaws.com/photos/1/square.jpg',
licence: 'cc-by',
attribution: 'Synthetic Photographer',
},
},
0,
{ selected: true, image: { width: 75, height: 75 } },
),
position: { x: 1, y: 2, z: 3 },
});
const ctx = paintingContext();
entry._overlayLayout = measureOverlayEntry(ctx, entry);
paintOverlayEntry(ctx, entry, {
rect: {
x: 10,
y: 20,
w: entry._overlayLayout.w,
h: entry._overlayLayout.h,
},
});
assert.equal(entry.selected, true);
assert.equal(
paintLaneForOverlayEntry(entry),
paintLaneForOverlayEntry({ selected: true }),
);
assert.equal(entry._overlayLayout.thumbH, 72);
assert.equal(ctx.images.length, 1);
assert.ok(ctx.fills.includes(WORLD_OVERLAY_STYLE.selectedBackground));
assert.ok(ctx.strokes.includes(WORLD_OVERLAY_STYLE.selectedBorder));
assert.ok(!ctx.text.some((line) => String(line).includes('↗')));
});
test('selected wildlife names retain a bounded title with the host selected metrics', () => {
for (const origin of ['inaturalist', 'acartia']) {
clearWorldOverlayTextMeasureCache();
const row = {
stableId: `${origin}:1`,
origin,
commonName:
'Synthetic bird with a very long common name that cannot widen the globe label',
scientificName: 'Avis synthetica',
iconic: 'Aves',
photo: {
square:
'https://inaturalist-open-data.s3.amazonaws.com/photos/1/square.jpg',
attribution:
'Synthetic Photographer, full attribution belongs in the dialog',
licence: 'cc-by',
},
};
const entry = normalizeOverlayEntry('wildlife-sightings-selected', {
...buildWildlifeSelectedLabel(row),
position: { x: 1, y: 2, z: 3 },
});
const fonts = [];
const ctx = {
font: '',
measureText(text) {
fonts.push(this.font);
return { width: [...text].length * 6 };
},
};
const layout = measureOverlayEntry(ctx, entry);
assert.equal(entry.variant, 'label');
assert.equal(
entry.selected,
true,
'selected names use the host selected painter',
);
assert.equal(entry.protected, true);
assert.equal(entry.paintLane, 'selected');
assert.equal(
paintLaneForOverlayEntry(entry),
paintLaneForOverlayEntry({ selected: true }),
);
assert.equal(entry.pinned, false);
assert.equal(entry.interactive, false);
assert.equal(entry.placement, 'above');
assert.deepEqual(entry.details, []);
assert.equal(entry.image, null);
assert.equal(layout.h, 31, 'shared selected title and padding');
assert.ok(layout.w <= 264, `bounded name, got ${layout.w}px`);
assert.deepEqual(fonts, [WORLD_OVERLAY_STYLE.fontSelected]);
}
});