From e3195a6534bae000a63e884ff647fac95d9d2498 Mon Sep 17 00:00:00 2001 From: Claudomator Agent Date: Wed, 18 Mar 2026 07:06:03 +0000 Subject: chore: autocommit uncommitted changes --- internal/handlers/handlers.go | 40 +++----------- internal/handlers/handlers_test.go | 108 +++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+), 32 deletions(-) (limited to 'internal') diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index 4988038..39e67c9 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -835,12 +835,7 @@ func (h *Handler) HandleGetListsOptions(w http.ResponseWriter, r *http.Request) return } - w.Header().Set("Content-Type", "text/html") - for _, list := range lists { - _, _ = fmt.Fprintf(w, ``, - template.HTMLEscapeString(list.ID), - template.HTMLEscapeString(list.Name)) - } + HTMLResponse(w, h.renderer, "lists-options", lists) } // HandleGetBugs returns the list of reported bugs @@ -850,19 +845,7 @@ func (h *Handler) HandleGetBugs(w http.ResponseWriter, r *http.Request) { JSONError(w, http.StatusInternalServerError, "Failed to fetch bugs", err) return } - - w.Header().Set("Content-Type", "text/html") - if len(bugs) == 0 { - _, _ = fmt.Fprint(w, `

No bugs reported yet.

`) - return - } - - for _, bug := range bugs { - _, _ = fmt.Fprintf(w, `
-

%s

-

%s

-
`, template.HTMLEscapeString(bug.Description), bug.CreatedAt.Format("Jan 2, 3:04 PM")) - } + HTMLResponse(w, h.renderer, "bugs", bugs) } // HandleReportBug saves a new bug report @@ -919,19 +902,12 @@ func (h *Handler) HandleGetTaskDetail(w http.ResponseWriter, r *http.Request) { } } - html := fmt.Sprintf(` -
-

%s

-
- - - - - -
-
- `, template.HTMLEscapeString(title), template.HTMLEscapeString(id), template.HTMLEscapeString(source), template.HTMLEscapeString(description)) - HTMLString(w, html) + HTMLResponse(w, h.renderer, "task-detail", struct { + Title string + ID string + Source string + Description string + }{title, id, source, description}) } // HandleUpdateTask updates a task description diff --git a/internal/handlers/handlers_test.go b/internal/handlers/handlers_test.go index 470ea5c..9a2287f 100644 --- a/internal/handlers/handlers_test.go +++ b/internal/handlers/handlers_test.go @@ -2827,6 +2827,114 @@ func TestHandleSettingsPage_IncludesSyncLog(t *testing.T) { } } +// ============================================================================= +// HandleGetBugs template tests +// ============================================================================= + +// TestHandleGetBugs_RendersTemplate verifies that HandleGetBugs uses the renderer +// with the "bugs" template and passes the bug list as data. +func TestHandleGetBugs_RendersTemplate(t *testing.T) { + h, cleanup := setupTestHandler(t) + defer cleanup() + + _ = h.store.SaveBug("test bug description") + + req := httptest.NewRequest("GET", "/bugs", nil) + w := httptest.NewRecorder() + h.HandleGetBugs(w, req) + + mr := h.renderer.(*MockRenderer) + var found bool + for _, call := range mr.Calls { + if call.Name == "bugs" { + found = true + break + } + } + if !found { + t.Error("Expected renderer to be called with 'bugs' template") + } +} + +// TestHandleGetBugs_NoBugs_RendersTemplate verifies that HandleGetBugs uses the +// renderer even when there are no bugs. +func TestHandleGetBugs_NoBugs_RendersTemplate(t *testing.T) { + h, cleanup := setupTestHandler(t) + defer cleanup() + + req := httptest.NewRequest("GET", "/bugs", nil) + w := httptest.NewRecorder() + h.HandleGetBugs(w, req) + + mr := h.renderer.(*MockRenderer) + var found bool + for _, call := range mr.Calls { + if call.Name == "bugs" { + found = true + break + } + } + if !found { + t.Error("Expected renderer to be called with 'bugs' template even when no bugs") + } +} + +// ============================================================================= +// HandleGetTaskDetail template tests +// ============================================================================= + +// TestHandleGetTaskDetail_RendersTemplate verifies that HandleGetTaskDetail uses +// the renderer with the "task-detail" template. +func TestHandleGetTaskDetail_RendersTemplate(t *testing.T) { + h, cleanup := setupTestHandler(t) + defer cleanup() + + req := httptest.NewRequest("GET", "/tasks/detail?id=abc&source=todoist", nil) + w := httptest.NewRecorder() + h.HandleGetTaskDetail(w, req) + + mr := h.renderer.(*MockRenderer) + var found bool + for _, call := range mr.Calls { + if call.Name == "task-detail" { + found = true + break + } + } + if !found { + t.Error("Expected renderer to be called with 'task-detail' template") + } +} + +// ============================================================================= +// HandleGetListsOptions template tests +// ============================================================================= + +// TestHandleGetListsOptions_RendersTemplate verifies that HandleGetListsOptions uses +// the renderer with the "lists-options" template. +func TestHandleGetListsOptions_RendersTemplate(t *testing.T) { + h, cleanup := setupTestHandler(t) + defer cleanup() + + h.trelloClient = &mockTrelloClient{boards: []models.Board{}} + + req := httptest.NewRequest("GET", "/trello/lists?board_id=board1", nil) + w := httptest.NewRecorder() + h.HandleGetListsOptions(w, req) + + mr := h.renderer.(*MockRenderer) + var found bool + for _, call := range mr.Calls { + if call.Name == "lists-options" { + found = true + break + } + } + if !found { + t.Error("Expected renderer to be called with 'lists-options' template") + } +} + // TestHandleSyncSources_AddsLogEntry verifies that syncing sources creates a sync log entry. func TestHandleSyncSources_AddsLogEntry(t *testing.T) { h, cleanup := setupTestHandler(t) -- cgit v1.2.3