diff options
| -rw-r--r-- | todolist/date_filter.go | 5 | ||||
| -rw-r--r-- | todolist/date_filter_test.go | 19 |
2 files changed, 20 insertions, 4 deletions
diff --git a/todolist/date_filter.go b/todolist/date_filter.go index e876ba1..8d64484 100644 --- a/todolist/date_filter.go +++ b/todolist/date_filter.go @@ -57,10 +57,7 @@ func (f *DateFilter) filterAgenda(pivot time.Time) []*Todo { var ret []*Todo for _, todo := range f.Todos { - if todo.Due == "" { - continue - } - if todo.Completed { + if todo.Due == "" || todo.Completed { continue } dueTime, _ := time.ParseInLocation("2006-01-02", todo.Due, f.Location) diff --git a/todolist/date_filter_test.go b/todolist/date_filter_test.go index 444b4ac..6dd88f6 100644 --- a/todolist/date_filter_test.go +++ b/todolist/date_filter_test.go @@ -96,3 +96,22 @@ func TestFilterDay(t *testing.T) { assert.Equal(1, len(filtered)) assert.Equal(1, filtered[0].Id) } + +func TestFilterAgenda(t *testing.T) { + assert := assert.New(t) + + var todos []*Todo + + completedTodo := &Todo{Id: 1, Subject: "completed", Completed: true, Due: time.Now().Format("2006-01-02")} + uncompletedTodo := &Todo{Id: 2, Subject: "uncompleted", Due: time.Now().Format("2006-01-02")} + + todos = append(todos, completedTodo) + todos = append(todos, uncompletedTodo) + + filter := NewDateFilter(todos) + + filtered := filter.filterAgenda(time.Now()) + + assert.Equal(1, len(filtered)) + assert.Equal(2, filtered[0].Id) +} |
