MapWorkspace.tsx opened with ~590 lines of theme catalogue, dataset matching and label formatting above a 3.200-line component. None of it is React, all of it is independently testable, and both render paths read from it, so it belongs beside the pure helpers that already live in mapWorkspaceUtils. The contract tests that read MapWorkspace.tsx would have gone red for a move that changes no behaviour at all — 24 of them. That is the brittleness the frontend_contract helper exists to remove, so it gains read_map_workspace(): the workspace is one feature spread over several modules, and a contract belongs to the feature rather than to whichever file currently holds it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
41 lines
1.7 KiB
Python
41 lines
1.7 KiB
Python
from pathlib import Path
|
|
from tests.frontend_contract import assert_calls, assert_mentions, assert_wired, read_map_workspace
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
|
|
|
|
def read(path: str) -> str:
|
|
return (ROOT / path).read_text(encoding="utf-8")
|
|
|
|
|
|
def test_work_area_change_clears_stale_spatial_results_before_switching_area() -> None:
|
|
workspace = read_map_workspace()
|
|
|
|
assert "const handleSelectMapArea = (areaId: string) => {" in workspace
|
|
assert "clearAreaSelection()\n onSelectMapArea(areaId)" in workspace
|
|
# One call site is a formatting rule; the contract is that the area
|
|
# selector routes through the handler that clears the drawn selection.
|
|
assert_calls(workspace, "handleSelectMapArea", first_argument="event.target.value")
|
|
|
|
|
|
def test_cancelled_selection_requests_cannot_restore_stale_results() -> None:
|
|
selection_hook = read("frontend/src/hooks/useMapSelectionExtract.ts")
|
|
themes_hook = read("frontend/src/hooks/useMapThemeSelectionInsights.ts")
|
|
|
|
assert "const requestSequence = useRef(0)" in selection_hook
|
|
assert "requestSequence.current += 1\n setMapSelectionBbox(null)" in selection_hook
|
|
assert "if (requestSequence.current !== sequence)" in selection_hook
|
|
assert "const requestSequence = useRef(0)" in themes_hook
|
|
assert "requestSequence.current += 1\n setThemeInsights([])" in themes_hook
|
|
assert "if (requestSequence.current !== sequence)" in themes_hook
|
|
|
|
|
|
def test_viewport_status_uses_end_user_map_language() -> None:
|
|
hook = read("frontend/src/hooks/useViewportVectorLayer.ts")
|
|
|
|
assert "load buildings from PostGIS" not in hook
|
|
assert "Zichtbare kaartobjecten laden..." in hook
|
|
assert "kaartobjecten getoond" in hook
|
|
assert "PostGIS" not in hook
|