Files
worldmonitor/tests/urlState.test.mts
Laksh f4a3ccb28c feat(country-brief): maximize mode, shareable URLs, expanded sections & i18n (#743)
* country deep dive

* feat(country-brief): add maximize mode, shareable URLs, and expanded sections

- Add maximize button that expands side panel to fullscreen overlay (960px centered)
- URL state: ?country=IR&expanded=1 deep-links to maximized view
- Expanded sections: full brief with citations, market volume bars, per-asset
  infrastructure lists, nearby ports, and 15 news items (vs 5 in side panel)
- Click-outside-to-minimize, Escape key handling (maximize→minimize→close)
- XSS-safe brief formatting: escapeHtml first, then controlled transforms
- Focus trap filters hidden .cdp-expanded-only elements via offsetParent check
- Extract getCountryCentroid to country-geometry.ts, remove duplicate helpers
- Unify panel interface via CountryBriefPanel, remove instanceof checks
- Remove classic CountryBriefPage toggle (always use deep-dive panel)
- Migrate hardcoded strings to i18n (signal chips, component bars, labels)
- Add 8 unit tests for expanded param URL round-trip

---------

Co-authored-by: Elie Habib <elie.habib@gmail.com>
2026-03-02 14:47:14 +04:00

91 lines
3.2 KiB
TypeScript

import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { parseMapUrlState, buildMapUrl } from '../src/utils/urlState.ts';
const EMPTY_LAYERS = {
conflicts: false, bases: false, cables: false, pipelines: false,
hotspots: false, ais: false, nuclear: false, irradiators: false,
sanctions: false, weather: false, economic: false, waterways: false,
outages: false, cyberThreats: false, datacenters: false, protests: false,
flights: false, military: false, natural: false, spaceports: false,
minerals: false, fires: false, ucdpEvents: false, displacement: false,
climate: false, startupHubs: false, cloudRegions: false,
accelerators: false, techHQs: false, techEvents: false,
tradeRoutes: false, iranAttacks: false, gpsJamming: false,
};
describe('parseMapUrlState expanded param', () => {
it('parses expanded=1 as true', () => {
const state = parseMapUrlState('?country=IR&expanded=1', EMPTY_LAYERS);
assert.equal(state.country, 'IR');
assert.equal(state.expanded, true);
});
it('parses missing expanded as undefined', () => {
const state = parseMapUrlState('?country=IR', EMPTY_LAYERS);
assert.equal(state.country, 'IR');
assert.equal(state.expanded, undefined);
});
it('ignores expanded=0', () => {
const state = parseMapUrlState('?country=IR&expanded=0', EMPTY_LAYERS);
assert.equal(state.expanded, undefined);
});
});
describe('buildMapUrl expanded param', () => {
const base = 'https://worldmonitor.app/';
const baseState = {
view: 'global' as const,
zoom: 2,
center: { lat: 0, lon: 0 },
timeRange: '24h' as const,
layers: EMPTY_LAYERS,
};
it('includes expanded=1 when true', () => {
const url = buildMapUrl(base, { ...baseState, country: 'IR', expanded: true });
const params = new URL(url).searchParams;
assert.equal(params.get('country'), 'IR');
assert.equal(params.get('expanded'), '1');
});
it('omits expanded when falsy', () => {
const url = buildMapUrl(base, { ...baseState, country: 'IR' });
const params = new URL(url).searchParams;
assert.equal(params.get('country'), 'IR');
assert.equal(params.has('expanded'), false);
});
it('omits expanded when undefined', () => {
const url = buildMapUrl(base, { ...baseState, country: 'IR', expanded: undefined });
const params = new URL(url).searchParams;
assert.equal(params.has('expanded'), false);
});
});
describe('expanded param round-trip', () => {
const base = 'https://worldmonitor.app/';
const baseState = {
view: 'global' as const,
zoom: 2,
center: { lat: 0, lon: 0 },
timeRange: '24h' as const,
layers: EMPTY_LAYERS,
};
it('round-trips country=IR&expanded=1', () => {
const url = buildMapUrl(base, { ...baseState, country: 'IR', expanded: true });
const parsed = parseMapUrlState(new URL(url).search, EMPTY_LAYERS);
assert.equal(parsed.country, 'IR');
assert.equal(parsed.expanded, true);
});
it('round-trips country=IR without expanded', () => {
const url = buildMapUrl(base, { ...baseState, country: 'IR' });
const parsed = parseMapUrlState(new URL(url).search, EMPTY_LAYERS);
assert.equal(parsed.country, 'IR');
assert.equal(parsed.expanded, undefined);
});
});