-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathEventBlacklistingTest.ts
More file actions
62 lines (54 loc) · 2.69 KB
/
Copy pathEventBlacklistingTest.ts
File metadata and controls
62 lines (54 loc) · 2.69 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import '../alien/InitTestEnvironment';
import { context, describe, it } from '@ephox/bedrock-client';
import { EditorComponent } from '../../../main/ts/public_api';
import { eachVersionContext, EditorFixture, editorHook } from '../alien/TestHooks';
import { map, merge, timer, first, buffer, Observable, tap, firstValueFrom, identity } from 'rxjs';
import { NgZone, provideZoneChangeDetection } 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()))
);
const testEventsShouldBeBoundWhenAllowed = async (fixture: EditorFixture<EditorComponent>, isZoneless: boolean) => {
const pEventsCompleted = firstValueFrom(
merge(
fixture.editorComponent.onKeyUp.pipe(map(Fun.constant('onKeyUp')), isZoneless ? identity : shouldRunInAngularZone),
fixture.editorComponent.onKeyDown.pipe(map(Fun.constant('onKeyDown')), isZoneless ? identity : shouldRunInAngularZone),
fixture.editorComponent.onClick.pipe(map(Fun.constant('onClick')), isZoneless ? identity : 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]);
};
eachVersionContext([ '4', '5', '6', '7', '8' ], () => {
context('zoneless', () => {
const createFixture = editorHook(EditorComponent);
const isZoneless = true;
it('Events should be bound when allowed', async () => {
const fixture = await createFixture({
allowedEvents: 'onKeyUp,onClick,onInit',
ignoreEvents: 'onClick',
});
await testEventsShouldBeBoundWhenAllowed(fixture, isZoneless);
});
});
context('with zone.js', () => {
const createFixture = editorHook(EditorComponent, { providers: [ provideZoneChangeDetection() ] });
const isZoneless = false;
it('Events should be bound when allowed', async () => {
const fixture = await createFixture({
allowedEvents: 'onKeyUp,onClick,onInit',
ignoreEvents: 'onClick',
});
await testEventsShouldBeBoundWhenAllowed(fixture, isZoneless);
});
});
});
});