1
- import {
2
- html ,
3
- fixture ,
4
- expect ,
5
- waitUntil ,
6
- elementUpdated ,
7
- } from '@open-wc/testing' ;
1
+ import { html , fixture , expect , elementUpdated } from '@open-wc/testing' ;
8
2
import { UUIPaginationElement } from './uui-pagination.element' ;
9
3
import '.' ;
10
4
@@ -31,17 +25,14 @@ describe('UUIPaginationElement', () => {
31
25
// });
32
26
33
27
it ( 'sets active class on current page' , async ( ) => {
34
- await waitUntil ( ( ) => element . visiblePages . length > 1 ) ;
35
28
element . current = 2 ;
29
+ await elementUpdated ( element ) ;
36
30
const button = element . shadowRoot ?. querySelector ( '#group' ) !
37
31
. children [ 3 ] as HTMLElement ;
38
- await elementUpdated ( button ) ;
39
-
40
32
expect ( button ) . to . have . class ( 'active-button' ) ;
41
33
} ) ;
42
34
43
35
it ( 'goes to selected page on click' , async ( ) => {
44
- await waitUntil ( ( ) => element . visiblePages . length > 1 ) ;
45
36
const button = element . shadowRoot ?. querySelector ( '#group' ) !
46
37
. children [ 3 ] as HTMLElement ;
47
38
button . click ( ) ;
@@ -53,8 +44,9 @@ describe('UUIPaginationElement', () => {
53
44
} ) ;
54
45
55
46
it ( 'goes to previous page on click' , async ( ) => {
56
- await waitUntil ( ( ) => element . visiblePages . length > 1 ) ;
57
47
element . current = 2 ;
48
+ await elementUpdated ( element ) ;
49
+
58
50
const buttons = element . shadowRoot ?. querySelector ( '#group' ) ! . children ;
59
51
const prevButton = buttons ! [ 1 ] as HTMLElement ;
60
52
const activeButton = buttons ! [ 2 ] as HTMLElement ;
@@ -67,21 +59,19 @@ describe('UUIPaginationElement', () => {
67
59
} ) ;
68
60
69
61
it ( 'goes to next page on click' , async ( ) => {
70
- await waitUntil ( ( ) => element . visiblePages . length > 1 ) ;
71
62
element . current = 2 ;
63
+ await elementUpdated ( element ) ;
64
+
72
65
const buttons = element . shadowRoot ?. querySelector ( '#group' ) ?. children ;
73
66
const nextButton = buttons ! [ 6 ] as HTMLElement ;
74
67
const activeButton = buttons ! [ 3 ] as HTMLElement ;
75
68
nextButton . click ( ) ;
76
69
77
- await elementUpdated ( element ) ;
78
-
79
70
expect ( element . current ) . to . equal ( 3 ) ;
80
71
expect ( activeButton ) . to . have . class ( 'active-button' ) ;
81
72
} ) ;
82
73
83
74
it ( 'goes to last page on click and disables last and next buttons' , async ( ) => {
84
- await waitUntil ( ( ) => element . visiblePages . length > 1 ) ;
85
75
let buttons = element . shadowRoot ?. querySelector ( '#group' ) ?. children ;
86
76
const lastButton = buttons ! [ 7 ] as HTMLElement ;
87
77
const nextButton = buttons ! [ 6 ] as HTMLElement ;
@@ -99,16 +89,16 @@ describe('UUIPaginationElement', () => {
99
89
} ) ;
100
90
101
91
it ( 'goes to first page on click and disables first and previous buttons' , async ( ) => {
102
- await waitUntil ( ( ) => element . visiblePages . length > 1 ) ;
103
92
element . current = 3 ;
93
+ await elementUpdated ( element ) ;
94
+
104
95
const buttons = element . shadowRoot ?. querySelector ( '#group' ) ?. children ;
105
96
const firstButton = buttons ! [ 0 ] as HTMLElement ;
106
97
const previousButton = buttons ! [ 1 ] as HTMLElement ;
107
- const activeButton = buttons ! [ 2 ] as HTMLElement ;
108
98
firstButton . click ( ) ;
109
-
110
99
await elementUpdated ( element ) ;
111
100
101
+ const activeButton = buttons ! [ 2 ] as HTMLElement ;
112
102
expect ( element . current ) . to . equal ( 1 ) ;
113
103
expect ( activeButton ) . to . have . class ( 'active-button' ) ;
114
104
expect ( firstButton ) . to . have . attribute ( 'disabled' ) ;
0 commit comments