mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-22 11:12:18 +00:00
As more sources arrive, each one reads the same everywhere it appears: its PROVIDERS chip, coverage lines, overview points, image cones and a single legend swatch. The palette lives in one place, PROVIDER_COLORS in src/layers/streetLevel/policy.js: Mapillary green (#05cb63), Panoramax purple, Google Street View blue. Mapillary drops its age dimming and magenta panoramas: lines and overview points are Mapillary green, cones are green too and 360° images keep their ring shape; the 360°/FLAT filter still separates them, and the selected sequence stays GEV cyan. The provider contract loses `legend`: `colors.coverage` is the source's one colour, and the core composes the legend as one swatch per active source (its name, its colour) followed by Selected. The chip group takes an optional per-chip colour as a `--chip-color` CSS variable, written only when it changes; Street Level chips show it as a swatch dot and, while on, as the chip's border, text and a faint fill. The feature gate checks the legend has one swatch per source plus Selected and that the Mapillary chip carries #05cb63. Co-Authored-By: Claude Opus 5.5 <[email protected]>
55 lines
2.3 KiB
JavaScript
55 lines
2.3 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { syncChipGroup } from './chipGroup.js';
|
|
import { railFixture } from './railTestFixture.mjs';
|
|
|
|
test('keyed chips retain focus, reflect state, reorder and remove without redundant writes', () => {
|
|
let writes = 0;
|
|
const f = railFixture(() => writes++);
|
|
const a = { id: 'a', label: 'GFS', active: true };
|
|
const b = { id: 'b', label: 'ECMWF' };
|
|
const legend = f.document.createElement('span');
|
|
f.container.appendChild(legend);
|
|
syncChipGroup(f.container, [a, b], { before: legend });
|
|
const first = f.container.children[0];
|
|
first.focus();
|
|
const next = [{ ...a, label: 'Changed', busy: true, disabled: true }, b];
|
|
syncChipGroup(f.container, next);
|
|
assert.equal(f.container.children[0], first);
|
|
assert.equal(f.document.activeElement, first);
|
|
assert.equal(first.disabled, true);
|
|
assert.equal(first.getAttribute('aria-busy'), 'true');
|
|
assert.equal(first.getAttribute('aria-pressed'), 'true');
|
|
writes = 0;
|
|
syncChipGroup(f.container, next);
|
|
assert.equal(writes, 0);
|
|
syncChipGroup(f.container, [b, a]);
|
|
assert.equal(f.container.children[1], first);
|
|
assert.equal(f.container.children[2], legend);
|
|
syncChipGroup(f.container, [a]);
|
|
assert.deepEqual(f.container.children, [first, legend]);
|
|
syncChipGroup(f.container, []);
|
|
assert.deepEqual(f.container.children, [legend]);
|
|
});
|
|
|
|
test('a chip colour is set once, changed, and cleared through a CSS variable', () => {
|
|
const f = railFixture(() => {});
|
|
const calls = [];
|
|
syncChipGroup(f.container, [{ id: 'm', label: 'M' }]);
|
|
const chip = f.container.children[0];
|
|
chip.style.setProperty = (name, value) => calls.push(['set', name, value]);
|
|
chip.style.removeProperty = (name) => calls.push(['remove', name]);
|
|
syncChipGroup(f.container, [{ id: 'm', label: 'M' }]);
|
|
assert.deepEqual(calls, [], 'a chip without a colour never touches style');
|
|
syncChipGroup(f.container, [{ id: 'm', label: 'M', color: '#05cb63' }]);
|
|
syncChipGroup(f.container, [{ id: 'm', label: 'M', color: '#05cb63' }]);
|
|
syncChipGroup(f.container, [{ id: 'm', label: 'M', color: '#a66bff' }]);
|
|
syncChipGroup(f.container, [{ id: 'm', label: 'M' }]);
|
|
assert.deepEqual(calls, [
|
|
['set', '--chip-color', '#05cb63'],
|
|
['set', '--chip-color', '#a66bff'],
|
|
['remove', '--chip-color'],
|
|
]);
|
|
assert.equal(chip.dataset.chipColor, undefined);
|
|
});
|