from core.route import Step1Result from core.schemas import RouteResponse from ui.components import render_route_summary def _result(sectors, lens, type_, in_scope, out): return Step1Result( route=RouteResponse(sectors=sectors, lens=lens, type=type_), in_scope=in_scope, out_of_scope=out, ) def test_summary_lists_in_scope_sectors(): md = render_route_summary(_result(["WASH"], ["Impact"], ["Context"], ["WASH"], [])) assert "WASH" in md assert "Impact" in md assert "Context" in md def test_summary_shows_out_of_scope_notice(): md = render_route_summary( _result(["WASH", "Health"], [], [], ["WASH"], ["Health"]) ) assert "outside catalog" in md.lower() assert "Health" in md assert "WASH" in md def test_summary_no_notice_when_all_in_scope(): md = render_route_summary(_result(["WASH"], [], [], ["WASH"], [])) assert "outside catalog" not in md.lower() def test_sector_groups_split_by_catalog(): from ui.components import make_sector_group, make_sector_group_no_catalog in_scope = make_sector_group() no_cat = make_sector_group_no_catalog() def labels(group): # Gradio normalises choices to (label, value) tuples return [c[0] if isinstance(c, (list, tuple)) else c for c in group.choices] assert "WASH" in labels(in_scope) assert "Food Security" in labels(in_scope) assert "WASH" not in labels(no_cat) # at least one real out-of-scope sector lands in the no-catalog group assert len(labels(no_cat)) >= 1 assert all(s not in labels(no_cat) for s in ("WASH", "Food Security", "Shelter"))