|
1 | 1 | import '../alien/InitTestEnvironment'; |
2 | 2 |
|
3 | | -import { describe, it } from '@ephox/bedrock-client'; |
| 3 | +import { context, describe, it } from '@ephox/bedrock-client'; |
4 | 4 |
|
5 | 5 | 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'; |
9 | 9 | import { Assertions } from '@ephox/agar'; |
10 | 10 | import { Fun } from '@ephox/katamari'; |
11 | 11 | import { throwTimeout } from '../alien/TestHelpers'; |
12 | 12 |
|
13 | | -describe.skip('EventBlacklistingTest', () => { |
| 13 | +describe('EventBlacklistingTest', () => { |
14 | 14 | const shouldRunInAngularZone = <T>(source: Observable<T>) => |
15 | 15 | source.pipe( |
16 | 16 | tap(() => Assertions.assertEq('Subscribers to events should run within NgZone', true, NgZone.isInAngularZone())) |
17 | 17 | ); |
18 | 18 |
|
| 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 | + |
19 | 35 | eachVersionContext([ '4', '5', '6', '7', '8' ], () => { |
20 | | - const createFixture = editorHook(EditorComponent); |
| 36 | + context('zoneless', () => { |
| 37 | + const createFixture = editorHook(EditorComponent); |
| 38 | + const isZoneless = true; |
21 | 39 |
|
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); |
26 | 46 | }); |
| 47 | + }); |
27 | 48 |
|
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 | + }); |
41 | 60 | }); |
42 | 61 | }); |
43 | 62 | }); |
0 commit comments