From 27ee1a271248e9f1de8ecb981a6cabfa8e498b1b Mon Sep 17 00:00:00 2001 From: Peter Stone Date: Fri, 6 Feb 2026 14:53:47 -1000 Subject: Fix missing settings button, disappeared events, and tab refresh bug - Add settings gear icon link to dashboard header - Fix GetTasksByDateRange/GetCardsByDateRange to include overdue items (changed from BETWEEN to <= end, filter completed tasks) - Fix refresh replacing active tab with tasks tab by using htmx.trigger(body, 'refresh-tasks') instead of innerHTML+htmx.process - Add refresh-tasks hx-trigger to meals, shopping, conditions tabs - Add tests for overdue inclusion/exclusion, settings link, template data Co-Authored-By: Claude Opus 4.6 --- internal/handlers/timeline_logic_test.go | 72 ++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) (limited to 'internal/handlers/timeline_logic_test.go') diff --git a/internal/handlers/timeline_logic_test.go b/internal/handlers/timeline_logic_test.go index 9a71741..11406b9 100644 --- a/internal/handlers/timeline_logic_test.go +++ b/internal/handlers/timeline_logic_test.go @@ -251,6 +251,78 @@ func TestCalcCalendarBounds(t *testing.T) { } } +func TestBuildTimeline_IncludesOverdueItems(t *testing.T) { + s := setupTestStore(t) + + // Base: "today" is Jan 2, 2023 + today := time.Date(2023, 1, 2, 0, 0, 0, 0, time.UTC) + yesterday := time.Date(2023, 1, 1, 10, 0, 0, 0, time.UTC) // overdue + todayNoon := time.Date(2023, 1, 2, 12, 0, 0, 0, time.UTC) // current + + // Save a task that is overdue (yesterday) and one that is current (today) + _ = s.SaveTasks([]models.Task{ + {ID: "overdue1", Content: "Overdue task", DueDate: &yesterday}, + {ID: "current1", Content: "Current task", DueDate: &todayNoon}, + }) + + // Query range: today through tomorrow + end := today.AddDate(0, 0, 1) + + items, err := BuildTimeline(context.Background(), s, nil, nil, today, end) + if err != nil { + t.Fatalf("BuildTimeline failed: %v", err) + } + + // Should include both the overdue task and the current task + if len(items) < 2 { + t.Errorf("Expected at least 2 items (overdue + current), got %d", len(items)) + for _, item := range items { + t.Logf(" item: %s (type=%s, time=%s)", item.Title, item.Type, item.Time) + } + } + + // Verify overdue task is marked as overdue + foundOverdue := false + for _, item := range items { + if item.ID == "overdue1" { + foundOverdue = true + if !item.IsOverdue { + t.Error("Expected overdue task to be marked IsOverdue=true") + } + if item.DaySection != models.DaySectionToday { + t.Errorf("Expected overdue task in Today section, got %s", item.DaySection) + } + } + } + if !foundOverdue { + t.Error("Overdue task was not included in timeline results") + } +} + +func TestBuildTimeline_ExcludesCompletedOverdue(t *testing.T) { + s := setupTestStore(t) + + yesterday := time.Date(2023, 1, 1, 10, 0, 0, 0, time.UTC) + today := time.Date(2023, 1, 2, 0, 0, 0, 0, time.UTC) + end := today.AddDate(0, 0, 1) + + // Save a completed overdue task — should NOT appear + _ = s.SaveTasks([]models.Task{ + {ID: "done1", Content: "Done overdue", DueDate: &yesterday, Completed: true}, + }) + + items, err := BuildTimeline(context.Background(), s, nil, nil, today, end) + if err != nil { + t.Fatalf("BuildTimeline failed: %v", err) + } + + for _, item := range items { + if item.ID == "done1" { + t.Error("Completed overdue task should not appear in timeline") + } + } +} + func timePtr(t time.Time) *time.Time { return &t } -- cgit v1.2.3