Files
geointel/backend/tests/test_sprint237_flanders_thematic_on_demand.py
T
JensandClaude Opus 5 3e4e211fad test frontend wiring instead of frontend formatting
19 tests were failing on main. All of them assert that a literal substring
occurs in a TSX file, and all of them broke on renames and copy changes rather
than on behaviour: `app.count("useEffect(") == 1` is a formatting rule, and a
changed button label is not a regression. 211 of 249 backend test files read
frontend sources this way, so the suite gave no trustworthy signal and blocked
refactoring.

tests/frontend_contract.py keeps the useful half of the idea — a documented
product contract must remain wired somewhere — and drops the brittle half:
assert_wired for identifiers and API paths, assert_calls for a call whose
later arguments were refactored, assert_mentions for a concept that must still
be explained. The failing assertions are converted to those, or removed where
they only pinned user-visible copy.

test_frontend_contract_test_style.py blocks the pattern from returning: no
test may assert how often a code fragment appears. Counting list values or
network calls is unaffected.

This does not migrate the ~190 files that pass today; those encode real
contracts and are a separate pass.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-22 14:34:13 +02:00

74 lines
3.4 KiB
Python

from pathlib import Path
from tests.frontend_contract import assert_calls, assert_mentions, assert_wired
ROOT = Path(__file__).resolve().parents[2]
def read(path: str) -> str:
return (ROOT / path).read_text(encoding="utf-8")
def test_flanders_workspace_exposes_governed_thematic_products_on_demand() -> None:
workspace = read("frontend/src/components/map/MapWorkspace.tsx")
product_hook = read("frontend/src/hooks/useOfficialMapProducts.ts")
selection_hook = read("frontend/src/hooks/useMapThemeSelectionInsights.ts")
api = read("frontend/src/services/api/datasets.ts")
assert "activeScopeProject?.name === FLANDERS_WORKSPACE_PROJECT_NAME" in workspace
assert "new Map<DataThemeId, OnDemandMapProduct>" in workspace
assert_wired(workspace, "space_occupation")
assert "setActiveThemeId(fallbackTheme.id)" in workspace
assert "return `referentiejaar ${observationYear}`" in workspace
assert "kind: 'thematic_raster'" in workspace
assert "productKey: onDemandProduct.productKey" in workspace
assert "datasetsApi.listThematicRasterProducts" in product_hook
assert "datasetsApi.acquireThematicRaster" in selection_hook
assert "datasetsApi.selectThematicRaster" in selection_hook
assert "datasetsApi.get(selectedProjectId, acquisitionJob.output_dataset_id)" in selection_hook
assert "/datasets/thematic-raster/acquire" in api
def test_selection_reads_and_bounded_acquires_all_relevant_themes() -> None:
workspace = read("frontend/src/components/map/MapWorkspace.tsx")
app = read("frontend/src/App.tsx")
selection_hook = read("frontend/src/hooks/useMapThemeSelectionInsights.ts")
# Selection reads the active theme; the loop form is incidental.
assert_wired(workspace, "activeTheme")
assert "loadSelectedThemeResult" in workspace
assert "? onDemandProductsForZones(resolvedZones)" in workspace
assert ".filter((product) => product.theme === activeThemeId)" not in workspace
assert "await loadThemeInsights(bbox, availableThemes, areaId)" in workspace
assert "!regionalPartitionedThemeActive && !onDemandThemeActive" in workspace
assert "onRefreshProjectData" in workspace
assert "selectedProjectId ? loadProjectData(selectedProjectId)" in app
assert "successful.some((item) => item.acquisition)" in selection_hook
assert "await onDatasetsChanged()" in selection_hook
assert "settleWithConcurrency(" in selection_hook
assert "queries," in selection_hook
assert "3," in selection_hook
def test_regional_on_demand_sources_require_a_bounded_drawn_selection() -> None:
workspace = read("frontend/src/components/map/MapWorkspace.tsx")
assert "regionalOnDemandThemeActive" in workspace
# Both regional source kinds need a bounded selection before acquiring.
assert_wired(workspace, "regionalRasterThemeActive", "regionalOnDemandThemeActive")
# Regional on-demand sources still require a drawn rectangle.
assert "Teken" in workspace and "rechthoek" in workspace
assert "begrensde" in workspace or "begrensd" in workspace
def test_frontend_does_not_contact_external_map_services_directly() -> None:
frontend_sources = "\n".join(
path.read_text(encoding="utf-8")
for path in (ROOT / "frontend/src").rglob("*")
if path.suffix in {".ts", ".tsx"}
)
assert "mercatornet.be" not in frontend_sources.casefold()
assert "geo.api.vlaanderen.be" not in frontend_sources.casefold()
assert "GetCoverage" not in frontend_sources