-
-
Notifications
You must be signed in to change notification settings - Fork 72
/
pagination_test.go
122 lines (96 loc) · 7.48 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package tags
import (
"html/template"
"testing"
"github.com/stretchr/testify/require"
)
func Test_Pagination(t *testing.T) {
r := require.New(t)
tag, err := Pagination(&Paginator{
Page: 2,
TotalPages: 3,
}, Options{
"path": "/foo",
})
r.NoError(err)
r.Equal(template.HTML(`<ul class=" pagination"><li class="page-item"><a class="page-link" href="/foo?page=1">«</a></li><li class="page-item"><a class="page-link" href="/foo?page=1">1</a></li><li class="page-item active"><a class="page-link" href="/foo?page=2">2</a></li><li class="page-item"><a class="page-link" href="/foo?page=3">3</a></li><li class="page-item"><a class="page-link" href="/foo?page=3">»</a></li></ul>`), tag.HTML())
}
func Test_Pagination_Page1(t *testing.T) {
r := require.New(t)
tag, err := Pagination(&Paginator{
Page: 1,
TotalPages: 3,
}, Options{
"path": "/foo",
})
r.NoError(err)
r.Equal(template.HTML(`<ul class=" pagination"><li class="page-item disabled"><span class="page-link">«</span></li><li class="page-item active"><a class="page-link" href="/foo?page=1">1</a></li><li class="page-item"><a class="page-link" href="/foo?page=2">2</a></li><li class="page-item"><a class="page-link" href="/foo?page=3">3</a></li><li class="page-item"><a class="page-link" href="/foo?page=2">»</a></li></ul>`), tag.HTML())
}
func Test_Pagination_Page3(t *testing.T) {
r := require.New(t)
tag, err := Pagination(&Paginator{
Page: 3,
TotalPages: 3,
}, Options{
"path": "/foo",
})
r.NoError(err)
r.Equal(template.HTML(`<ul class=" pagination"><li class="page-item"><a class="page-link" href="/foo?page=2">«</a></li><li class="page-item"><a class="page-link" href="/foo?page=1">1</a></li><li class="page-item"><a class="page-link" href="/foo?page=2">2</a></li><li class="page-item active"><a class="page-link" href="/foo?page=3">3</a></li><li class="page-item disabled"><span class="page-link">»</span></li></ul>`), tag.HTML())
}
func Test_Pagination_LongPageStart(t *testing.T) {
r := require.New(t)
tag, err := Pagination(&Paginator{
Page: 1,
TotalPages: 29,
}, Options{
"path": "/foo",
})
r.NoError(err)
r.Equal(template.HTML(`<ul class=" pagination"><li class="page-item disabled"><span class="page-link">«</span></li><li class="page-item active"><a class="page-link" href="/foo?page=1">1</a></li><li class="page-item"><a class="page-link" href="/foo?page=2">2</a></li><li class="page-item"><a class="page-link" href="/foo?page=3">3</a></li><li class="page-item"><a class="page-link" href="/foo?page=4">4</a></li><li class="page-item"><a class="page-link" href="/foo?page=5">5</a></li><li class="page-item"><a class="page-link" href="/foo?page=6">6</a></li><li class="page-item"><a class="page-link" href="/foo?page=7">7</a></li><li class="page-item"><a class="page-link" href="/foo?page=8">8</a></li><li class="page-item"><a class="page-link" href="/foo?page=9">9</a></li><li class="page-item disabled"><a class="page-link">...</a></li><li class="page-item"><a class="page-link" href="/foo?page=29">29</a></li><li class="page-item"><a class="page-link" href="/foo?page=2">»</a></li></ul>`), tag.HTML())
}
func Test_Pagination_LongPageStartPoint1(t *testing.T) {
r := require.New(t)
tag, err := Pagination(&Paginator{
Page: 6,
TotalPages: 29,
}, Options{
"path": "/foo",
})
r.NoError(err)
r.Equal(template.HTML(`<ul class=" pagination"><li class="page-item"><a class="page-link" href="/foo?page=5">«</a></li><li class="page-item"><a class="page-link" href="/foo?page=1">1</a></li><li class="page-item"><a class="page-link" href="/foo?page=2">2</a></li><li class="page-item"><a class="page-link" href="/foo?page=3">3</a></li><li class="page-item"><a class="page-link" href="/foo?page=4">4</a></li><li class="page-item"><a class="page-link" href="/foo?page=5">5</a></li><li class="page-item active"><a class="page-link" href="/foo?page=6">6</a></li><li class="page-item"><a class="page-link" href="/foo?page=7">7</a></li><li class="page-item"><a class="page-link" href="/foo?page=8">8</a></li><li class="page-item"><a class="page-link" href="/foo?page=9">9</a></li><li class="page-item disabled"><a class="page-link">...</a></li><li class="page-item"><a class="page-link" href="/foo?page=29">29</a></li><li class="page-item"><a class="page-link" href="/foo?page=7">»</a></li></ul>`), tag.HTML())
}
func Test_Pagination_LongPagePoint2(t *testing.T) {
r := require.New(t)
tag, err := Pagination(&Paginator{
Page: 23,
TotalPages: 29,
}, Options{
"path": "/foo",
})
r.NoError(err)
r.Equal(template.HTML(`<ul class=" pagination"><li class="page-item"><a class="page-link" href="/foo?page=22">«</a></li><li class="page-item"><a class="page-link" href="/foo?page=1">1</a></li><li class="page-item disabled"><a class="page-link">...</a></li><li class="page-item"><a class="page-link" href="/foo?page=20">20</a></li><li class="page-item"><a class="page-link" href="/foo?page=21">21</a></li><li class="page-item"><a class="page-link" href="/foo?page=22">22</a></li><li class="page-item active"><a class="page-link" href="/foo?page=23">23</a></li><li class="page-item"><a class="page-link" href="/foo?page=24">24</a></li><li class="page-item"><a class="page-link" href="/foo?page=25">25</a></li><li class="page-item"><a class="page-link" href="/foo?page=26">26</a></li><li class="page-item disabled"><a class="page-link">...</a></li><li class="page-item"><a class="page-link" href="/foo?page=29">29</a></li><li class="page-item"><a class="page-link" href="/foo?page=24">»</a></li></ul>`), tag.HTML())
}
func Test_Pagination_LongPageEnd(t *testing.T) {
r := require.New(t)
tag, err := Pagination(&Paginator{
Page: 24,
TotalPages: 29,
}, Options{
"path": "/foo",
})
r.NoError(err)
r.Equal(template.HTML(`<ul class=" pagination"><li class="page-item"><a class="page-link" href="/foo?page=23">«</a></li><li class="page-item"><a class="page-link" href="/foo?page=1">1</a></li><li class="page-item disabled"><a class="page-link">...</a></li><li class="page-item"><a class="page-link" href="/foo?page=21">21</a></li><li class="page-item"><a class="page-link" href="/foo?page=22">22</a></li><li class="page-item"><a class="page-link" href="/foo?page=23">23</a></li><li class="page-item active"><a class="page-link" href="/foo?page=24">24</a></li><li class="page-item"><a class="page-link" href="/foo?page=25">25</a></li><li class="page-item"><a class="page-link" href="/foo?page=26">26</a></li><li class="page-item"><a class="page-link" href="/foo?page=27">27</a></li><li class="page-item"><a class="page-link" href="/foo?page=28">28</a></li><li class="page-item"><a class="page-link" href="/foo?page=29">29</a></li><li class="page-item"><a class="page-link" href="/foo?page=25">»</a></li></ul>`), tag.HTML())
}
func Test_Pagination_NextPrevContent(t *testing.T) {
r := require.New(t)
tag, err := Pagination(&Paginator{
Page: 2,
TotalPages: 3,
}, Options{
"path": "/foo",
"nextContent": "Next",
"previousContent": "Previous",
})
r.NoError(err)
r.Equal(template.HTML(`<ul class=" pagination" nextContent="Next" previousContent="Previous"><li class="page-item"><a class="page-link" href="/foo?page=1">Previous</a></li><li class="page-item"><a class="page-link" href="/foo?page=1">1</a></li><li class="page-item active"><a class="page-link" href="/foo?page=2">2</a></li><li class="page-item"><a class="page-link" href="/foo?page=3">3</a></li><li class="page-item"><a class="page-link" href="/foo?page=3">Next</a></li></ul>`), tag.HTML())
}