@@ -27,6 +27,16 @@ import {
27
27
import { filter } from 'rxjs' ;
28
28
import { CoreNavigator } from '@services/navigator' ;
29
29
30
+ enum BehatBlocking {
31
+ DOM_MUTATION = 'dom-mutation' ,
32
+ BLOCKED = 'blocked' ,
33
+ FORCED_DELAY = 'forced-delay' ,
34
+ DELAY = 'DELAY' , // Special entry to indicate there are pending entries.
35
+ HTTP_REQUEST = 'httprequest-' , // Prefix for HTTP requests.
36
+ GENERATED = 'generated-' , // Prefix for generated keys.
37
+ NAVIGATION = 'navigation-' , // Prefix for navigation keys.
38
+ }
39
+
30
40
/**
31
41
* Behat block JS manager.
32
42
*/
@@ -136,10 +146,10 @@ export class TestingBehatBlockingService {
136
146
block ( key = '' ) : string {
137
147
// Add a special DELAY entry whenever another entry is added.
138
148
if ( this . pendingList . length === 0 ) {
139
- this . pendingList . push ( ' DELAY' ) ;
149
+ this . pendingList . push ( BehatBlocking . DELAY ) ;
140
150
}
141
151
if ( ! key ) {
142
- key = `generated- ${ this . keyIndex } ` ;
152
+ key = `${ BehatBlocking . GENERATED } ${ this . keyIndex } ` ;
143
153
this . keyIndex ++ ;
144
154
}
145
155
this . pendingList . push ( key ) ;
@@ -187,7 +197,7 @@ export class TestingBehatBlockingService {
187
197
* Adds a pending key to the array, but removes it after some ticks.
188
198
*/
189
199
async delay ( ) : Promise < void > {
190
- const key = this . block ( 'forced-delay' ) ;
200
+ const key = this . block ( BehatBlocking . FORCED_DELAY ) ;
191
201
await this . unblock ( key ) ;
192
202
}
193
203
@@ -218,7 +228,7 @@ export class TestingBehatBlockingService {
218
228
219
229
if ( ! this . recentMutation ) {
220
230
this . recentMutation = true ;
221
- this . block ( 'dom-mutation' ) ;
231
+ this . block ( BehatBlocking . DOM_MUTATION ) ;
222
232
223
233
setTimeout ( ( ) => {
224
234
this . pollRecentMutation ( ) ;
@@ -246,7 +256,7 @@ export class TestingBehatBlockingService {
246
256
protected pollRecentMutation ( ) : void {
247
257
if ( Date . now ( ) - this . lastMutation > 500 ) {
248
258
this . recentMutation = false ;
249
- this . unblock ( 'dom-mutation' ) ;
259
+ this . unblock ( BehatBlocking . DOM_MUTATION ) ;
250
260
251
261
return ;
252
262
}
@@ -285,12 +295,12 @@ export class TestingBehatBlockingService {
285
295
286
296
if ( isBlocked ) {
287
297
if ( ! this . waitingBlocked ) {
288
- this . block ( 'blocked' ) ;
298
+ this . block ( BehatBlocking . BLOCKED ) ;
289
299
this . waitingBlocked = true ;
290
300
}
291
301
} else {
292
302
if ( this . waitingBlocked ) {
293
- this . unblock ( 'blocked' ) ;
303
+ this . unblock ( BehatBlocking . BLOCKED ) ;
294
304
this . waitingBlocked = false ;
295
305
}
296
306
}
@@ -306,7 +316,7 @@ export class TestingBehatBlockingService {
306
316
XMLHttpRequest . prototype . open = function ( ...args ) {
307
317
NgZone . run ( ( ) => {
308
318
const index = requestIndex ++ ;
309
- const key = `httprequest- ${ index } ` ;
319
+ const key = `${ BehatBlocking . HTTP_REQUEST } ${ index } ` ;
310
320
const isAsync = args [ 2 ] !== false ;
311
321
312
322
try {
0 commit comments