@@ -16,9 +16,7 @@ import {
16
16
ViewChild ,
17
17
NgZone ,
18
18
} from '@angular/core' ;
19
- import { AnimationEvent } from '@angular/animations' ;
20
19
import { By } from '@angular/platform-browser' ;
21
- import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
22
20
import { Direction , Directionality } from '@angular/cdk/bidi' ;
23
21
import { OverlayContainer , OverlayModule , CdkScrollable } from '@angular/cdk/overlay' ;
24
22
import { Platform } from '@angular/cdk/platform' ;
@@ -29,6 +27,7 @@ import {
29
27
dispatchMouseEvent ,
30
28
createKeyboardEvent ,
31
29
dispatchEvent ,
30
+ createFakeEvent ,
32
31
} from '@angular/cdk/testing/private' ;
33
32
import { ESCAPE } from '@angular/cdk/keycodes' ;
34
33
import { FocusMonitor } from '@angular/cdk/a11y' ;
@@ -56,7 +55,7 @@ describe('MatTooltip', () => {
56
55
platform = { IOS : false , isBrowser : true , ANDROID : false } ;
57
56
58
57
TestBed . configureTestingModule ( {
59
- imports : [ MatTooltipModule , OverlayModule , NoopAnimationsModule ] ,
58
+ imports : [ MatTooltipModule , OverlayModule ] ,
60
59
declarations : [
61
60
BasicTooltipDemo ,
62
61
ScrollableTooltipDemo ,
@@ -114,12 +113,12 @@ describe('MatTooltip', () => {
114
113
fixture . detectChanges ( ) ;
115
114
116
115
// wait till animation has finished
117
- tick ( 500 ) ;
116
+ finishCurrentTooltipAnimation ( overlayContainerElement , true ) ;
118
117
119
118
// Make sure tooltip is shown to the user and animation has finished
120
119
const tooltipElement = overlayContainerElement . querySelector ( '.mat-tooltip' ) as HTMLElement ;
121
120
expect ( tooltipElement instanceof HTMLElement ) . toBe ( true ) ;
122
- expect ( tooltipElement . style . transform ) . toBe ( 'scale(1) ') ;
121
+ expect ( tooltipElement . classList ) . toContain ( 'mat-tooltip-show ') ;
123
122
124
123
expect ( overlayContainerElement . textContent ) . toContain ( initialTooltipMessage ) ;
125
124
@@ -134,7 +133,7 @@ describe('MatTooltip', () => {
134
133
expect ( tooltipDirective . _isTooltipVisible ( ) ) . toBe ( false ) ;
135
134
136
135
// On animation complete, should expect that the tooltip has been detached.
137
- flushMicrotasks ( ) ;
136
+ finishCurrentTooltipAnimation ( overlayContainerElement , false ) ;
138
137
assertTooltipInstance ( tooltipDirective , false ) ;
139
138
} ) ) ;
140
139
@@ -144,17 +143,17 @@ describe('MatTooltip', () => {
144
143
tick ( 0 ) ;
145
144
expect ( tooltipDirective . _isTooltipVisible ( ) ) . toBe ( true ) ;
146
145
fixture . detectChanges ( ) ;
147
- tick ( 500 ) ;
146
+ finishCurrentTooltipAnimation ( overlayContainerElement , true ) ;
148
147
149
148
tooltipDirective . _overlayRef ! . detach ( ) ;
150
149
tick ( 0 ) ;
151
150
fixture . detectChanges ( ) ;
152
151
expect ( tooltipDirective . _isTooltipVisible ( ) ) . toBe ( false ) ;
153
- flushMicrotasks ( ) ;
154
152
assertTooltipInstance ( tooltipDirective , false ) ;
155
153
156
154
tooltipDirective . show ( ) ;
157
155
tick ( 0 ) ;
156
+ finishCurrentTooltipAnimation ( overlayContainerElement , true ) ;
158
157
expect ( tooltipDirective . _isTooltipVisible ( ) ) . toBe ( true ) ;
159
158
} ) ) ;
160
159
@@ -177,7 +176,7 @@ describe('MatTooltip', () => {
177
176
TestBed
178
177
. resetTestingModule ( )
179
178
. configureTestingModule ( {
180
- imports : [ MatTooltipModule , OverlayModule , NoopAnimationsModule ] ,
179
+ imports : [ MatTooltipModule , OverlayModule ] ,
181
180
declarations : [ BasicTooltipDemo ] ,
182
181
providers : [ {
183
182
provide : MAT_TOOLTIP_DEFAULT_OPTIONS ,
@@ -212,7 +211,7 @@ describe('MatTooltip', () => {
212
211
TestBed
213
212
. resetTestingModule ( )
214
213
. configureTestingModule ( {
215
- imports : [ MatTooltipModule , OverlayModule , NoopAnimationsModule ] ,
214
+ imports : [ MatTooltipModule , OverlayModule ] ,
216
215
declarations : [ TooltipDemoWithoutPositionBinding ] ,
217
216
providers : [ {
218
217
provide : MAT_TOOLTIP_DEFAULT_OPTIONS ,
@@ -372,16 +371,7 @@ describe('MatTooltip', () => {
372
371
tooltipDirective . hide ( 0 ) ;
373
372
fixture . detectChanges ( ) ;
374
373
tick ( ) ;
375
-
376
- // At this point the animation should be able to complete itself and trigger the
377
- // _animationDone function, but for unknown reasons in the test infrastructure,
378
- // this does not occur. Manually call the hook so the animation subscriptions get invoked.
379
- tooltipDirective . _tooltipInstance ! . _animationDone ( {
380
- fromState : 'visible' ,
381
- toState : 'hidden' ,
382
- totalTime : 150 ,
383
- phaseName : 'done' ,
384
- } as AnimationEvent ) ;
374
+ finishCurrentTooltipAnimation ( overlayContainerElement , false ) ;
385
375
386
376
expect ( ( ) => {
387
377
tooltipDirective . position = 'right' ;
@@ -395,7 +385,7 @@ describe('MatTooltip', () => {
395
385
396
386
tooltipDirective . show ( ) ;
397
387
tick ( 0 ) ; // Tick for the show delay (default is 0)
398
- expect ( tooltipDirective . _tooltipInstance ! . _visibility ) . toBe ( 'visible' ) ;
388
+ expect ( tooltipDirective . _tooltipInstance ! . isVisible ( ) ) . toBe ( true ) ;
399
389
400
390
fixture . detectChanges ( ) ;
401
391
expect ( overlayContainerElement . textContent ) . toContain ( initialTooltipMessage ) ;
@@ -472,33 +462,21 @@ describe('MatTooltip', () => {
472
462
it ( 'should not try to dispose the tooltip when destroyed and done hiding' , fakeAsync ( ( ) => {
473
463
tooltipDirective . show ( ) ;
474
464
fixture . detectChanges ( ) ;
475
- tick ( 150 ) ;
465
+ finishCurrentTooltipAnimation ( overlayContainerElement , true ) ;
476
466
477
467
const tooltipDelay = 1000 ;
478
468
tooltipDirective . hide ( ) ;
479
469
tick ( tooltipDelay ) ; // Change the tooltip state to hidden and trigger animation start
470
+ finishCurrentTooltipAnimation ( overlayContainerElement , false ) ;
480
471
481
- // Store the tooltip instance, which will be set to null after the button is hidden.
482
- const tooltipInstance = tooltipDirective . _tooltipInstance ! ;
483
472
fixture . componentInstance . showButton = false ;
484
473
fixture . detectChanges ( ) ;
485
-
486
- // At this point the animation should be able to complete itself and trigger the
487
- // _animationDone function, but for unknown reasons in the test infrastructure,
488
- // this does not occur. Manually call this and verify that doing so does not
489
- // throw an error.
490
- tooltipInstance . _animationDone ( {
491
- fromState : 'visible' ,
492
- toState : 'hidden' ,
493
- totalTime : 150 ,
494
- phaseName : 'done' ,
495
- } as AnimationEvent ) ;
496
474
} ) ) ;
497
475
498
476
it ( 'should complete the afterHidden stream when tooltip is destroyed' , fakeAsync ( ( ) => {
499
477
tooltipDirective . show ( ) ;
500
478
fixture . detectChanges ( ) ;
501
- tick ( 150 ) ;
479
+ finishCurrentTooltipAnimation ( overlayContainerElement , true ) ;
502
480
503
481
const spy = jasmine . createSpy ( 'complete spy' ) ;
504
482
const subscription = tooltipDirective . _tooltipInstance ! . afterHidden ( )
@@ -507,7 +485,7 @@ describe('MatTooltip', () => {
507
485
tooltipDirective . hide ( 0 ) ;
508
486
tick ( 0 ) ;
509
487
fixture . detectChanges ( ) ;
510
- tick ( 500 ) ;
488
+ finishCurrentTooltipAnimation ( overlayContainerElement , false ) ;
511
489
512
490
expect ( spy ) . toHaveBeenCalled ( ) ;
513
491
subscription . unsubscribe ( ) ;
@@ -580,7 +558,7 @@ describe('MatTooltip', () => {
580
558
tooltipDirective . show ( ) ;
581
559
tick ( 0 ) ;
582
560
fixture . detectChanges ( ) ;
583
- tick ( 500 ) ;
561
+ finishCurrentTooltipAnimation ( overlayContainerElement , true ) ;
584
562
585
563
let tooltipWrapper =
586
564
overlayContainerElement . querySelector ( '.cdk-overlay-connected-position-bounding-box' ) ! ;
@@ -589,13 +567,13 @@ describe('MatTooltip', () => {
589
567
tooltipDirective . hide ( 0 ) ;
590
568
tick ( 0 ) ;
591
569
fixture . detectChanges ( ) ;
592
- tick ( 500 ) ;
570
+ finishCurrentTooltipAnimation ( overlayContainerElement , false ) ;
593
571
594
572
dir . value = 'ltr' ;
595
573
tooltipDirective . show ( ) ;
596
574
tick ( 0 ) ;
597
575
fixture . detectChanges ( ) ;
598
- tick ( 500 ) ;
576
+ finishCurrentTooltipAnimation ( overlayContainerElement , true ) ;
599
577
600
578
tooltipWrapper =
601
579
overlayContainerElement . querySelector ( '.cdk-overlay-connected-position-bounding-box' ) ! ;
@@ -613,15 +591,15 @@ describe('MatTooltip', () => {
613
591
tooltipDirective . show ( ) ;
614
592
tick ( 0 ) ;
615
593
fixture . detectChanges ( ) ;
616
- tick ( 500 ) ;
594
+ finishCurrentTooltipAnimation ( overlayContainerElement , true ) ;
617
595
618
596
expect ( tooltipDirective . _isTooltipVisible ( ) ) . toBe ( true ) ;
619
597
expect ( overlayContainerElement . textContent ) . toContain ( initialTooltipMessage ) ;
620
598
621
599
document . body . click ( ) ;
622
600
tick ( 0 ) ;
623
601
fixture . detectChanges ( ) ;
624
- tick ( 500 ) ;
602
+ finishCurrentTooltipAnimation ( overlayContainerElement , false ) ;
625
603
fixture . detectChanges ( ) ;
626
604
627
605
expect ( tooltipDirective . _isTooltipVisible ( ) ) . toBe ( false ) ;
@@ -632,10 +610,9 @@ describe('MatTooltip', () => {
632
610
tooltipDirective . show ( ) ;
633
611
tick ( 0 ) ;
634
612
fixture . detectChanges ( ) ;
635
-
636
613
document . body . click ( ) ;
637
614
fixture . detectChanges ( ) ;
638
- tick ( 500 ) ;
615
+ finishCurrentTooltipAnimation ( overlayContainerElement , true ) ;
639
616
640
617
expect ( overlayContainerElement . textContent ) . toContain ( initialTooltipMessage ) ;
641
618
} ) ) ;
@@ -717,7 +694,7 @@ describe('MatTooltip', () => {
717
694
tick ( 0 ) ;
718
695
expect ( tooltipDirective . _isTooltipVisible ( ) ) . toBe ( true ) ;
719
696
fixture . detectChanges ( ) ;
720
- tick ( 500 ) ;
697
+ finishCurrentTooltipAnimation ( overlayContainerElement , true ) ;
721
698
722
699
const overlayRef = tooltipDirective . _overlayRef ! ;
723
700
@@ -727,7 +704,7 @@ describe('MatTooltip', () => {
727
704
tick ( 0 ) ;
728
705
expect ( tooltipDirective . _isTooltipVisible ( ) ) . toBe ( true ) ;
729
706
fixture . detectChanges ( ) ;
730
- tick ( 500 ) ;
707
+ finishCurrentTooltipAnimation ( overlayContainerElement , true ) ;
731
708
732
709
expect ( overlayRef . detach ) . not . toHaveBeenCalled ( ) ;
733
710
} ) ) ;
@@ -864,12 +841,12 @@ describe('MatTooltip', () => {
864
841
fixture . detectChanges ( ) ;
865
842
866
843
// wait until animation has finished
867
- tick ( 500 ) ;
844
+ finishCurrentTooltipAnimation ( overlayContainerElement , true ) ;
868
845
869
846
// Make sure tooltip is shown to the user and animation has finished
870
847
const tooltipElement = overlayContainerElement . querySelector ( '.mat-tooltip' ) as HTMLElement ;
871
848
expect ( tooltipElement instanceof HTMLElement ) . toBe ( true ) ;
872
- expect ( tooltipElement . style . transform ) . toBe ( 'scale(1) ') ;
849
+ expect ( tooltipElement . classList ) . toContain ( 'mat-tooltip-show ') ;
873
850
874
851
// After hide called, a timeout delay is created that will to hide the tooltip.
875
852
const tooltipDelay = 1000 ;
@@ -882,7 +859,7 @@ describe('MatTooltip', () => {
882
859
expect ( tooltipDirective . _isTooltipVisible ( ) ) . toBe ( false ) ;
883
860
884
861
// On animation complete, should expect that the tooltip has been detached.
885
- flushMicrotasks ( ) ;
862
+ finishCurrentTooltipAnimation ( overlayContainerElement , false ) ;
886
863
assertTooltipInstance ( tooltipDirective , false ) ;
887
864
} ) ) ;
888
865
@@ -912,9 +889,9 @@ describe('MatTooltip', () => {
912
889
913
890
assertTooltipInstance ( fixture . componentInstance . tooltip , false ) ;
914
891
915
- tick ( 250 ) ; // Finish the delay.
892
+ tick ( 500 ) ; // Finish the delay.
916
893
fixture . detectChanges ( ) ;
917
- tick ( 500 ) ; // Finish the animation.
894
+ finishCurrentTooltipAnimation ( overlayContainerElement , true ) ; // Finish the animation.
918
895
919
896
assertTooltipInstance ( fixture . componentInstance . tooltip , true ) ;
920
897
} ) ) ;
@@ -953,7 +930,7 @@ describe('MatTooltip', () => {
953
930
fixture . detectChanges ( ) ;
954
931
tick ( 500 ) ; // Finish the open delay.
955
932
fixture . detectChanges ( ) ;
956
- tick ( 500 ) ; // Finish the animation.
933
+ finishCurrentTooltipAnimation ( overlayContainerElement , true ) ; // Finish the animation.
957
934
assertTooltipInstance ( fixture . componentInstance . tooltip , true ) ;
958
935
959
936
dispatchFakeEvent ( button , 'touchend' ) ;
@@ -963,7 +940,7 @@ describe('MatTooltip', () => {
963
940
964
941
tick ( 500 ) ; // Finish the delay.
965
942
fixture . detectChanges ( ) ;
966
- tick ( 500 ) ; // Finish the exit animation.
943
+ finishCurrentTooltipAnimation ( overlayContainerElement , false ) ; // Finish the exit animation.
967
944
968
945
assertTooltipInstance ( fixture . componentInstance . tooltip , false ) ;
969
946
} ) ) ;
@@ -977,7 +954,7 @@ describe('MatTooltip', () => {
977
954
fixture . detectChanges ( ) ;
978
955
tick ( 500 ) ; // Finish the open delay.
979
956
fixture . detectChanges ( ) ;
980
- tick ( 500 ) ; // Finish the animation.
957
+ finishCurrentTooltipAnimation ( overlayContainerElement , true ) ; // Finish the animation.
981
958
assertTooltipInstance ( fixture . componentInstance . tooltip , true ) ;
982
959
983
960
dispatchFakeEvent ( button , 'touchcancel' ) ;
@@ -987,7 +964,7 @@ describe('MatTooltip', () => {
987
964
988
965
tick ( 500 ) ; // Finish the delay.
989
966
fixture . detectChanges ( ) ;
990
- tick ( 500 ) ; // Finish the exit animation.
967
+ finishCurrentTooltipAnimation ( overlayContainerElement , false ) ; // Finish the exit animation.
991
968
992
969
assertTooltipInstance ( fixture . componentInstance . tooltip , false ) ;
993
970
} ) ) ;
@@ -1229,3 +1206,12 @@ function assertTooltipInstance(tooltip: MatTooltip, shouldExist: boolean): void
1229
1206
// happens due to the `_tooltipInstance` having a circular structure.
1230
1207
expect ( ! ! tooltip . _tooltipInstance ) . toBe ( shouldExist ) ;
1231
1208
}
1209
+
1210
+ function finishCurrentTooltipAnimation ( overlayContainer : HTMLElement , isVisible : boolean ) {
1211
+ const tooltip = overlayContainer . querySelector ( '.mat-tooltip' ) ! ;
1212
+ const event = createFakeEvent ( 'animationend' ) ;
1213
+ Object . defineProperty ( event , 'animationName' , {
1214
+ get : ( ) => `mat-tooltip-${ isVisible ? 'show' : 'hide' } `
1215
+ } ) ;
1216
+ dispatchEvent ( tooltip , event ) ;
1217
+ }
0 commit comments