"""Tests for the rendered homepage -- ported from backend/tests/web/test_homepage.py (repo-split Stage 4): content.py's Jinja rendering lives in this service now, not backend's. The cache-only "unusual right now" precompute (api/homepage.py) itself stays tested in backend/tests/web/test_homepage.py -- nothing about it moved. """ import datetime import pathlib import time import pytest from api import homepage from data import cities from api import content_payloads from conftest import B def _pick(name, pct, cls, grade, tail, slug=None): return { "slug": slug or (name.lower().replace(" ", "-") + "-xx"), "name": name, "display": f"{name}, Somewhere", "lat": 1.0, "lon": 2.0, "cell_id": "1_2", "date": datetime.date.today().isoformat(), "metric": "tmax", "metric_label": "High temp", "window_label": "mid-July", "value": 99.0, "normal": 88.0, "percentile": pct, "pct_label": homepage._pct_label(pct), "grade": grade, "grade_label": homepage._grade_label(grade, tail), "cls": cls, "departure": abs(pct - 50), "tail": tail, } @pytest.fixture def no_feed(monkeypatch): """The homepage with no precomputed feed at all.""" monkeypatch.setattr(homepage, "load", lambda: None) return None def test_homepage_is_complete_without_js(client, no_feed): """A crawler (or a reader with JS off) gets the whole page as real HTML.""" r = client.get(f"{B}/") assert r.status_code == 200 html = r.text assert "How unusual is your weather?" in html assert "How it works" in html assert "Climate context for 1,000 cities" in html assert "Free. No ads. No tracking." in html # The interactive tool's DOM contract survives the move to Jinja. for dom_id in ('id="find-btn"', 'id="date-input"', 'id="panel"', 'id="placeholder"', 'id="results"'): assert dom_id in html # Exactly one h1: the hero headline. The brand degrades to a
. assert html.count("