summaryrefslogtreecommitdiff
path: root/internal/handlers/handlers_test.go
diff options
context:
space:
mode:
authorPeter Stone <thepeterstone@gmail.com>2026-08-13 08:38:29 +0000
committerPeter Stone <thepeterstone@gmail.com>2026-08-13 08:38:29 +0000
commita03d7673e7adf9a575c7272b2b528a74b230535e (patch)
treea4ac635d92eade4df117db2a4fbdfe1eff13d677 /internal/handlers/handlers_test.go
parent2509dde6aa372a505b186657706f4d21bd391807 (diff)
Fix blank task-detail modal for Google Tasks
loadTaskDetailData/HandleUpdateTask only had cases for "trello" and "doot" sources, so opening a gtask from the Tasks or Timeline tab rendered an empty title/description. Reuses the existing findGoogleTask cache lookup for both. Renamed the API client's UpdateTaskNotes to UpdateTask(title, notes) so the web modal can save an edited title too, not just description; the widget's description-only edit popup now just round-trips the task's existing title unchanged.
Diffstat (limited to 'internal/handlers/handlers_test.go')
-rw-r--r--internal/handlers/handlers_test.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/internal/handlers/handlers_test.go b/internal/handlers/handlers_test.go
index b618b71..8900f66 100644
--- a/internal/handlers/handlers_test.go
+++ b/internal/handlers/handlers_test.go
@@ -1965,6 +1965,62 @@ func TestHandleUpdateTask_DootSource_NoTitle_LeavesContentUntouched(t *testing.T
}
}
+func TestHandleGetTaskDetail_GtasksSource_LoadsRealTaskFields(t *testing.T) {
+ h, cleanup := setupTestHandler(t)
+ defer cleanup()
+
+ if err := h.store.SaveGoogleTasks([]models.GoogleTask{
+ {ID: "g1", Title: "Renew passport", Notes: "bring photo", ListID: "list-a", UpdatedAt: time.Now()},
+ }); err != nil {
+ t.Fatal(err)
+ }
+
+ req := httptest.NewRequest("GET", "/tasks/detail?id=g1&source=gtasks", nil)
+ w := httptest.NewRecorder()
+ h.HandleGetTaskDetail(w, req)
+
+ if w.Code != http.StatusOK {
+ t.Fatalf("status = %d, want 200, body=%s", w.Code, w.Body.String())
+ }
+ mock := h.renderer.(*MockRenderer)
+ data, ok := mock.Calls[len(mock.Calls)-1].Data.(taskDetailData)
+ if !ok {
+ t.Fatalf("unexpected data type %T", mock.Calls[len(mock.Calls)-1].Data)
+ }
+ if data.Title != "Renew passport" || data.Description != "bring photo" {
+ t.Errorf("Title/Description = %q/%q, want %q/%q", data.Title, data.Description, "Renew passport", "bring photo")
+ }
+ if data.IsDoot {
+ t.Error("IsDoot = true, want false for a Google Task")
+ }
+}
+
+func TestHandleUpdateTask_GtasksSource_SavesTitleAndNotes(t *testing.T) {
+ h, cleanup := setupTestHandler(t)
+ defer cleanup()
+
+ if err := h.store.SaveGoogleTasks([]models.GoogleTask{
+ {ID: "g1", Title: "Old title", Notes: "Old notes", ListID: "list-a", UpdatedAt: time.Now()},
+ }); err != nil {
+ t.Fatal(err)
+ }
+ mock := &mockGoogleTasksClient{}
+ h.googleTasksClient = mock
+
+ req := httptest.NewRequest("POST", "/tasks/update", strings.NewReader("id=g1&source=gtasks&title=New+title&description=New+notes"))
+ req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
+ req.Header.Set("HX-Request", "true")
+ w := httptest.NewRecorder()
+ h.HandleUpdateTask(w, req)
+
+ if w.Code != http.StatusOK {
+ t.Fatalf("status = %d, want 200, body=%s", w.Code, w.Body.String())
+ }
+ if mock.notesListID != "list-a" || mock.notesTaskID != "g1" || mock.notesTitle != "New title" || mock.notes != "New notes" {
+ t.Errorf("unexpected update call: listID=%q taskID=%q title=%q notes=%q", mock.notesListID, mock.notesTaskID, mock.notesTitle, mock.notes)
+ }
+}
+
func TestHandleDeleteTask_DootSource_RemovesTask(t *testing.T) {
h, cleanup := setupTestHandler(t)
defer cleanup()