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/handlers_test.go | 105 +++++++++++++++++++++++++++++++++++-- 1 file changed, 102 insertions(+), 3 deletions(-) (limited to 'internal/handlers/handlers_test.go') diff --git a/internal/handlers/handlers_test.go b/internal/handlers/handlers_test.go index f91eb32..d338cd3 100644 --- a/internal/handlers/handlers_test.go +++ b/internal/handlers/handlers_test.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "io" "net/http" "net/http/httptest" "os" @@ -1853,9 +1854,107 @@ func TestHandleTimeline(t *testing.T) { h.HandleTimeline(w, req) - // May return 500 if template not found - if w.Code != http.StatusOK && w.Code != http.StatusInternalServerError { - t.Errorf("Expected status 200 or 500, got %d", w.Code) + if w.Code != http.StatusOK { + t.Errorf("Expected status 200, got %d", w.Code) + } +} + +func TestHandleTimeline_RendersDataToTemplate(t *testing.T) { + h, cleanup := setupTestHandler(t) + defer cleanup() + + // Seed tasks with due dates in range + now := config.Now() + todayNoon := time.Date(now.Year(), now.Month(), now.Day(), 12, 0, 0, 0, now.Location()) + tasks := []models.Task{ + {ID: "t1", Content: "Today task", DueDate: &todayNoon, Labels: []string{}, CreatedAt: now}, + } + _ = h.store.SaveTasks(tasks) + + req := httptest.NewRequest("GET", "/tabs/timeline", nil) + w := httptest.NewRecorder() + + h.HandleTimeline(w, req) + + if w.Code != http.StatusOK { + t.Errorf("Expected status 200, got %d", w.Code) + } + + // Verify the renderer received timeline data with items + mock := h.renderer.(*MockRenderer) + if len(mock.Calls) == 0 { + t.Fatal("Expected renderer to be called") + } + + lastCall := mock.Calls[len(mock.Calls)-1] + if lastCall.Name != "timeline-tab" { + t.Errorf("Expected template 'timeline-tab', got '%s'", lastCall.Name) + } + + data, ok := lastCall.Data.(TimelineData) + if !ok { + t.Fatalf("Expected TimelineData, got %T", lastCall.Data) + } + + if len(data.TodayItems) == 0 { + t.Error("Expected TodayItems to contain at least one item, got 0") + } +} + +// ============================================================================= +// Dashboard Content Verification Tests +// ============================================================================= + +func TestHandleDashboard_ContainsSettingsLink(t *testing.T) { + db, cleanup := setupTestDB(t) + defer cleanup() + + mockTodoist := &mockTodoistClient{} + mockTrello := &mockTrelloClient{} + + // Use a renderer that outputs actual content so we can check for settings link + renderer := NewMockRenderer() + renderer.RenderFunc = func(w io.Writer, name string, data interface{}) error { + if name == "index.html" { + // Check that data includes what the template needs + // We verify the template at the source: index.html must contain /settings link + fmt.Fprintf(w, "rendered:%s", name) + } + return nil + } + + h := &Handler{ + store: db, + todoistClient: mockTodoist, + trelloClient: mockTrello, + config: &config.Config{CacheTTLMinutes: 5}, + renderer: renderer, + } + + req := httptest.NewRequest("GET", "/", nil) + w := httptest.NewRecorder() + + h.HandleDashboard(w, req) + + if w.Code != http.StatusOK { + t.Errorf("Expected status 200, got %d", w.Code) + } +} + +// TestDashboardTemplate_HasSettingsLink verifies the index.html template +// contains a link to /settings. This catches regressions where the settings +// button is accidentally removed. +func TestDashboardTemplate_HasSettingsLink(t *testing.T) { + // Read the actual template file and verify it contains a settings link + content, err := os.ReadFile("../../web/templates/index.html") + if err != nil { + t.Skipf("Cannot read template file (running from unexpected directory): %v", err) + } + + templateStr := string(content) + + if !strings.Contains(templateStr, `href="/settings"`) { + t.Error("index.html must contain a link to /settings (settings button missing from UI)") } } -- cgit v1.2.3