Spaces:
Running
Add Qualtrics-style confirm-skip dialog to questionnaires; test the finish reorder
Browse filesPorted sl-cu-nicewebrl's confirm-dialog pattern: Continue is always
clickable on slider batteries and the free-text strategy page, but if
something's unanswered a dialog asks "are you sure you want to continue
without answering?" (Go back and answer / Continue anyway). belief_stage
deliberately keeps its existing Submit-then-lock pattern instead, matching
sl-cu's own _belief_page (which explicitly does not use the confirm-dialog
there).
Updated test_back_navigation.py's existing Back-chain test for the new
confirm dialog, added a test confirming the dialog is skipped once a
slider has actually been touched, and added test_finish_reorder.py
covering the credits-bridge screen and the simplified final screen.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Files changed (2)
127 unmodified lines128129130131132133134135136137138127 unmodified linesimport asyncio# ?dev=1&start=end lands on Fatigue_post first (no Back there by design)await user.should_see("How tired do you feel right now?")user.find("Continue").click()await asyncio.sleep(0.1)# now on NASA_TLX -- it should have a Back buttonawait user.should_see("Back")user.find("Back").click()await asyncio.sleep(0.1)# should be back on Fatigue_postawait user.should_see("How tired do you feel right now?")127 unmodified lines128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161127 unmodified linesimport asyncio# ?dev=1&start=end lands on Fatigue_post first (no Back there by design)await user.should_see("How tired do you feel right now?")# the slider hasn't been touched, so Continue now triggers the# Qualtrics-style "are you sure" confirmation dialog (ported from sl-cu)user.find("Continue").click()await asyncio.sleep(0.1)await user.should_see("Continue anyway")user.find("Continue anyway").click()await asyncio.sleep(0.1)# now on NASA_TLX -- it should have a Back buttonawait user.should_see("Back")user.find("Back").click()await asyncio.sleep(0.1)# should be back on Fatigue_postawait user.should_see("How tired do you feel right now?")@pytest.mark.module_under_test(web_app)async def test_slider_battery_skips_confirm_dialog_once_touched(user: User) -> None:"""If every slider has been touched, Continue proceeds immediately -- no dialog."""from nicegui import uiawait user.open("/?dev=1&start=end&role=c&theme=harvest&pid=SMOKE_touched_slider")import asyncioawait user.should_see("How tired do you feel right now?")slider = next(iter(user.find(kind=ui.slider).elements))with user.client:slider.value = 70 # triggers on_value_change -> touched[key] = True, same as a real dragawait asyncio.sleep(0.05)user.find("Continue").click()await asyncio.sleep(0.1)# no confirmation dialog -- straight through to NASA_TLXawait user.should_see("Back")assert not user._gather_elements("Continue anyway", None, None, None)
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879"""Credits/money-conversion screen moved to right after gameplay (QuestionnaireTransition),and the true final screen (web_app.finish_experiment) no longer repeats it."""import osos.environ["RELOAD"] = "0"os.environ["STORAGE_SECRET"] = "test"os.environ["PORT"] = "8092"
import asyncioimport reimport pytestimport web_appimport effort_stages as Efrom nicegui.testing import User
@pytest.mark.module_under_test(web_app)async def test_credits_bridge_shows_totals_and_picture_before_questionnaires(user: User) -> None: await user.open("/?dev=1&start=quiz&role=c&theme=harvest&pid=SMOKE_bridge") user.javascript_rules[re.compile(r".*window\.Cornfield.*")] = lambda _match: None from nicegui import ui as ui_module with user.client: from nicegui import app app.storage.user["self_points"] = 42 app.storage.user["partner_points"] = 17 container = ui_module.column()
task = asyncio.create_task(E.credits_bridge_display(None, container)) await asyncio.sleep(0.1) await user.should_see("Almost done!") await user.should_see("42 credits") await user.should_see("17 credits") await user.should_see("Now, please answer a couple of questions") user.find("Continue").click() result = await asyncio.wait_for(task, timeout=5) assert result["self_points"] == 42 assert result["partner_points"] == 17
CLICK_LABELS = ["Continue anyway", "Continue", "Submit", "Close"]
async def _click_any(user: User): # belief_stage's radio option ("Yes") is idempotent to click and must be # selected before Submit does anything -- opportunistically select it first try: user.find("Yes").click() await asyncio.sleep(0.05) except AssertionError: pass for label in CLICK_LABELS: try: el = user.find(label) except AssertionError: continue el.click() await asyncio.sleep(0.05) return label return None
@pytest.mark.module_under_test(web_app)async def test_true_final_screen_has_no_repeated_credits_or_picture(user: User) -> None: await user.open("/?dev=1&start=end&role=c&theme=harvest&pid=SMOKE_final_screen&trials=1&mb=4") user.javascript_rules[re.compile(r".*window\.Cornfield.*")] = lambda _match: None # drive straight through the whole post-task questionnaire chain to reach the true end for _ in range(60): clicked = await _click_any(user) if clicked is None: break try: await user.should_see("Please let the experimenter know you're ready.", retries=1) break except AssertionError: continue await user.should_see("Completed!") await user.should_see("Please let the experimenter know you're ready.") # the credit/money-conversion markdown (now shown earlier, on the bridge screen) must # not be repeated on this true final screen await user.should_not_see("bonus of")