Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions services/concept_lab_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
21 changes: 11 additions & 10 deletions tests/test_concept_lab_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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})
Expand Down
Loading