1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
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)
}
})
}
}
|