From b2b1e3da2d969fc48646e8007f39e0bb12c0ed6d Mon Sep 17 00:00:00 2001 From: Zerune0 Date: Sun, 15 Nov 2026 12:37:08 -0500 Subject: [PATCH] Enable Home Learning DNA entry before opening a course --- pages/0_Dashboard.py | 14 ++++++++++++-- tests/test_learning_dna.py | 17 ++++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/pages/0_Dashboard.py b/pages/0_Dashboard.py index 9845ecb..a977dbd 100644 --- a/pages/0_Dashboard.py +++ b/pages/0_Dashboard.py @@ -115,11 +115,21 @@ def load_demo_package(filename: str, expected_course_id: str) -> StudyPackage: st.rerun() with st.container(key="dashboard_learning_dna"): + dna_course = selected_course + if dna_course is None and st.session_state["courses"]: + courses_by_id = {course.course_id: course for course in st.session_state["courses"]} + dna_course_id = st.selectbox( + tr("Course"), list(courses_by_id), + format_func=lambda course_id: courses_by_id[course_id].course_name, + key="learning_dna_course", + ) + dna_course = courses_by_id[dna_course_id] if st.button( tr("View Learning DNA"), icon=":material/insights:", - key="learning_dna_open", disabled=selected_course is None, + key="learning_dna_open", disabled=dna_course is None, ): - st.session_state[f"progress_tab_{selected_course.course_id}"] = "Learning DNA" + select_course(st.session_state, dna_course.course_id) + st.session_state[f"progress_tab_{dna_course.course_id}"] = "Learning DNA" st.switch_page("pages/3_Performance.py") # Study totals: one always-visible row of small tiles (assets/paper_panels.css). diff --git a/tests/test_learning_dna.py b/tests/test_learning_dna.py index 5960d12..7ee743b 100644 --- a/tests/test_learning_dna.py +++ b/tests/test_learning_dna.py @@ -214,8 +214,9 @@ def test_dashboard_entry_navigates_to_learning_dna_in_registered_app(): from tests.auth_helpers import signed_in_app app=signed_in_app(ROOT/'app.py').run() assert not app.exception - assert app.button(key='learning_dna_open').disabled + assert not app.button(key='learning_dna_open').disabled course,history=course_and_history() + app.session_state['courses'] = [course] app.session_state['current_course']=course app.session_state['practice_history_test-dna']=history app.session_state['performance_mode_test-dna']='Topic Practice' @@ -235,3 +236,17 @@ def test_dashboard_entry_navigates_to_learning_dna_in_registered_app(): assert 'progress_tab_test-dna' not in app.session_state app.switch_page('pages/3_Performance.py').run() assert [s.value for s in app.subheader if s.value!=course.course_name][0]=='Mastery by topic' + + +def test_dashboard_dna_opens_chosen_demo_without_previously_opening_course(): + from tests.auth_helpers import signed_in_app + app = signed_in_app(ROOT/'app.py').run() + assert app.session_state['current_course'] is None + app.selectbox(key='learning_dna_course').select('calculus-i-demo').run() + app.button(key='learning_dna_open').click().run() + assert not app.exception + assert app.title[0].value == 'Progress' + assert app.session_state['current_course'].course_id == 'calculus-i-demo' + assert app.session_state['progress_tab_calculus-i-demo'] == 'Learning DNA' + sections = [s.value for s in app.subheader if s.value != 'Calculus I Demo'] + assert sections[0] == 'Example ยท Learning DNA'