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