-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathEventBlacklistingTest.ts
More file actions
43 lines (37 loc) · 1.86 KB
/
Copy pathEventBlacklistingTest.ts
File metadata and controls
43 lines (37 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import '../alien/InitTestEnvironment';
import { describe, it } from '@ephox/bedrock-client';
import { EditorComponent } from '../../../main/ts/public_api';
import { eachVersionContext, editorHook } from '../alien/TestHooks';
import { map, merge, timer, first, buffer, Observable, tap, firstValueFrom } from 'rxjs';
import { NgZone } from '@angular/core';
import { Assertions } from '@ephox/agar';
import { Fun } from '@ephox/katamari';
import { throwTimeout } from '../alien/TestHelpers';
describe('EventBlacklistingTest', () => {
const shouldRunInAngularZone = <T>(source: Observable<T>) =>
source.pipe(
tap(() => Assertions.assertEq('Subscribers to events should run within NgZone', true, NgZone.isInAngularZone()))
);
eachVersionContext([ '4', '5', '6', '7', '8' ], () => {
const createFixture = editorHook(EditorComponent);
it('Events should be bound when allowed', async () => {
const fixture = await createFixture({
allowedEvents: 'onKeyUp,onClick,onInit',
ignoreEvents: 'onClick',
});
const pEventsCompleted = firstValueFrom(
merge(
fixture.editorComponent.onKeyUp.pipe(map(Fun.constant('onKeyUp')), shouldRunInAngularZone),
fixture.editorComponent.onKeyDown.pipe(map(Fun.constant('onKeyDown')), shouldRunInAngularZone),
fixture.editorComponent.onClick.pipe(map(Fun.constant('onClick')), shouldRunInAngularZone)
).pipe(throwTimeout(10000, 'Timed out waiting for some event to fire'), buffer(timer(100)), first())
);
fixture.editor.fire('keydown');
fixture.editor.fire('keyclick');
fixture.editor.fire('keyup');
const eventsCompleted = await pEventsCompleted;
Assertions.assertEq('Only one event should have fired', 1, eventsCompleted.length);
Assertions.assertEq('Only keyup should fire', 'onKeyUp', eventsCompleted[0]);
});
});
});