From 9a899f94fde4f3c986b4e203676a89e348c20683 Mon Sep 17 00:00:00 2001 From: Echo Date: Tue, 10 Feb 2026 19:07:21 +0000 Subject: [PATCH] feat: US-005 - Frontend: Stats section collapse with chevron --- dashboard/habits.html | 23 ++ dashboard/tests/test_habits_frontend.py | 272 +++++++++++++++++++++++- 2 files changed, 294 insertions(+), 1 deletion(-) diff --git a/dashboard/habits.html b/dashboard/habits.html index cba9669..ed833a6 100644 --- a/dashboard/habits.html +++ b/dashboard/habits.html @@ -1696,9 +1696,29 @@ if (content.classList.contains('visible')) { content.classList.remove('visible'); chevron.classList.remove('expanded'); + // Save collapsed state to localStorage + localStorage.setItem('habits-stats-collapsed', 'true'); } else { content.classList.add('visible'); chevron.classList.add('expanded'); + // Save expanded state to localStorage + localStorage.setItem('habits-stats-collapsed', 'false'); + } + } + + function restoreWeeklySummaryState() { + const content = document.getElementById('weeklySummaryContent'); + const chevron = document.getElementById('weeklySummaryChevron'); + const isCollapsed = localStorage.getItem('habits-stats-collapsed'); + + // Default is collapsed (isCollapsed === null means first visit) + // Only expand if explicitly set to 'false' + if (isCollapsed === 'false') { + content.classList.add('visible'); + chevron.classList.add('expanded'); + } else { + content.classList.remove('visible'); + chevron.classList.remove('expanded'); } } @@ -2452,6 +2472,9 @@ } }); + // Restore collapsed/expanded state from localStorage + restoreWeeklySummaryState(); + loadHabits(); diff --git a/dashboard/tests/test_habits_frontend.py b/dashboard/tests/test_habits_frontend.py index 9e42986..4ce2d50 100644 --- a/dashboard/tests/test_habits_frontend.py +++ b/dashboard/tests/test_habits_frontend.py @@ -2,6 +2,7 @@ Test suite for Habits frontend page structure and navigation Story US-002: Frontend - Compact habit cards (~100px height) Story US-003: Frontend - Check/uncheck toggle behavior +Story US-005: Frontend - Stats section collapse with chevron Story US-006: Frontend - Page structure, layout, and navigation link Story US-007: Frontend - Habit card component Story US-008: Frontend - Create habit modal with all options @@ -1752,9 +1753,23 @@ def run_all_tests(): test_render_habits_uses_search, test_event_listeners_initialized, test_typecheck_us004, + # US-005 tests (Stats section collapse) + test_stats_section_collapsed_by_default, + test_stats_header_clickable_with_chevron, + test_toggle_function_exists, + test_chevron_rotates_on_expand, + test_content_displays_when_visible, + test_localstorage_save_on_toggle, + test_restore_function_exists, + test_restore_expands_when_false, + test_restore_collapses_by_default, + test_restore_called_on_page_load, + test_css_transition_300ms, + test_height_constraint_collapsed, + test_typecheck_us005, ] - print(f"\nRunning {len(tests)} frontend tests for US-002, US-003, US-006 through US-014...\n") + print(f"\nRunning {len(tests)} frontend tests for US-002, US-003, US-005, US-006 through US-014...\n") failed = [] for test in tests: @@ -2258,5 +2273,260 @@ def test_typecheck_us004(): assert result.returncode == 0, f"Typecheck failed: {result.stderr}" print("✓ Test 137: Typecheck passes") +# ========== US-005 Tests: Stats section collapse with chevron ========== + +def test_stats_section_collapsed_by_default(): + """Test 138: Stats section (weekly summary) starts collapsed by default""" + html_path = Path(__file__).parent.parent / 'habits.html' + content = html_path.read_text() + + # Check that weekly-summary-content does NOT have 'visible' class by default in HTML + assert '
' in content or \ + '