| """Tests for app/pages/5_summary.py — SUMMARY state.""" |
|
|
| import pytest |
| from streamlit.testing.v1 import AppTest |
|
|
| from app.services.mock_data import ( |
| MOCK_ELIGIBILITY_LEDGERS, |
| MOCK_PATIENT_PROFILE, |
| MOCK_TRIAL_CANDIDATES, |
| ) |
|
|
|
|
| @pytest.fixture |
| def summary_app(): |
| at = AppTest.from_file("app/pages/5_summary.py", default_timeout=10) |
| at.session_state["journey_state"] = "SUMMARY" |
| at.session_state["patient_profile"] = MOCK_PATIENT_PROFILE |
| at.session_state["trial_candidates"] = MOCK_TRIAL_CANDIDATES |
| at.session_state["eligibility_ledger"] = MOCK_ELIGIBILITY_LEDGERS |
| at.session_state["parlant_session_id"] = None |
| at.session_state["parlant_agent_id"] = None |
| at.session_state["uploaded_files"] = [] |
| at.session_state["search_anchors"] = None |
| at.session_state["last_event_offset"] = 0 |
| return at.run() |
|
|
|
|
| def test_page_renders_without_error(summary_app): |
| assert len(summary_app.exception) == 0 |
|
|
|
|
| def test_displays_summary_counts(summary_app): |
| all_md = " ".join(str(m.value) for m in summary_app.markdown) |
| all_metrics_labels = " ".join(str(m.label) for m in summary_app.metric) |
| combined = all_md + " " + all_metrics_labels |
| |
| assert any(w in combined.lower() for w in ["eligible", "uncertain", "ineligible", "total"]) |
|
|
|
|
| def test_has_download_buttons(summary_app): |
| |
| assert len(summary_app.button) >= 1 |
|
|
|
|
| def test_has_new_session_button(summary_app): |
| labels = [str(b.label) for b in summary_app.button] |
| assert any( |
| "new" in lbl.lower() or "start" in lbl.lower() or "reset" in lbl.lower() for lbl in labels |
| ) |
|
|
|
|
| def test_new_session_resets_state(summary_app): |
| reset_btns = [ |
| b |
| for b in summary_app.button |
| if any(w in str(b.label).lower() for w in ["new", "start", "reset"]) |
| ] |
| if reset_btns: |
| reset_btns[0].click() |
| at = summary_app.run() |
| assert at.session_state["journey_state"] == "INGEST" |
| assert at.session_state["patient_profile"] is None |
| assert len(at.exception) == 0 |
|
|