1
+ import { Directionality } from '@angular/cdk/bidi' ;
2
+ import { A , ESCAPE } from '@angular/cdk/keycodes' ;
3
+ import { Overlay , OverlayContainer , ScrollDispatcher } from '@angular/cdk/overlay' ;
4
+ import { _supportsShadowDom } from '@angular/cdk/platform' ;
1
5
import {
2
- ComponentFixture ,
3
- fakeAsync ,
4
- flushMicrotasks ,
5
- TestBed ,
6
- tick ,
7
- flush ,
8
- } from '@angular/core/testing' ;
6
+ createKeyboardEvent ,
7
+ dispatchEvent ,
8
+ dispatchKeyboardEvent ,
9
+ } from '@angular/cdk/testing/private' ;
10
+ import { Location } from '@angular/common' ;
11
+ import { SpyLocation } from '@angular/common/testing' ;
9
12
import {
10
13
ChangeDetectionStrategy ,
11
14
Component ,
12
15
ComponentRef ,
13
16
Directive ,
14
- inject ,
15
17
Inject ,
16
18
InjectionToken ,
17
19
Injector ,
18
20
TemplateRef ,
19
21
ViewChild ,
20
22
ViewContainerRef ,
21
23
ViewEncapsulation ,
24
+ inject ,
22
25
} from '@angular/core' ;
23
- import { By } from '@angular/platform-browser' ;
24
- import { Location } from '@angular/common' ;
25
- import { SpyLocation } from '@angular/common/testing' ;
26
- import { Directionality } from '@angular/cdk/bidi' ;
27
- import { Overlay , OverlayContainer , ScrollDispatcher } from '@angular/cdk/overlay' ;
28
- import { A , ESCAPE } from '@angular/cdk/keycodes' ;
29
- import { _supportsShadowDom } from '@angular/cdk/platform' ;
30
26
import {
31
- dispatchKeyboardEvent ,
32
- createKeyboardEvent ,
33
- dispatchEvent ,
34
- } from '@angular/cdk/testing/private' ;
27
+ ComponentFixture ,
28
+ TestBed ,
29
+ fakeAsync ,
30
+ flush ,
31
+ flushMicrotasks ,
32
+ tick ,
33
+ } from '@angular/core/testing' ;
34
+ import { By } from '@angular/platform-browser' ;
35
35
import { Subject } from 'rxjs' ;
36
36
import { DIALOG_DATA , Dialog , DialogModule , DialogRef } from './index' ;
37
37
@@ -282,17 +282,20 @@ describe('Dialog', () => {
282
282
const spy = jasmine . createSpy ( 'backdropClick spy' ) ;
283
283
dialogRef . backdropClick . subscribe ( spy ) ;
284
284
viewContainerFixture . detectChanges ( ) ;
285
+ flush ( ) ;
285
286
286
287
const backdrop = overlayContainerElement . querySelector ( '.cdk-overlay-backdrop' ) as HTMLElement ;
287
288
288
289
backdrop . click ( ) ;
289
290
viewContainerFixture . detectChanges ( ) ;
291
+ flush ( ) ;
290
292
expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
291
293
292
294
// Additional clicks after the dialog has closed should not be emitted
293
295
dialogRef . disableClose = false ;
294
296
backdrop . click ( ) ;
295
297
viewContainerFixture . detectChanges ( ) ;
298
+ flush ( ) ;
296
299
expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
297
300
} ) ) ;
298
301
@@ -303,6 +306,7 @@ describe('Dialog', () => {
303
306
dialogRef . keydownEvents . subscribe ( spy ) ;
304
307
305
308
viewContainerFixture . detectChanges ( ) ;
309
+ flush ( ) ;
306
310
307
311
let backdrop = overlayContainerElement . querySelector ( '.cdk-overlay-backdrop' ) as HTMLElement ;
308
312
let container = overlayContainerElement . querySelector ( 'cdk-dialog-container' ) as HTMLElement ;
@@ -757,9 +761,11 @@ describe('Dialog', () => {
757
761
fakeAsync ( ( ) => {
758
762
const templateInjectFixture = TestBed . createComponent ( TemplateInjectorParentComponent ) ;
759
763
templateInjectFixture . detectChanges ( ) ;
764
+ flush ( ) ;
760
765
761
766
dialog . open ( templateInjectFixture . componentInstance . templateRef ) ;
762
767
templateInjectFixture . detectChanges ( ) ;
768
+ flush ( ) ;
763
769
764
770
expect ( templateInjectFixture . componentInstance . innerComponentValue ) . toBe (
765
771
'hello from parent component' ,
@@ -840,7 +846,7 @@ describe('Dialog', () => {
840
846
} ) ;
841
847
842
848
viewContainerFixture . detectChanges ( ) ;
843
- flushMicrotasks ( ) ;
849
+ flush ( ) ;
844
850
845
851
expect ( document . activeElement ! . tagName )
846
852
. withContext ( 'Expected first tabbable element (input) in the dialog to be focused.' )
@@ -910,17 +916,15 @@ describe('Dialog', () => {
910
916
911
917
let dialogRef = dialog . open ( PizzaMsg , { viewContainerRef : testViewContainerRef } ) ;
912
918
913
- flushMicrotasks ( ) ;
914
919
viewContainerFixture . detectChanges ( ) ;
915
- flushMicrotasks ( ) ;
920
+ flush ( ) ;
916
921
917
922
expect ( document . activeElement ! . id ) . not . toBe (
918
923
'dialog-trigger' ,
919
924
'Expected the focus to change when dialog was opened.' ,
920
925
) ;
921
926
922
927
dialogRef . close ( ) ;
923
- flushMicrotasks ( ) ;
924
928
viewContainerFixture . detectChanges ( ) ;
925
929
flush ( ) ;
926
930
@@ -939,18 +943,18 @@ describe('Dialog', () => {
939
943
viewContainerFixture . destroy ( ) ;
940
944
const fixture = TestBed . createComponent ( ShadowDomComponent ) ;
941
945
fixture . detectChanges ( ) ;
946
+ flush ( ) ;
942
947
const button = fixture . debugElement . query ( By . css ( 'button' ) ) ! . nativeElement ;
943
948
944
949
button . focus ( ) ;
945
950
946
951
const dialogRef = dialog . open ( PizzaMsg ) ;
947
- flushMicrotasks ( ) ;
948
952
fixture . detectChanges ( ) ;
949
- flushMicrotasks ( ) ;
953
+ flush ( ) ;
950
954
951
955
const spy = spyOn ( button , 'focus' ) . and . callThrough ( ) ;
952
956
dialogRef . close ( ) ;
953
- flushMicrotasks ( ) ;
957
+ flush ( ) ;
954
958
fixture . detectChanges ( ) ;
955
959
tick ( 500 ) ;
956
960
@@ -994,7 +998,7 @@ describe('Dialog', () => {
994
998
dialog . open ( DialogWithoutFocusableElements ) ;
995
999
996
1000
viewContainerFixture . detectChanges ( ) ;
997
- flushMicrotasks ( ) ;
1001
+ flush ( ) ;
998
1002
999
1003
expect ( document . activeElement ! . tagName . toLowerCase ( ) )
1000
1004
. withContext ( 'Expected dialog container to be focused.' )
@@ -1013,14 +1017,12 @@ describe('Dialog', () => {
1013
1017
restoreFocus : false ,
1014
1018
} ) ;
1015
1019
1016
- flushMicrotasks ( ) ;
1017
1020
viewContainerFixture . detectChanges ( ) ;
1018
- flushMicrotasks ( ) ;
1021
+ flush ( ) ;
1019
1022
1020
1023
expect ( document . activeElement ! . id ) . not . toBe ( 'dialog-trigger' ) ;
1021
1024
1022
1025
dialogRef . close ( ) ;
1023
- flushMicrotasks ( ) ;
1024
1026
viewContainerFixture . detectChanges ( ) ;
1025
1027
flush ( ) ;
1026
1028
0 commit comments