-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_test.go
133 lines (125 loc) · 3.19 KB
/
model_test.go
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package main
import (
"fmt"
"reflect"
"testing"
"github.com/dominickp/hn/client"
)
func Test_getTopMenuCurrentPageChoices(t *testing.T) {
type args struct {
m model
}
topMenuResponse := client.TopMenuResponse{}
numItems := 25
for i := 1; i < numItems; i++ {
item := client.Item{Id: i, Title: fmt.Sprintf("item %d", i), Score: 33}
topMenuResponse.Items = append(topMenuResponse.Items, item)
}
tests := []struct {
name string
args args
want []string
}{
{
name: "TestGetTopMenuCurrentPageChoices",
args: args{m: model{currentPage: 1, pageSize: 5, topMenuResponse: topMenuResponse}},
want: []string{"33 item 1", "33 item 2", "33 item 3", "33 item 4", "33 item 5"},
},
{
name: "TestGetTopMenuCurrentPageChoicesPage2",
args: args{m: model{currentPage: 2, pageSize: 5, topMenuResponse: topMenuResponse}},
want: []string{"33 item 6", "33 item 7", "33 item 8", "33 item 9", "33 item 10"},
},
{
name: "TestGetTopMenuCurrentPageLongerPage",
args: args{m: model{currentPage: 1, pageSize: 10, topMenuResponse: topMenuResponse}},
want: []string{
"33 item 1", "33 item 2", "33 item 3", "33 item 4", "33 item 5",
"33 item 6", "33 item 7", "33 item 8", "33 item 9", "33 item 10",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := getTopMenuCurrentPageChoices(tt.args.m); !reflect.DeepEqual(got, tt.want) {
t.Errorf("getTopMenuCurrentPageChoices() = %v, want %v", got, tt.want)
}
})
}
}
func Test_model_getCurrentTopic(t *testing.T) {
tests := []struct {
name string
m model
want *client.Item
}{
{
name: "TestGetCurrentTopic",
m: model{topicHistoryStack: []client.Item{
{Id: 1, Title: "item 1"},
{Id: 1, Title: "item 2"},
{Id: 1, Title: "item 3"},
}},
want: &client.Item{Id: 1, Title: "item 3"},
},
{
name: "TestGetCurrentTopicEmptyStack",
m: model{topicHistoryStack: []client.Item{}},
want: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.m.getCurrentTopic(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("model.getCurrentTopic() = %v, want %v", got, tt.want)
}
})
}
}
func Test_getContent(t *testing.T) {
type args struct {
m model
}
tests := []struct {
name string
args args
want string
}{
{
name: "TestGetContentWithCurrentTopic",
args: args{m: model{
topicHistoryStack: []client.Item{{
Id: 1, Title: "item 1", By: "Joe", Kids: []int{1, 2, 3}, Url: "http://example.com", Text: "foo...",
}},
choices: []string{"33 item 1", "33 item 2"},
}},
want: `item 1
By Joe (3 comments)
foo...
→ http://example.com
> 33 item 1
33 item 2
`,
},
{
name: "TestGetContentTopMenu",
args: args{m: model{
topicHistoryStack: []client.Item{},
choices: []string{"33 item 1", "33 item 2", "33 item 3", "33 item 4", "33 item 5"},
}},
want: `> 33 item 1
33 item 2
33 item 3
33 item 4
33 item 5
`,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := getContent(tt.args.m); got != tt.want {
t.Errorf("getContent() = \n'%v', want \n'%v'", got, tt.want)
}
})
}
}