readthrough / tests /test_continuity_view.py
Viney's picture
feat: add compact mode to section headers for half-width grid cells
00fa796
Raw History Blame Contribute Delete
2.56 kB
def test_status_badge_covers_every_status():
"""t() defaults to English outside a Streamlit runtime (see dashboard/i18n.py::t
docstring), so the English label is what a pytest-run assertion can check."""
from dashboard.continuity_view import _status_badge
labels = {"new": "New", "ongoing": "Ongoing", "escalated": "Escalated", "resolved": "Resolved", "stale": "Stale"}
for status, label in labels.items():
html = _status_badge(status)
assert "<span" in html
assert label in html
def test_partition_threads_groups_open_before_closed_and_preserves_order():
from dashboard.continuity_view import _partition_threads
threads = [
{"thread_id": "a", "status": "resolved"},
{"thread_id": "b", "status": "ongoing"},
{"thread_id": "c", "status": "new"},
{"thread_id": "d", "status": "stale"},
{"thread_id": "e", "status": "escalated"},
]
open_threads, closed_threads = _partition_threads(threads)
assert [t["thread_id"] for t in open_threads] == ["b", "c", "e"]
assert [t["thread_id"] for t in closed_threads] == ["a", "d"]
def test_partition_threads_empty_list():
from dashboard.continuity_view import _partition_threads
assert _partition_threads([]) == ([], [])
def test_render_swallows_threads_db_failure(monkeypatch, capsys):
"""A threads_db failure (e.g. 'database is locked' on the shared HF Space)
must not abort rendering the rest of the page -- render() logs and returns,
matching dashboard/verdict.py::_render_brief_diff's fail-closed pattern."""
from dashboard import continuity_view
def _boom(ticker):
raise RuntimeError("database is locked")
monkeypatch.setattr("storage.threads_db.list_all_threads", _boom)
continuity_view.render({"ticker": "AAPL"}) # must not raise
assert "database is locked" in capsys.readouterr().err
def test_render_compact_forwards_to_explained_header(monkeypatch):
"""compact=True must reach the header markup, not just be accepted and dropped."""
from dashboard import continuity_view
monkeypatch.setattr("storage.threads_db.list_all_threads", lambda ticker: [])
captured = {}
original = continuity_view.st.markdown
def _spy(html, **kwargs):
captured.setdefault("html", []).append(html)
return original(html, **kwargs)
monkeypatch.setattr(continuity_view.st, "markdown", _spy)
continuity_view.render({"ticker": "AAPL"}, compact=True)
assert any("margin:4px 0 10px" in html for html in captured["html"])