package handlers import ( "testing" "time" "task-dashboard/internal/models" ) func TestIsActionableList(t *testing.T) { tests := []struct { name string listName string want bool }{ {"doing list", "Doing", true}, {"in progress", "In Progress", true}, {"to do", "To Do", true}, {"todo", "todo", true}, {"tasks", "My Tasks", true}, {"next", "Next Up", true}, {"today", "Today", true}, {"backlog", "Backlog", false}, {"done", "Done", false}, {"ideas", "Ideas", false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := isActionableList(tt.listName); got != tt.want { t.Errorf("isActionableList(%q) = %v, want %v", tt.listName, got, tt.want) } }) } } func TestFilterAndSortTrelloTasks(t *testing.T) { due := time.Now() boards := []models.Board{ { ID: "b1", Name: "Work Board", Cards: []models.Card{ {ID: "c1", Name: "Due Task", ListName: "Backlog", DueDate: &due, BoardName: "Work Board"}, {ID: "c2", Name: "Doing Task", ListName: "Doing", BoardName: "Work Board"}, {ID: "c3", Name: "Backlog Task", ListName: "Backlog", BoardName: "Work Board"}, {ID: "c4", Name: "Todo Task", ListName: "To Do", BoardName: "Work Board"}, }, }, } tasks := filterAndSortTrelloTasks(boards) // Should have 3 tasks: c1 (has due date), c2 (Doing list), c4 (To Do list) if len(tasks) != 3 { t.Errorf("Expected 3 tasks, got %d", len(tasks)) } // Verify c3 (Backlog without due date) is not included for _, task := range tasks { if task.ID == "c3" { t.Error("Backlog task without due date should not be included") } } // Verify expected tasks are present found := map[string]bool{} for _, task := range tasks { found[task.ID] = true } if !found["c1"] { t.Error("Expected c1 (Due Task) to be present") } if !found["c2"] { t.Error("Expected c2 (Doing Task) to be present") } if !found["c4"] { t.Error("Expected c4 (Todo Task) to be present") } } func TestAtomUrgencyTier(t *testing.T) { now := time.Now() yesterday := now.AddDate(0, 0, -1) tomorrow := now.AddDate(0, 0, 1) todayWithTime := time.Date(now.Year(), now.Month(), now.Day(), 14, 30, 0, 0, now.Location()) todayMidnight := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()) tests := []struct { name string atom models.Atom want int }{ {"no due date", models.Atom{DueDate: nil}, 4}, {"overdue", models.Atom{DueDate: &yesterday, IsOverdue: true}, 0}, {"future", models.Atom{DueDate: &tomorrow, IsFuture: true}, 3}, {"today with time", models.Atom{DueDate: &todayWithTime, HasSetTime: true}, 1}, {"today all-day", models.Atom{DueDate: &todayMidnight, HasSetTime: false}, 2}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := atomUrgencyTier(tt.atom); got != tt.want { t.Errorf("atomUrgencyTier() = %v, want %v", got, tt.want) } }) } }