@@ -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,61 @@ 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
+
1589
+ afterEach ( ( ) => {
1590
+ overlayContainer . ngOnDestroy ( ) ;
1591
+ } ) ;
1592
+
1593
+ beforeEach ( ( ) => {
1594
+ viewContainerFixture = TestBed . createComponent ( ComponentWithChildViewContainer ) ;
1595
+ viewContainerFixture . detectChanges ( ) ;
1596
+ testViewContainerRef = viewContainerFixture . componentInstance . childViewContainer ;
1597
+ } ) ;
1598
+
1599
+ it ( 'should return the current state of the dialog' , fakeAsync ( ( ) => {
1600
+ const dialogRef = dialog . open ( PizzaMsg , { viewContainerRef : testViewContainerRef } ) ;
1601
+ // Duration of the close animation in milliseconds. Extracted from the
1602
+ // Angular animations definition of the dialog.
1603
+ const dialogCloseDuration = 75 ;
1604
+
1605
+ expect ( dialogRef . getState ( ) ) . toBe ( MatDialogState . OPEN ) ;
1606
+ dialogRef . close ( ) ;
1607
+ viewContainerFixture . detectChanges ( ) ;
1608
+
1609
+ expect ( dialogRef . getState ( ) ) . toBe ( MatDialogState . CLOSING ) ;
1610
+
1611
+ // Ensure that the closing state is still set if half of the animation has
1612
+ // passed by. The dialog state should be only set to `closed` when the dialog
1613
+ // finished the close animation.
1614
+ tick ( dialogCloseDuration / 2 ) ;
1615
+ expect ( dialogRef . getState ( ) ) . toBe ( MatDialogState . CLOSING ) ;
1616
+
1617
+ // Flush the remaining duration of the closing animation. We flush all other remaining
1618
+ // tasks (e.g. the fallback close timeout) to avoid fakeAsync pending timer failures.
1619
+ flush ( ) ;
1620
+ expect ( dialogRef . getState ( ) ) . toBe ( MatDialogState . CLOSED ) ;
1621
+ } ) ) ;
1622
+ } ) ;
1623
+
1582
1624
@Directive ( { selector : 'dir-with-view-container' } )
1583
1625
class DirectiveWithViewContainer {
1584
1626
constructor ( public viewContainerRef : ViewContainerRef ) { }
0 commit comments