1
- import { html , fixture , expect , elementUpdated } from '@open-wc/testing' ;
1
+ import {
2
+ html ,
3
+ fixture ,
4
+ expect ,
5
+ elementUpdated ,
6
+ oneEvent ,
7
+ } from '@open-wc/testing' ;
2
8
import { UUIPaginationElement } from './uui-pagination.element' ;
3
9
import '.' ;
4
10
@@ -24,66 +30,109 @@ describe('UUIPaginationElement', () => {
24
30
// expect(true).to.be.false;
25
31
// });
26
32
33
+ describe ( 'properties' , ( ) => {
34
+ it ( 'has an total property' , ( ) => {
35
+ expect ( element ) . to . have . property ( 'total' ) ;
36
+ } ) ;
37
+
38
+ it ( 'has a current property' , ( ) => {
39
+ expect ( element ) . to . have . property ( 'current' ) ;
40
+ } ) ;
41
+
42
+ it ( 'has a label property' , ( ) => {
43
+ expect ( element ) . to . have . property ( 'label' ) ;
44
+ } ) ;
45
+ } ) ;
46
+
47
+ describe ( 'methods' , ( ) => {
48
+ it ( 'has a goToNextPage method' , ( ) => {
49
+ expect ( element ) . to . have . property ( 'goToNextPage' ) . that . is . a ( 'function' ) ;
50
+ } ) ;
51
+ it ( 'has a goToPreviousPage method' , ( ) => {
52
+ expect ( element )
53
+ . to . have . property ( 'goToPreviousPage' )
54
+ . that . is . a ( 'function' ) ;
55
+ } ) ;
56
+ it ( 'has a goToPage method' , ( ) => {
57
+ expect ( element ) . to . have . property ( 'goToPage' ) . that . is . a ( 'function' ) ;
58
+ } ) ;
59
+ } ) ;
60
+
61
+ describe ( 'events' , ( ) => {
62
+ describe ( 'change' , ( ) => {
63
+ it ( 'emits a change event when another page is clicked' , async ( ) => {
64
+ const listener = oneEvent ( element , 'change' ) ;
65
+ const button = element . shadowRoot ?. querySelector ( '#pages' ) !
66
+ . children [ 3 ] as HTMLElement ;
67
+ button ?. click ( ) ;
68
+ const event = await listener ;
69
+ expect ( event ) . to . exist ;
70
+ expect ( event . type ) . to . equal ( 'change' ) ;
71
+ expect ( element . current ) . to . equal ( 2 ) ;
72
+ } ) ;
73
+ } ) ;
74
+ } ) ;
75
+
27
76
it ( 'sets active class on current page' , async ( ) => {
28
77
element . current = 2 ;
29
78
await elementUpdated ( element ) ;
30
- const button = element . shadowRoot ?. querySelector ( '#group ' ) !
79
+ const button = element . shadowRoot ?. querySelector ( '#pages ' ) !
31
80
. children [ 3 ] as HTMLElement ;
32
- expect ( button ) . to . have . class ( 'active-button ' ) ;
81
+ expect ( button ) . to . have . class ( 'active' ) ;
33
82
} ) ;
34
83
35
84
it ( 'goes to selected page on click' , async ( ) => {
36
- const button = element . shadowRoot ?. querySelector ( '#group ' ) !
85
+ const button = element . shadowRoot ?. querySelector ( '#pages ' ) !
37
86
. children [ 3 ] as HTMLElement ;
38
87
button . click ( ) ;
39
88
40
89
await elementUpdated ( element ) ;
41
90
42
- expect ( button ) . to . have . class ( 'active-button ' ) ;
91
+ expect ( button ) . to . have . class ( 'active' ) ;
43
92
expect ( element . current ) . to . equal ( 2 ) ;
44
93
} ) ;
45
94
46
95
it ( 'goes to previous page on click' , async ( ) => {
47
96
element . current = 2 ;
48
97
await elementUpdated ( element ) ;
49
98
50
- const buttons = element . shadowRoot ?. querySelector ( '#group ' ) ! . children ;
99
+ const buttons = element . shadowRoot ?. querySelector ( '#pages ' ) ! . children ;
51
100
const prevButton = buttons ! [ 1 ] as HTMLElement ;
52
101
const activeButton = buttons ! [ 2 ] as HTMLElement ;
53
102
prevButton . click ( ) ;
54
103
55
104
await elementUpdated ( element ) ;
56
105
57
106
expect ( element . current ) . to . equal ( 1 ) ;
58
- expect ( activeButton ) . to . have . class ( 'active-button ' ) ;
107
+ expect ( activeButton ) . to . have . class ( 'active' ) ;
59
108
} ) ;
60
109
61
110
it ( 'goes to next page on click' , async ( ) => {
62
111
element . current = 2 ;
63
112
await elementUpdated ( element ) ;
64
113
65
- const buttons = element . shadowRoot ?. querySelector ( '#group ' ) ?. children ;
114
+ const buttons = element . shadowRoot ?. querySelector ( '#pages ' ) ?. children ;
66
115
const nextButton = buttons ! [ 6 ] as HTMLElement ;
67
116
const activeButton = buttons ! [ 3 ] as HTMLElement ;
68
117
nextButton . click ( ) ;
69
118
70
119
expect ( element . current ) . to . equal ( 3 ) ;
71
- expect ( activeButton ) . to . have . class ( 'active-button ' ) ;
120
+ expect ( activeButton ) . to . have . class ( 'active' ) ;
72
121
} ) ;
73
122
74
123
it ( 'goes to last page on click and disables last and next buttons' , async ( ) => {
75
- let buttons = element . shadowRoot ?. querySelector ( '#group ' ) ?. children ;
124
+ let buttons = element . shadowRoot ?. querySelector ( '#pages ' ) ?. children ;
76
125
const lastButton = buttons ! [ 7 ] as HTMLElement ;
77
126
const nextButton = buttons ! [ 6 ] as HTMLElement ;
78
127
lastButton . click ( ) ;
79
128
80
129
await elementUpdated ( element ) ;
81
130
82
- buttons = element . shadowRoot ?. querySelector ( '#group ' ) ?. children ;
131
+ buttons = element . shadowRoot ?. querySelector ( '#pages ' ) ?. children ;
83
132
const activeButton = buttons ! [ 5 ] as HTMLElement ;
84
133
85
134
expect ( element . current ) . to . equal ( 30 ) ;
86
- expect ( activeButton ) . to . have . class ( 'active-button ' ) ;
135
+ expect ( activeButton ) . to . have . class ( 'active' ) ;
87
136
expect ( nextButton ) . to . have . attribute ( 'disabled' ) ;
88
137
expect ( lastButton ) . to . have . attribute ( 'disabled' ) ;
89
138
} ) ;
@@ -92,15 +141,15 @@ describe('UUIPaginationElement', () => {
92
141
element . current = 3 ;
93
142
await elementUpdated ( element ) ;
94
143
95
- const buttons = element . shadowRoot ?. querySelector ( '#group ' ) ?. children ;
144
+ const buttons = element . shadowRoot ?. querySelector ( '#pages ' ) ?. children ;
96
145
const firstButton = buttons ! [ 0 ] as HTMLElement ;
97
146
const previousButton = buttons ! [ 1 ] as HTMLElement ;
98
147
firstButton . click ( ) ;
99
148
await elementUpdated ( element ) ;
100
149
101
150
const activeButton = buttons ! [ 2 ] as HTMLElement ;
102
151
expect ( element . current ) . to . equal ( 1 ) ;
103
- expect ( activeButton ) . to . have . class ( 'active-button ' ) ;
152
+ expect ( activeButton ) . to . have . class ( 'active' ) ;
104
153
expect ( firstButton ) . to . have . attribute ( 'disabled' ) ;
105
154
expect ( previousButton ) . to . have . attribute ( 'disabled' ) ;
106
155
} ) ;
@@ -110,12 +159,11 @@ describe('UUIPaginationElement', () => {
110
159
html ` < uui-pagination .total =${ 30 } > </ uui-pagination > `
111
160
) ;
112
161
113
- const children = element . shadowRoot ?. querySelector ( '#group ' ) ?. children ;
162
+ const children = element . shadowRoot ?. querySelector ( '#pages ' ) ?. children ;
114
163
const arr = [ ] . slice . call ( children ) ;
115
164
116
165
const hasDots =
117
- arr . filter ( ( e : HTMLElement ) => e . classList . contains ( 'dots-button' ) )
118
- . length > 0 ;
166
+ arr . filter ( ( e : HTMLElement ) => e . classList . contains ( 'dots' ) ) . length > 0 ;
119
167
expect ( hasDots ) . to . be . true ;
120
168
} ) ;
121
169
@@ -124,12 +172,11 @@ describe('UUIPaginationElement', () => {
124
172
html ` < uui-pagination .total =${ 1 } > </ uui-pagination > `
125
173
) ;
126
174
127
- const children = element . shadowRoot ?. querySelector ( '#group ' ) ?. children ;
175
+ const children = element . shadowRoot ?. querySelector ( '#pages ' ) ?. children ;
128
176
const arr = [ ] . slice . call ( children ) ;
129
177
130
178
const hasDots =
131
- arr . filter ( ( e : HTMLElement ) => e . classList . contains ( 'dots-button' ) )
132
- . length > 0 ;
179
+ arr . filter ( ( e : HTMLElement ) => e . classList . contains ( 'dots' ) ) . length > 0 ;
133
180
expect ( hasDots ) . to . be . false ;
134
181
} ) ;
135
182
0 commit comments