@@ -20,7 +20,7 @@ import {
20
20
ComponentFactoryResolver
21
21
} from '@angular/core' ;
22
22
import { By } from '@angular/platform-browser' ;
23
- import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
23
+ import { BrowserAnimationsModule , NoopAnimationsModule } from '@angular/platform-browser/animations' ;
24
24
import { Location } from '@angular/common' ;
25
25
import { SpyLocation } from '@angular/common/testing' ;
26
26
import { Directionality } from '@angular/cdk/bidi' ;
@@ -777,19 +777,6 @@ describe('MatDialog', () => {
777
777
expect ( resolver . resolveComponentFactory ) . toHaveBeenCalled ( ) ;
778
778
} ) ) ;
779
779
780
- it ( 'should return the current state of the dialog' , fakeAsync ( ( ) => {
781
- const dialogRef = dialog . open ( PizzaMsg , { viewContainerRef : testViewContainerRef } ) ;
782
-
783
- expect ( dialogRef . getState ( ) ) . toBe ( MatDialogState . OPEN ) ;
784
- dialogRef . close ( ) ;
785
- viewContainerFixture . detectChanges ( ) ;
786
-
787
- expect ( dialogRef . getState ( ) ) . toBe ( MatDialogState . CLOSING ) ;
788
- flush ( ) ;
789
-
790
- expect ( dialogRef . getState ( ) ) . toBe ( MatDialogState . CLOSED ) ;
791
- } ) ) ;
792
-
793
780
describe ( 'passing in data' , ( ) => {
794
781
it ( 'should be able to pass in data' , ( ) => {
795
782
let config = {
@@ -1579,6 +1566,59 @@ describe('MatDialog with default options', () => {
1579
1566
} ) ;
1580
1567
1581
1568
1569
+ describe ( 'MatDialog with animations enabled' , ( ) => {
1570
+ let dialog : MatDialog ;
1571
+ let overlayContainer : OverlayContainer ;
1572
+
1573
+ let testViewContainerRef : ViewContainerRef ;
1574
+ let viewContainerFixture : ComponentFixture < ComponentWithChildViewContainer > ;
1575
+
1576
+ beforeEach ( fakeAsync ( ( ) => {
1577
+ TestBed . configureTestingModule ( {
1578
+ imports : [ MatDialogModule , DialogTestModule , BrowserAnimationsModule ] ,
1579
+ } ) ;
1580
+
1581
+ TestBed . compileComponents ( ) ;
1582
+ } ) ) ;
1583
+
1584
+ beforeEach ( inject ( [ MatDialog , OverlayContainer ] , ( d : MatDialog , oc : OverlayContainer ) => {
1585
+ dialog = d ;
1586
+ overlayContainer = oc ;
1587
+
1588
+ viewContainerFixture = TestBed . createComponent ( ComponentWithChildViewContainer ) ;
1589
+ viewContainerFixture . detectChanges ( ) ;
1590
+ testViewContainerRef = viewContainerFixture . componentInstance . childViewContainer ;
1591
+ } ) ) ;
1592
+
1593
+ afterEach ( ( ) => {
1594
+ overlayContainer . ngOnDestroy ( ) ;
1595
+ } ) ;
1596
+
1597
+ it ( 'should return the current state of the dialog' , fakeAsync ( ( ) => {
1598
+ const dialogRef = dialog . open ( PizzaMsg , { viewContainerRef : testViewContainerRef } ) ;
1599
+ // Duration of the close animation in milliseconds. Extracted from the
1600
+ // Angular animations definition of the dialog.
1601
+ const dialogCloseDuration = 75 ;
1602
+
1603
+ expect ( dialogRef . getState ( ) ) . toBe ( MatDialogState . OPEN ) ;
1604
+ dialogRef . close ( ) ;
1605
+ viewContainerFixture . detectChanges ( ) ;
1606
+
1607
+ expect ( dialogRef . getState ( ) ) . toBe ( MatDialogState . CLOSING ) ;
1608
+
1609
+ // Ensure that the closing state is still set if half of the animation has
1610
+ // passed by. The dialog state should be only set to `closed` when the dialog
1611
+ // finished the close animation.
1612
+ tick ( dialogCloseDuration / 2 ) ;
1613
+ expect ( dialogRef . getState ( ) ) . toBe ( MatDialogState . CLOSING ) ;
1614
+
1615
+ // Flush the remaining duration of the closing animation. We flush all other remaining
1616
+ // tasks (e.g. the fallback close timeout) to avoid fakeAsync pending timer failures.
1617
+ flush ( ) ;
1618
+ expect ( dialogRef . getState ( ) ) . toBe ( MatDialogState . CLOSED ) ;
1619
+ } ) ) ;
1620
+ } ) ;
1621
+
1582
1622
@Directive ( { selector : 'dir-with-view-container' } )
1583
1623
class DirectiveWithViewContainer {
1584
1624
constructor ( public viewContainerRef : ViewContainerRef ) { }
0 commit comments