@@ -100,7 +100,16 @@ describe('UUIToastNotificationContainerElement', () => {
100
100
101
101
element . appendChild ( toastElement ) ;
102
102
103
- await sleep ( 600 ) ; // Enough time to cover if it did happen that the element opened and auto-closed.
103
+ // Wait for OPENED event
104
+ const openedListener = oneEvent (
105
+ toastElement ,
106
+ UUIToastNotificationEvent . OPENED
107
+ ) ;
108
+ const openedEvent = await openedListener ;
109
+ expect ( openedEvent ) . to . exist ;
110
+ expect ( openedEvent . type ) . to . equal ( UUIToastNotificationEvent . OPENED ) ;
111
+
112
+ await sleep ( element . autoClose + 1 ) ; // Enough time to cover if it did happen that the element opened and auto-closed.
104
113
105
114
// Check that its open.
106
115
expect ( toastElement . open ) . to . be . true ;
@@ -113,28 +122,51 @@ describe('UUIToastNotificationContainerElement', () => {
113
122
element . appendChild ( toastElement ) ;
114
123
115
124
await elementUpdated ( element ) ;
116
- await sleep ( 100 ) ;
125
+
126
+ // Wait for OPENING event
127
+ const openingListener = oneEvent (
128
+ toastElement ,
129
+ UUIToastNotificationEvent . OPENING
130
+ ) ;
131
+ const openingEvent = await openingListener ;
132
+ expect ( openingEvent ) . to . exist ;
133
+ expect ( openingEvent . type ) . to . equal ( UUIToastNotificationEvent . OPENING ) ;
117
134
118
135
element . pauseAutoClose ( ) ;
119
136
120
- await sleep ( 500 ) ; // Enough time to cover if it did happen that the element opened and auto-closed.
137
+ // Wait for OPENED event
138
+ const openedListener = oneEvent (
139
+ toastElement ,
140
+ UUIToastNotificationEvent . OPENED
141
+ ) ;
142
+ const openedEvent = await openedListener ;
143
+ expect ( openedEvent ) . to . exist ;
144
+ expect ( openedEvent . type ) . to . equal ( UUIToastNotificationEvent . OPENED ) ;
121
145
122
146
// Check that its still open, pause actually did work.
123
147
expect ( toastElement . open ) . to . be . true ;
124
148
} ) ;
125
149
126
150
it ( 'pausing autoClose when open' , async ( ) => {
127
- element . autoClose = 200 ;
151
+ element . autoClose = 20 ;
128
152
await elementUpdated ( element ) ;
129
153
130
154
element . appendChild ( toastElement ) ;
131
155
132
156
await elementUpdated ( element ) ;
133
- await sleep ( 500 ) ;
157
+
158
+ // Wait for OPENED event
159
+ const openedListener = oneEvent (
160
+ toastElement ,
161
+ UUIToastNotificationEvent . OPENED
162
+ ) ;
163
+ const openedEvent = await openedListener ;
164
+ expect ( openedEvent ) . to . exist ;
165
+ expect ( openedEvent . type ) . to . equal ( UUIToastNotificationEvent . OPENED ) ;
134
166
135
167
element . pauseAutoClose ( ) ;
136
168
137
- await sleep ( 300 ) ; // Enough time to cover if it did happen that the element auto-closed.
169
+ await sleep ( element . autoClose + 1 ) ; // Enough time to cover if it did happen that the element auto-closed.
138
170
139
171
// Check that its still open, pause actually did work.
140
172
expect ( toastElement . open ) . to . be . true ;
@@ -146,7 +178,14 @@ describe('UUIToastNotificationContainerElement', () => {
146
178
147
179
element . appendChild ( toastElement ) ;
148
180
149
- await sleep ( 100 ) ; // Enough time to cover if it did happen that the element opened and auto-closed.
181
+ // Wait for OPENED event
182
+ const openedListener = oneEvent (
183
+ toastElement ,
184
+ UUIToastNotificationEvent . OPENED
185
+ ) ;
186
+ const openedEvent = await openedListener ;
187
+ expect ( openedEvent ) . to . exist ;
188
+ expect ( openedEvent . type ) . to . equal ( UUIToastNotificationEvent . OPENED ) ;
150
189
151
190
// Check that its still open, pause actually did work.
152
191
expect ( toastElement . open ) . to . be . true ;
@@ -168,19 +207,26 @@ describe('UUIToastNotificationContainerElement', () => {
168
207
element . appendChild ( toastElement ) ;
169
208
170
209
await elementUpdated ( element ) ;
171
- await sleep ( 100 ) ;
210
+
211
+ // Wait for OPENED event
212
+ const openedListener = oneEvent (
213
+ toastElement ,
214
+ UUIToastNotificationEvent . OPENED
215
+ ) ;
216
+ const openedEvent = await openedListener ;
217
+ expect ( openedEvent ) . to . exist ;
218
+ expect ( openedEvent . type ) . to . equal ( UUIToastNotificationEvent . OPENED ) ;
172
219
173
220
toastElement . dispatchEvent ( new Event ( 'focus' ) ) ;
174
221
175
- await sleep ( 400 ) ; // Enough time to cover if it did happen that the element opened and auto-closed.
222
+ await sleep ( element . autoClose + 1 ) ; // Enough time to cover if it did happen that the element opened and auto-closed.
176
223
177
224
// Check that its still open, pause actually did work.
178
- expect ( ( toastElement as any ) . _animate ) . to . be . false ; // Checking private _animate to ensure that guessed animation time was good.
179
225
expect ( toastElement . open ) . to . be . true ;
180
226
181
227
toastElement . dispatchEvent ( new Event ( 'blur' ) ) ;
182
228
183
- await sleep ( 40 ) ; // Enough time to cover if it did happen that the element opened and auto-closed.
229
+ await sleep ( element . autoClose + 1 ) ; // Enough time to cover if it did happen that the element opened and auto-closed.
184
230
185
231
// Check that its still open, pause actually did work.
186
232
expect ( toastElement . open ) . to . be . false ;
@@ -192,19 +238,26 @@ describe('UUIToastNotificationContainerElement', () => {
192
238
element . appendChild ( toastElement ) ;
193
239
194
240
await elementUpdated ( element ) ;
195
- await sleep ( 100 ) ;
241
+
242
+ // Wait for OPENED event
243
+ const openedListener = oneEvent (
244
+ toastElement ,
245
+ UUIToastNotificationEvent . OPENED
246
+ ) ;
247
+ const openedEvent = await openedListener ;
248
+ expect ( openedEvent ) . to . exist ;
249
+ expect ( openedEvent . type ) . to . equal ( UUIToastNotificationEvent . OPENED ) ;
196
250
197
251
toastElement . dispatchEvent ( new Event ( 'mouseenter' ) ) ;
198
252
199
- await sleep ( 400 ) ; // Enough time to cover if it did happen that the element opened and auto-closed.
253
+ await sleep ( element . autoClose + 1 ) ; // Enough time to cover if it did happen that the element opened and auto-closed.
200
254
201
255
// Check that its still open, pause actually did work.
202
- expect ( ( toastElement as any ) . _animate ) . to . be . false ; // Checking private _animate to ensure that guessed animation time was good.
203
256
expect ( toastElement . open ) . to . be . true ;
204
257
205
258
toastElement . dispatchEvent ( new Event ( 'mouseleave' ) ) ;
206
259
207
- await sleep ( 40 ) ; // Enough time to cover if it did happen that the element opened and auto-closed.
260
+ await sleep ( element . autoClose + 1 ) ; // Enough time to cover if it did happen that the element opened and auto-closed.
208
261
209
262
// Check that its still open, pause actually did work.
210
263
expect ( toastElement . open ) . to . be . false ;
0 commit comments