summaryrefslogtreecommitdiff
path: root/internal/handlers/handlers_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/handlers/handlers_test.go')
-rw-r--r--internal/handlers/handlers_test.go107
1 files changed, 107 insertions, 0 deletions
diff --git a/internal/handlers/handlers_test.go b/internal/handlers/handlers_test.go
index 4c776b0..a43dec2 100644
--- a/internal/handlers/handlers_test.go
+++ b/internal/handlers/handlers_test.go
@@ -1869,6 +1869,113 @@ func TestHandleGetTaskDetail_RendersTemplate(t *testing.T) {
}
}
+// TestHandleGetTaskDetail_DootSource_LoadsRealTaskFields guards against a
+// regression where source=="doot" fell through the switch in
+// loadTaskDetailData with no case, silently leaving Title/Description blank
+// -- native tasks are the primary type the Tasks tab and its detail modal
+// are built around, so this previously meant opening any native task's
+// detail showed an empty modal.
+func TestHandleGetTaskDetail_DootSource_LoadsRealTaskFields(t *testing.T) {
+ h, cleanup := setupTestHandler(t)
+ defer cleanup()
+
+ if err := h.store.CreateNativeTask(models.Task{
+ ID: "task-1", Content: "Clean gutters", Description: "Ladder's in the garage", Priority: 1,
+ }); err != nil {
+ t.Fatal(err)
+ }
+
+ req := httptest.NewRequest("GET", "/tasks/detail?id=task-1&source=doot", 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)
+ lastCall := mock.Calls[len(mock.Calls)-1]
+ data, ok := lastCall.Data.(taskDetailData)
+ if !ok {
+ t.Fatalf("unexpected data type %T", lastCall.Data)
+ }
+ if !data.IsDoot {
+ t.Error("IsDoot = false, want true")
+ }
+ if data.Title != "Clean gutters" {
+ t.Errorf("Title = %q, want %q", data.Title, "Clean gutters")
+ }
+ if data.Description != "Ladder's in the garage" {
+ t.Errorf("Description = %q, want %q", data.Description, "Ladder's in the garage")
+ }
+}
+
+func TestHandleSetTaskRecurrence_SetsAndClears(t *testing.T) {
+ h, cleanup := setupTestHandler(t)
+ defer cleanup()
+
+ if err := h.store.CreateNativeTask(models.Task{ID: "task-1", Content: "Water plants", Priority: 1}); err != nil {
+ t.Fatal(err)
+ }
+
+ req := httptest.NewRequest("POST", "/tasks/recurrence", strings.NewReader("id=task-1&freq=weekly&interval=2&weekdays=1&weekdays=3"))
+ req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
+ w := httptest.NewRecorder()
+ h.HandleSetTaskRecurrence(w, req)
+
+ if w.Code != http.StatusOK {
+ t.Fatalf("status = %d, want 200, body=%s", w.Code, w.Body.String())
+ }
+ task, err := h.store.GetNativeTaskByID("task-1")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if task.RecurrenceFreq != "weekly" || task.RecurrenceInterval != 2 {
+ t.Errorf("recurrence = freq=%q interval=%d, want weekly/2", task.RecurrenceFreq, task.RecurrenceInterval)
+ }
+ if len(task.RecurrenceWeekdays) != 2 {
+ t.Errorf("weekdays = %v, want [1 3]", task.RecurrenceWeekdays)
+ }
+ if task.RecurrenceSeriesID == "" {
+ t.Error("RecurrenceSeriesID should be set once a recurrence pattern is active")
+ }
+
+ // Clearing (freq="") should drop the pattern.
+ req2 := httptest.NewRequest("POST", "/tasks/recurrence", strings.NewReader("id=task-1&freq=&interval=1"))
+ req2.Header.Set("Content-Type", "application/x-www-form-urlencoded")
+ w2 := httptest.NewRecorder()
+ h.HandleSetTaskRecurrence(w2, req2)
+
+ if w2.Code != http.StatusOK {
+ t.Fatalf("status = %d, want 200, body=%s", w2.Code, w2.Body.String())
+ }
+ task, err = h.store.GetNativeTaskByID("task-1")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if task.RecurrenceFreq != "" {
+ t.Errorf("RecurrenceFreq = %q after clear, want empty", task.RecurrenceFreq)
+ }
+}
+
+func TestHandleSetTaskRecurrence_InvalidFreq_Returns400(t *testing.T) {
+ h, cleanup := setupTestHandler(t)
+ defer cleanup()
+
+ if err := h.store.CreateNativeTask(models.Task{ID: "task-1", Content: "Water plants", Priority: 1}); err != nil {
+ t.Fatal(err)
+ }
+
+ req := httptest.NewRequest("POST", "/tasks/recurrence", strings.NewReader("id=task-1&freq=fortnightly"))
+ req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
+ w := httptest.NewRecorder()
+ h.HandleSetTaskRecurrence(w, req)
+
+ if w.Code != http.StatusBadRequest {
+ t.Fatalf("status = %d, want 400", w.Code)
+ }
+}
+
// =============================================================================
// HandleGetListsOptions template tests
// =============================================================================