"""Conflicts Leaflet overlay: default-off toggle, catalog fetch, no jitter.""" from __future__ import annotations from pathlib import Path ROOT = Path(__file__).resolve().parent.parent HTML = (ROOT / "app/static/index.html").read_text() def _fn(name: str, until: str | None = None) -> str: chunk = HTML.split(f"function {name}", 1)[1] if until: chunk = chunk.split(until, 1)[0] return chunk def test_conflicts_toggle_default_off(): assert 'id="lp-conflicts-on"' in HTML assert 'id="conflicts-layer"' in HTML assert "> Conflicts<" in HTML or "> Conflicts", 1)[0] assert "checked" not in on def test_conflicts_fetches_catalog_not_liveuamap(): js = _fn("loadConflicts", "/* ═══════════════ INITIAL LOAD") assert "/api/conflicts" in js assert "liveuamap.com" not in HTML.lower() assert "Math.random" not in js assert "jitter" not in js.lower() def test_conflicts_not_refetched_on_moveend(): refresh = HTML.split("function refreshLiveOverlays", 1)[1].split( "function addExtraAttrib", 1 )[0] assert "loadConflicts" not in refresh assert "probeConflicts" not in refresh init = HTML.split("function initMap", 1)[1].split("function readMapPrefs", 1)[0] assert "probeConflicts()" in init assert "loadConflicts(true)" not in init assert "paintConflicts()" not in init def test_conflicts_hides_toggle_on_404(): js = _fn("loadConflicts", "/* ═══════════════ INITIAL LOAD") assert "r.status === 404" in js assert "hideConflictsToggle()" in js hide = _fn("hideConflictsToggle", "function paintConflicts") assert "row.hidden = true" in hide assert "lp-conflicts-on" in hide def test_conflicts_popup_and_severity_colors(): paint = _fn("paintConflicts", "async function probeConflicts") assert "z.label" in paint assert "z.description" in paint assert "eventCount" in paint assert "L.circleMarker" in paint assert "z.lat == null || z.lon == null" in paint assert "Number.isFinite(lat)" in paint color = _fn("conflictSeverityColor", "function hideConflictsToggle") assert "war" in color and "#ff2a6d" in color assert "high" in color and "#fb923c" in color assert "elevated" in color and "#facc15" in color