diff options
Diffstat (limited to 'todolist/app_test.go')
| -rw-r--r-- | todolist/app_test.go | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/todolist/app_test.go b/todolist/app_test.go index f35a7bc..2fb7717 100644 --- a/todolist/app_test.go +++ b/todolist/app_test.go @@ -43,3 +43,97 @@ func TestAddTodoWithEuropeanDates(t *testing.T) { assert.Equal([]string{}, todo.Projects) assert.Equal([]string{}, todo.Contexts) } + +func TestListbyProject(t *testing.T) { + assert := assert.New(t) + app := &App{TodoList: &TodoList{}, TodoStore: &MemoryStore{}} + app.Load() + + // create three todos w/wo a project + app.AddTodo("this is a test +testme") + app.AddTodo("this is a test +testmetoo @work") + app.AddTodo("this is a test with no projects") + app.CompleteTodo("c 1") + + // simulate listTodos + input := "l by p" + filtered := NewFilter(app.TodoList.Todos()).Filter(input) + grouped := app.getGroups(input, filtered) + + assert.Equal(3, len(grouped.Groups)) + + // testme project has 1 todo and its completed + assert.Equal(1, len(grouped.Groups["testme"])) + assert.Equal(true, grouped.Groups["testme"][0].Completed) + + // testmetoo project has 1 todo and it has a context + assert.Equal(1, len(grouped.Groups["testmetoo"])) + assert.Equal(1, len(grouped.Groups["testmetoo"][0].Contexts)) + assert.Equal("work", grouped.Groups["testmetoo"][0].Contexts[0]) +} + +func TestListbyContext(t *testing.T) { + assert := assert.New(t) + app := &App{TodoList: &TodoList{}, TodoStore: &MemoryStore{}} + app.Load() + + // create three todos w/wo a context + app.AddTodo("this is a test +testme") + app.AddTodo("this is a test +testmetoo @work") + app.AddTodo("this is a test with no projects") + app.CompleteTodo("c 1") + + // simulate listTodos + input := "l by c" + filtered := NewFilter(app.TodoList.Todos()).Filter(input) + grouped := app.getGroups(input, filtered) + + assert.Equal(2, len(grouped.Groups)) + + // work context has 1 todo and it has a project of testmetoo + assert.Equal(1, len(grouped.Groups["work"])) + assert.Equal(1, len(grouped.Groups["work"][0].Projects)) + assert.Equal("testmetoo", grouped.Groups["work"][0].Projects[0]) + + // There are two todos with no context + assert.Equal(2, len(grouped.Groups["No contexts"])) + + // check to see if the a todos with no context contain a + // completed todo + var hasACompletedTodo bool + for _, todo := range grouped.Groups["No contexts"] { + if todo.Completed { + hasACompletedTodo = true + } + } + assert.Equal(true, hasACompletedTodo) +} + +func TestGetId(t *testing.T) { + assert := assert.New(t) + app := &App{TodoList: &TodoList{}, TodoStore: &MemoryStore{}} + // not a valid id + assert.Equal(-1, app.getId("p")) + // a single digit id + assert.Equal(6, app.getId("6")) + // a double digit id + assert.Equal(66, app.getId("66")) +} + +func TestGetIds(t *testing.T) { + assert := assert.New(t) + app := &App{TodoList: &TodoList{}, TodoStore: &MemoryStore{}} + // no valid id here + assert.Equal(0, len(app.getIds("p"))) + // one valid value here + assert.Equal([]int{6}, app.getIds("6")) + // lots of single post numbers + assert.Equal([]int{6, 10, 8, 4}, app.getIds("6,10,8,4")) + // a correct range + assert.Equal([]int{6, 7, 8}, app.getIds("6-8")) + // some incorrect ranges + assert.Equal(0, len(app.getIds("6-6"))) + assert.Equal(0, len(app.getIds("8-6"))) + // some compsite ranges + assert.Equal([]int{5, 6, 7, 8, 10, 11, 9}, app.getIds("5,6-8,10-11,9")) +} |
