@@ -4,11 +4,11 @@ import { Pagination } from '../../../src/lib/components';
4
4
5
5
test ( 'shows controls' , ( ) => {
6
6
const { getByLabelText } = render ( Pagination , {
7
- limit : 0 ,
7
+ limit : 100 ,
8
8
offset : 0 ,
9
- sum : 100
9
+ sum : 150
10
10
} ) ;
11
- expect ( getByLabelText ( 'previous page' ) ) . toBeInTheDocument ( ) ;
11
+ expect ( getByLabelText ( 'prev page' ) ) . toBeInTheDocument ( ) ;
12
12
expect ( getByLabelText ( 'next page' ) ) . toBeInTheDocument ( ) ;
13
13
} ) ;
14
14
@@ -19,8 +19,8 @@ test('pagination - first page', () => {
19
19
sum : 100
20
20
} ) ;
21
21
22
- expect ( getByLabelText ( 'previous page' ) ) . toBeDisabled ( ) ;
23
- expect ( getByLabelText ( 'next page' ) ) . not . toBeDisabled ( ) ;
22
+ expect ( getByLabelText ( 'prev page' ) ) . toHaveClass ( 'is-disabled' ) ;
23
+ expect ( getByLabelText ( 'next page' ) ) . not . toHaveClass ( 'is-disabled' ) ;
24
24
} ) ;
25
25
26
26
test ( 'pagination - last page' , ( ) => {
@@ -30,8 +30,8 @@ test('pagination - last page', () => {
30
30
sum : 30
31
31
} ) ;
32
32
33
- expect ( getByLabelText ( 'previous page' ) ) . not . toBeDisabled ( ) ;
34
- expect ( getByLabelText ( 'next page' ) ) . toBeDisabled ( ) ;
33
+ expect ( getByLabelText ( 'prev page' ) ) . not . toHaveClass ( 'is-disabled' ) ;
34
+ expect ( getByLabelText ( 'next page' ) ) . toHaveClass ( 'is-disabled' ) ;
35
35
} ) ;
36
36
37
37
test ( 'pagination - forward' , async ( ) => {
@@ -41,9 +41,9 @@ test('pagination - forward', async () => {
41
41
sum : 60
42
42
} ) ;
43
43
44
- const back = getByLabelText ( 'previous page' ) ;
44
+ const back = getByLabelText ( 'prev page' ) ;
45
45
const forth = getByLabelText ( 'next page' ) ;
46
- expect ( back ) . toBeDisabled ( ) ;
46
+ expect ( back ) . toHaveClass ( 'is-disabled' ) ;
47
47
48
48
await fireEvent . click ( forth ) ;
49
49
expect ( component . offset ) . toEqual ( 25 ) ;
@@ -52,8 +52,8 @@ test('pagination - forward', async () => {
52
52
expect ( component . offset ) . toEqual ( 50 ) ;
53
53
54
54
await fireEvent . click ( forth ) ;
55
- expect ( component . offset ) . toEqual ( 60 ) ;
56
- expect ( forth ) . toBeDisabled ( ) ;
55
+ expect ( component . offset ) . toEqual ( 50 ) ;
56
+ expect ( forth ) . toHaveClass ( 'is-disabled' ) ;
57
57
} ) ;
58
58
59
59
test ( 'pagination - backwards' , async ( ) => {
@@ -63,19 +63,50 @@ test('pagination - backwards', async () => {
63
63
sum : 60
64
64
} ) ;
65
65
66
- const back = getByLabelText ( 'previous page' ) ;
66
+ const back = getByLabelText ( 'prev page' ) ;
67
67
const forth = getByLabelText ( 'next page' ) ;
68
- expect ( forth ) . toBeDisabled ( ) ;
68
+ expect ( forth ) . toHaveClass ( 'is-disabled' ) ;
69
69
70
70
await fireEvent . click ( back ) ;
71
- expect ( component . offset ) . toEqual ( 30 ) ;
71
+ expect ( component . offset ) . toEqual ( 25 ) ;
72
72
73
73
await fireEvent . click ( back ) ;
74
- expect ( component . offset ) . toEqual ( 5 ) ;
74
+ expect ( component . offset ) . toEqual ( 0 ) ;
75
75
76
76
await fireEvent . click ( back ) ;
77
77
expect ( component . offset ) . toEqual ( 0 ) ;
78
- expect ( back ) . toBeDisabled ( ) ;
78
+ expect ( back ) . toHaveClass ( 'is-disabled' ) ;
79
+ } ) ;
80
+
81
+ test ( 'pagination - number button click' , async ( ) => {
82
+ const { getByText, getAllByLabelText, component } = render ( Pagination , {
83
+ limit : 25 ,
84
+ offset : 0 ,
85
+ sum : 60
86
+ } ) ;
87
+
88
+ const buttons = getAllByLabelText ( 'page' ) ;
89
+ const [ button1 , button2 , button3 ] = buttons ;
90
+
91
+ const one = getByText ( '1' ) ;
92
+ const two = getByText ( '2' ) ;
93
+ const three = getByText ( '3' ) ;
94
+ expect ( button1 ) . toHaveClass ( 'is-disabled' ) ;
95
+
96
+ await fireEvent . click ( two ) ;
97
+ expect ( component . offset ) . toEqual ( 25 ) ;
98
+ expect ( button1 ) . not . toHaveClass ( 'is-disabled' ) ;
99
+ expect ( button2 ) . toHaveClass ( 'is-disabled' ) ;
100
+
101
+ await fireEvent . click ( three ) ;
102
+ expect ( component . offset ) . toEqual ( 50 ) ;
103
+ expect ( button2 ) . not . toHaveClass ( 'is-disabled' ) ;
104
+ expect ( button3 ) . toHaveClass ( 'is-disabled' ) ;
105
+
106
+ await fireEvent . click ( one ) ;
107
+ expect ( component . offset ) . toEqual ( 0 ) ;
108
+ expect ( button1 ) . toHaveClass ( 'is-disabled' ) ;
109
+ expect ( button3 ) . not . toHaveClass ( 'is-disabled' ) ;
79
110
} ) ;
80
111
81
112
test ( 'shows no controls' , ( ) => {
@@ -85,6 +116,6 @@ test('shows no controls', () => {
85
116
sum : 10
86
117
} ) ;
87
118
88
- expect ( queryByLabelText ( 'previous page' ) ) . not . toBeInTheDocument ( ) ;
119
+ expect ( queryByLabelText ( 'prev page' ) ) . not . toBeInTheDocument ( ) ;
89
120
expect ( queryByLabelText ( 'next page' ) ) . not . toBeInTheDocument ( ) ;
90
121
} ) ;
0 commit comments