Skip to content

Commit 85dab1c

Browse files
INT-3396: adjust event blacklisting test
1 parent 0593b02 commit 85dab1c

2 files changed

Lines changed: 44 additions & 25 deletions

File tree

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,62 @@
11
import '../alien/InitTestEnvironment';
22

3-
import { describe, it } from '@ephox/bedrock-client';
3+
import { context, describe, it } from '@ephox/bedrock-client';
44

55
import { EditorComponent } from '../../../main/ts/public_api';
6-
import { eachVersionContext, editorHook } from '../alien/TestHooks';
7-
import { map, merge, timer, first, buffer, Observable, tap, firstValueFrom } from 'rxjs';
8-
import { NgZone } from '@angular/core';
6+
import { eachVersionContext, EditorFixture, editorHook } from '../alien/TestHooks';
7+
import { map, merge, timer, first, buffer, Observable, tap, firstValueFrom, identity } from 'rxjs';
8+
import { NgZone, provideZoneChangeDetection } from '@angular/core';
99
import { Assertions } from '@ephox/agar';
1010
import { Fun } from '@ephox/katamari';
1111
import { throwTimeout } from '../alien/TestHelpers';
1212

13-
describe.skip('EventBlacklistingTest', () => {
13+
describe('EventBlacklistingTest', () => {
1414
const shouldRunInAngularZone = <T>(source: Observable<T>) =>
1515
source.pipe(
1616
tap(() => Assertions.assertEq('Subscribers to events should run within NgZone', true, NgZone.isInAngularZone()))
1717
);
1818

19+
const testEventsShouldBeBoundWhenAllowed = async (fixture: EditorFixture<EditorComponent>, isZoneless: boolean) => {
20+
const pEventsCompleted = firstValueFrom(
21+
merge(
22+
fixture.editorComponent.onKeyUp.pipe(map(Fun.constant('onKeyUp')), isZoneless ? identity : shouldRunInAngularZone),
23+
fixture.editorComponent.onKeyDown.pipe(map(Fun.constant('onKeyDown')), isZoneless ? identity : shouldRunInAngularZone),
24+
fixture.editorComponent.onClick.pipe(map(Fun.constant('onClick')), isZoneless ? identity : shouldRunInAngularZone)
25+
).pipe(throwTimeout(10000, 'Timed out waiting for some event to fire'), buffer(timer(100)), first())
26+
);
27+
fixture.editor.fire('keydown');
28+
fixture.editor.fire('keyclick');
29+
fixture.editor.fire('keyup');
30+
const eventsCompleted = await pEventsCompleted;
31+
Assertions.assertEq('Only one event should have fired', 1, eventsCompleted.length);
32+
Assertions.assertEq('Only keyup should fire', 'onKeyUp', eventsCompleted[0]);
33+
};
34+
1935
eachVersionContext([ '4', '5', '6', '7', '8' ], () => {
20-
const createFixture = editorHook(EditorComponent);
36+
context('zoneless', () => {
37+
const createFixture = editorHook(EditorComponent);
38+
const isZoneless = true;
2139

22-
it('Events should be bound when allowed', async () => {
23-
const fixture = await createFixture({
24-
allowedEvents: 'onKeyUp,onClick,onInit',
25-
ignoreEvents: 'onClick',
40+
it('Events should be bound when allowed', async () => {
41+
const fixture = await createFixture({
42+
allowedEvents: 'onKeyUp,onClick,onInit',
43+
ignoreEvents: 'onClick',
44+
});
45+
await testEventsShouldBeBoundWhenAllowed(fixture, isZoneless);
2646
});
47+
});
2748

28-
const pEventsCompleted = firstValueFrom(
29-
merge(
30-
fixture.editorComponent.onKeyUp.pipe(map(Fun.constant('onKeyUp')), shouldRunInAngularZone),
31-
fixture.editorComponent.onKeyDown.pipe(map(Fun.constant('onKeyDown')), shouldRunInAngularZone),
32-
fixture.editorComponent.onClick.pipe(map(Fun.constant('onClick')), shouldRunInAngularZone)
33-
).pipe(throwTimeout(10000, 'Timed out waiting for some event to fire'), buffer(timer(100)), first())
34-
);
35-
fixture.editor.fire('keydown');
36-
fixture.editor.fire('keyclick');
37-
fixture.editor.fire('keyup');
38-
const eventsCompleted = await pEventsCompleted;
39-
Assertions.assertEq('Only one event should have fired', 1, eventsCompleted.length);
40-
Assertions.assertEq('Only keyup should fire', 'onKeyUp', eventsCompleted[0]);
49+
context('with zone.js', () => {
50+
const createFixture = editorHook(EditorComponent, { providers: [ provideZoneChangeDetection() ] });
51+
const isZoneless = false;
52+
53+
it('Events should be bound when allowed', async () => {
54+
const fixture = await createFixture({
55+
allowedEvents: 'onKeyUp,onClick,onInit',
56+
ignoreEvents: 'onClick',
57+
});
58+
await testEventsShouldBeBoundWhenAllowed(fixture, isZoneless);
59+
});
4160
});
4261
});
4362
});

tinymce-angular-component/src/test/ts/browser/NgZoneTest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('NgZoneTest', () => {
2222
it('Subscribers to events should run within NgZone', async () => {
2323
const fixture = TestBed.createComponent(EditorComponent);
2424
const editor = fixture.componentInstance;
25-
fixture.detectChanges();
25+
fixture.detectChanges(); // TODO: consider using fixture.whenStable()
2626

2727
await new Promise<void>((resolve) => {
2828
editor.onInit.pipe(first(), throwTimeout(10000, 'Timed out waiting for init event')).subscribe(() => {
@@ -36,7 +36,7 @@ describe('NgZoneTest', () => {
3636
it('Subscribers to onKeyUp should run within NgZone', async () => {
3737
const fixture = TestBed.createComponent(EditorComponent);
3838
const editor = fixture.componentInstance;
39-
fixture.detectChanges();
39+
fixture.detectChanges(); // TODO: consider using fixture.whenStable()
4040

4141
await new Promise<void>((resolve) => {
4242
editor.onKeyUp.pipe(first(), throwTimeout(10000, 'Timed out waiting for key up event')).subscribe(() => {

0 commit comments

Comments
 (0)