-
Notifications
You must be signed in to change notification settings - Fork 0
/
pagination_test.go
104 lines (101 loc) · 2.69 KB
/
pagination_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
package pagination
import (
"testing"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"github.com/stretchr/testify/assert"
)
func TestNewInlineKeyboardPaginator(t *testing.T) {
type args struct {
page int
all int
data string
}
tests := []struct {
name string
args args
want []tgbotapi.InlineKeyboardButton
}{{
name: "when one",
args: args{
page: 1,
all: 1,
data: "data#{page}",
},
want: nil,
}, {
name: "less 5",
args: args{
page: 2,
all: 4,
data: "data#{page}",
},
want: []tgbotapi.InlineKeyboardButton{
tgbotapi.NewInlineKeyboardButtonData("1", "data#1"),
tgbotapi.NewInlineKeyboardButtonData("·2·", "data#2"),
tgbotapi.NewInlineKeyboardButtonData("3", "data#3"),
tgbotapi.NewInlineKeyboardButtonData("4", "data#4"),
},
}, {
name: "eq 5",
args: args{
page: 3,
all: 5,
data: "data#{page}",
},
want: []tgbotapi.InlineKeyboardButton{
tgbotapi.NewInlineKeyboardButtonData("1", "data#1"),
tgbotapi.NewInlineKeyboardButtonData("2", "data#2"),
tgbotapi.NewInlineKeyboardButtonData("·3·", "data#3"),
tgbotapi.NewInlineKeyboardButtonData("4", "data#4"),
tgbotapi.NewInlineKeyboardButtonData("5", "data#5"),
},
}, {
name: "startKeyboard",
args: args{
page: 2,
all: 30,
data: "data#{page}",
},
want: []tgbotapi.InlineKeyboardButton{
tgbotapi.NewInlineKeyboardButtonData("1", "data#1"),
tgbotapi.NewInlineKeyboardButtonData("·2·", "data#2"),
tgbotapi.NewInlineKeyboardButtonData("3", "data#3"),
tgbotapi.NewInlineKeyboardButtonData("4 ›", "data#4"),
tgbotapi.NewInlineKeyboardButtonData("30 »", "data#30"),
},
}, {
name: "middleKeyboard",
args: args{
page: 15,
all: 30,
data: "data#{page}",
},
want: []tgbotapi.InlineKeyboardButton{
tgbotapi.NewInlineKeyboardButtonData("« 1", "data#1"),
tgbotapi.NewInlineKeyboardButtonData("‹ 14", "data#14"),
tgbotapi.NewInlineKeyboardButtonData("·15·", "data#15"),
tgbotapi.NewInlineKeyboardButtonData("16 ›", "data#16"),
tgbotapi.NewInlineKeyboardButtonData("30 »", "data#30"),
},
}, {
name: "finishKeyboard",
args: args{
page: 28,
all: 30,
data: "data#{page}",
},
want: []tgbotapi.InlineKeyboardButton{
tgbotapi.NewInlineKeyboardButtonData("« 1", "data#1"),
tgbotapi.NewInlineKeyboardButtonData("‹ 27", "data#27"),
tgbotapi.NewInlineKeyboardButtonData("·28·", "data#28"),
tgbotapi.NewInlineKeyboardButtonData("29", "data#29"),
tgbotapi.NewInlineKeyboardButtonData("30", "data#30"),
},
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := NewInlineKeyboardPaginator(tt.args.page, tt.args.all, tt.args.data)
assert.Equal(t, tt.want, got)
})
}
}