summaryrefslogtreecommitdiff
path: root/internal/handlers/handlers_test.go
diff options
context:
space:
mode:
authorPeter Stone <thepeterstone@gmail.com>2026-02-06 14:53:47 -1000
committerPeter Stone <thepeterstone@gmail.com>2026-02-06 14:53:47 -1000
commit27ee1a271248e9f1de8ecb981a6cabfa8e498b1b (patch)
tree7a5b8555ea4199094104f3e2b1227c08a33037ed /internal/handlers/handlers_test.go
parent0a1001eb0bd2d1f7c0624ae1ef8ae7ccdb3447d4 (diff)
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 <noreply@anthropic.com>
Diffstat (limited to 'internal/handlers/handlers_test.go')
-rw-r--r--internal/handlers/handlers_test.go105
1 files changed, 102 insertions, 3 deletions
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)")
}
}