Skip to content

Commit be9f856

Browse files
committed
MOBILE-4842 behat: Add constants to behat blocking service
1 parent 5041393 commit be9f856

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/testing/services/behat-blocking.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ import {
2727
import { filter } from 'rxjs';
2828
import { CoreNavigator } from '@services/navigator';
2929

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+
3040
/**
3141
* Behat block JS manager.
3242
*/
@@ -136,10 +146,10 @@ export class TestingBehatBlockingService {
136146
block(key = ''): string {
137147
// Add a special DELAY entry whenever another entry is added.
138148
if (this.pendingList.length === 0) {
139-
this.pendingList.push('DELAY');
149+
this.pendingList.push(BehatBlocking.DELAY);
140150
}
141151
if (!key) {
142-
key = `generated-${this.keyIndex}`;
152+
key = `${BehatBlocking.GENERATED}${this.keyIndex}`;
143153
this.keyIndex++;
144154
}
145155
this.pendingList.push(key);
@@ -187,7 +197,7 @@ export class TestingBehatBlockingService {
187197
* Adds a pending key to the array, but removes it after some ticks.
188198
*/
189199
async delay(): Promise<void> {
190-
const key = this.block('forced-delay');
200+
const key = this.block(BehatBlocking.FORCED_DELAY);
191201
await this.unblock(key);
192202
}
193203

@@ -218,7 +228,7 @@ export class TestingBehatBlockingService {
218228

219229
if (!this.recentMutation) {
220230
this.recentMutation = true;
221-
this.block('dom-mutation');
231+
this.block(BehatBlocking.DOM_MUTATION);
222232

223233
setTimeout(() => {
224234
this.pollRecentMutation();
@@ -246,7 +256,7 @@ export class TestingBehatBlockingService {
246256
protected pollRecentMutation(): void {
247257
if (Date.now() - this.lastMutation > 500) {
248258
this.recentMutation = false;
249-
this.unblock('dom-mutation');
259+
this.unblock(BehatBlocking.DOM_MUTATION);
250260

251261
return;
252262
}
@@ -285,12 +295,12 @@ export class TestingBehatBlockingService {
285295

286296
if (isBlocked) {
287297
if (!this.waitingBlocked) {
288-
this.block('blocked');
298+
this.block(BehatBlocking.BLOCKED);
289299
this.waitingBlocked = true;
290300
}
291301
} else {
292302
if (this.waitingBlocked) {
293-
this.unblock('blocked');
303+
this.unblock(BehatBlocking.BLOCKED);
294304
this.waitingBlocked = false;
295305
}
296306
}
@@ -306,7 +316,7 @@ export class TestingBehatBlockingService {
306316
XMLHttpRequest.prototype.open = function(...args) {
307317
NgZone.run(() => {
308318
const index = requestIndex++;
309-
const key = `httprequest-${index}`;
319+
const key = `${BehatBlocking.HTTP_REQUEST}${index}`;
310320
const isAsync = args[2] !== false;
311321

312322
try {

0 commit comments

Comments
 (0)