Files
meshcore-hub/tests/test_web/test_advertisements.py
Louis King a5fabf7d46 chore(web): remove lit-html fallback & legacy code — Phase 4
The React frontend is complete (Phases 1-3); the lit-html fallback is dead
(its vendor globals were removed in Phase 3). Delete it and the scaffolding:

- Delete the entire src/meshcore_hub/web/static/js/spa/ lit-html tree,
  LitBridge.tsx, and legacy.d.ts.
- Remove the @legacy alias from vite.config.ts and tsconfig.json.
- Remove lit-html and qrcodejs from package.json (both unused now).
- Remove the lit-html fallback {% else %} branch from spa.html — the Vite
  build is now required to serve the UI (no fallback bundle).

Tests (fallback no longer exists):
- test_home/advertisements/nodes/messages.py: assert the React mount point
  (id="app") instead of a bundled-or-fallback script tag.
- test_caching.py: JS-cache tests are header-only (static JS is bundled into
  dist/, absent in test env; the middleware sets headers on 404 too); the
  dist-bundle HTML test drops its fallback branch.

Docs:
- AGENTS.md: new Frontend (React) section (host-run npm/vite/tsc toolchain,
  react-chartjs-2/react-leaflet/react-qr-code, CSS load order); clarified the
  compose-stack rule to exempt frontend tooling.
- REACT_MIGRATION.md: Phase 4 complete, final file structure, decisions.

Verified: tsc --noEmit clean, npm run build, full pytest (1463 passed,
22 skipped), pre-commit (passed).
2026-07-21 19:13:01 +01:00

88 lines
3.6 KiB
Python

"""Tests for the advertisements page route (SPA)."""
import json
from fastapi.testclient import TestClient
class TestAdvertisementsPage:
"""Tests for the advertisements page."""
def test_advertisements_returns_200(self, client: TestClient) -> None:
"""Test that advertisements page returns 200 status code."""
response = client.get("/advertisements")
assert response.status_code == 200
def test_advertisements_returns_html(self, client: TestClient) -> None:
"""Test that advertisements page returns HTML content."""
response = client.get("/advertisements")
assert "text/html" in response.headers["content-type"]
def test_advertisements_contains_network_name(self, client: TestClient) -> None:
"""Test that advertisements page contains the network name."""
response = client.get("/advertisements")
assert "Test Network" in response.text
def test_advertisements_contains_app_config(self, client: TestClient) -> None:
"""Test that advertisements page contains SPA config."""
response = client.get("/advertisements")
assert "window.__APP_CONFIG__" in response.text
def test_advertisements_contains_spa_mount(self, client: TestClient) -> None:
"""Test that advertisements page renders the React SPA mount point."""
response = client.get("/advertisements")
assert 'id="app"' in response.text
class TestAdvertisementsPageFilters:
"""Tests for advertisements page with query parameters.
In the SPA architecture, all routes return the same shell.
Query parameters are handled client-side.
"""
def test_advertisements_with_search(self, client: TestClient) -> None:
"""Test advertisements page with search parameter returns SPA shell."""
response = client.get("/advertisements?search=node")
assert response.status_code == 200
def test_advertisements_with_public_key_filter(self, client: TestClient) -> None:
"""Test advertisements page with public_key filter returns SPA shell."""
response = client.get(
"/advertisements?public_key=abc123def456abc123def456abc123de"
)
assert response.status_code == 200
def test_advertisements_with_pagination(self, client: TestClient) -> None:
"""Test advertisements page with pagination parameters returns SPA shell."""
response = client.get("/advertisements?page=1&limit=25")
assert response.status_code == 200
def test_advertisements_page_2(self, client: TestClient) -> None:
"""Test advertisements page 2 returns SPA shell."""
response = client.get("/advertisements?page=2")
assert response.status_code == 200
def test_advertisements_with_all_filters(self, client: TestClient) -> None:
"""Test advertisements page with multiple filters returns SPA shell."""
response = client.get(
"/advertisements?search=test&public_key=abc123&page=1&limit=10"
)
assert response.status_code == 200
class TestAdvertisementsConfig:
"""Tests for advertisements page SPA config content."""
def test_advertisements_config_has_network_name(self, client: TestClient) -> None:
"""Test that SPA config includes network name."""
response = client.get("/advertisements")
text = response.text
config_start = text.find("window.__APP_CONFIG__ = ") + len(
"window.__APP_CONFIG__ = "
)
config_end = text.find(";", config_start)
config = json.loads(text[config_start:config_end])
assert config["network_name"] == "Test Network"