todolist_test.gno
1.59 Kb ยท 60 lines
1package todolistrealm
2
3import (
4 "std"
5 "strconv"
6 "testing"
7
8 "gno.land/p/demo/todolist"
9 "gno.land/p/demo/uassert"
10)
11
12var (
13 node any
14 tdl *todolist.TodoList
15)
16
17func TestNewTodoList(t *testing.T) {
18 title := "My Todo List"
19 tlid, _ := NewTodoList(title)
20 uassert.Equal(t, 1, tlid, "tlid does not match")
21
22 // get the todolist node from the tree
23 node, _ = todolistTree.Get(strconv.Itoa(tlid))
24 // convert the node to a TodoList struct
25 tdl = node.(*todolist.TodoList)
26
27 uassert.Equal(t, title, tdl.Title, "title does not match")
28 uassert.Equal(t, 1, tlid, "tlid does not match")
29 uassert.Equal(t, tdl.Owner.String(), std.OriginCaller().String(), "owner does not match")
30 uassert.Equal(t, 0, len(tdl.GetTasks()), "Expected no tasks in the todo list")
31}
32
33func TestAddTask(t *testing.T) {
34 AddTask(1, "Task 1")
35
36 tasks := tdl.GetTasks()
37 uassert.Equal(t, 1, len(tasks), "total task does not match")
38 uassert.Equal(t, "Task 1", tasks[0].Title, "task title does not match")
39 uassert.False(t, tasks[0].Done, "Expected task to be not done")
40}
41
42func TestToggleTaskStatus(t *testing.T) {
43 ToggleTaskStatus(1, 0)
44 task := tdl.GetTasks()[0]
45 uassert.True(t, task.Done, "Expected task to be done, but it is not marked as done")
46
47 ToggleTaskStatus(1, 0)
48 uassert.False(t, task.Done, "Expected task to be not done, but it is marked as done")
49}
50
51func TestRemoveTask(t *testing.T) {
52 RemoveTask(1, 0)
53 tasks := tdl.GetTasks()
54 uassert.Equal(t, 0, len(tasks), "Expected no tasks in the todo list")
55}
56
57func TestRemoveTodoList(t *testing.T) {
58 RemoveTodoList(1)
59 uassert.Equal(t, 0, todolistTree.Size(), "Expected no tasks in the todo list")
60}