From efa663d70ca6be8f8bd109103513b36238e49c24 Mon Sep 17 00:00:00 2001 From: mormal1016 Date: Mon, 16 Nov 2026 02:01:32 +0800 Subject: [PATCH] fix(lab): separate prediction choices and emphasize check action --- services/concept_lab_ui.py | 5 +++-- tests/test_concept_lab_steps.py | 21 +++++++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/services/concept_lab_ui.py b/services/concept_lab_ui.py index 5aa83fb..95a3f58 100644 --- a/services/concept_lab_ui.py +++ b/services/concept_lab_ui.py @@ -152,9 +152,10 @@ def prediction(topic): Once a prediction has been checked, "Next: explore" leads on to step 2. """ prompt, choices = PREDICTIONS[topic] - selected = st.radio(tr(prompt), choices, index=None, format_func={choice: tr(choice) for choice in choices}.get, horizontal=True, + selected = st.radio(tr(prompt), choices, index=None, format_func={choice: tr(choice) for choice in choices}.get, horizontal=False, key=f'lab_{topic}_prediction', on_change=keep_value, args=(f'lab_{topic}_prediction',)) - if st.button(tr('Check my prediction'), key=f'lab_{topic}_check'): + if st.button(tr('Check my prediction'), key=f'lab_{topic}_check', + type='primary', width='stretch'): st.session_state[f'lab_{topic}_checked'] = selected checked = st.session_state.get(f'lab_{topic}_checked') if checked is not None and checked == selected: diff --git a/tests/test_concept_lab_steps.py b/tests/test_concept_lab_steps.py index 1526de1..863b16a 100644 --- a/tests/test_concept_lab_steps.py +++ b/tests/test_concept_lab_steps.py @@ -200,6 +200,10 @@ def test_next_explore_appears_only_after_a_prediction_is_checked(topic): app = _lab() assert not any(button.key == f"lab_{topic}_next_explore" for button in app.button) + radio = app.radio(key=f"lab_{topic}_prediction") + assert radio.proto.horizontal is False + assert app.button(key=f"lab_{topic}_check").proto.type == "primary" + # Checking with no choice only asks for one. app.button(key=f"lab_{topic}_check").click().run() assert "Choose a prediction first." in [item.value for item in app.info] @@ -544,20 +548,17 @@ def test_corner_conclusion_waits_until_the_student_has_predicted(): assert title in [s.value for s in later.subheader] -def _same_click_twice(topic): - import streamlit as st - from services.concept_lab_ui import _set_answer_shown - - _set_answer_shown(topic, True) - _set_answer_shown(topic, True) - st.write(str(st.session_state[f"lab_{topic}_answer_shown"])) - - @pytest.mark.parametrize("topic", TOPICS) def test_a_double_click_on_show_answer_leaves_the_answer_shown(topic): # The button carries the state it asks for, so the same click arriving twice # (the second half of a double click landing after the rerun started) changes nothing. - twice = AppTest.from_function(_same_click_twice, kwargs={"topic": topic}).run() + twice = AppTest.from_string( + "import streamlit as st\n" + "from services.concept_lab_ui import _set_answer_shown\n" + f"_set_answer_shown({topic!r}, True)\n" + f"_set_answer_shown({topic!r}, True)\n" + f"st.write(str(st.session_state['lab_{topic}_answer_shown']))\n" + ).run() assert not twice.exception and twice.markdown[0].value == "True" app = _lab(**{f"lab_{topic}_step": 3})