@@ -15,6 +15,8 @@ import {NgModule,
1515 Injector ,
1616 Inject ,
1717} from '@angular/core' ;
18+ import { Location } from '@angular/common' ;
19+ import { SpyLocation } from '@angular/common/testing' ;
1820import { MdDialogModule } from './index' ;
1921import { MdDialog } from './dialog' ;
2022import { OverlayContainer } from '../core' ;
@@ -29,6 +31,7 @@ describe('MdDialog', () => {
2931
3032 let testViewContainerRef : ViewContainerRef ;
3133 let viewContainerFixture : ComponentFixture < ComponentWithChildViewContainer > ;
34+ let mockLocation : SpyLocation ;
3235
3336 beforeEach ( async ( ( ) => {
3437 TestBed . configureTestingModule ( {
@@ -37,15 +40,17 @@ describe('MdDialog', () => {
3740 { provide : OverlayContainer , useFactory : ( ) => {
3841 overlayContainerElement = document . createElement ( 'div' ) ;
3942 return { getContainerElement : ( ) => overlayContainerElement } ;
40- } }
43+ } } ,
44+ { provide : Location , useClass : SpyLocation }
4145 ] ,
4246 } ) ;
4347
4448 TestBed . compileComponents ( ) ;
4549 } ) ) ;
4650
47- beforeEach ( inject ( [ MdDialog ] , ( d : MdDialog ) => {
51+ beforeEach ( inject ( [ MdDialog , Location ] , ( d : MdDialog , l : Location ) => {
4852 dialog = d ;
53+ mockLocation = l as SpyLocation ;
4954 } ) ) ;
5055
5156 beforeEach ( ( ) => {
@@ -274,6 +279,28 @@ describe('MdDialog', () => {
274279 expect ( overlayContainerElement . querySelectorAll ( 'md-dialog-container' ) . length ) . toBe ( 0 ) ;
275280 } ) ;
276281
282+ it ( 'should close all open dialogs when the user goes forwards/backwards in history' , ( ) => {
283+ dialog . open ( PizzaMsg ) ;
284+ dialog . open ( PizzaMsg ) ;
285+
286+ expect ( overlayContainerElement . querySelectorAll ( 'md-dialog-container' ) . length ) . toBe ( 2 ) ;
287+
288+ mockLocation . simulateUrlPop ( '' ) ;
289+
290+ expect ( overlayContainerElement . querySelectorAll ( 'md-dialog-container' ) . length ) . toBe ( 0 ) ;
291+ } ) ;
292+
293+ it ( 'should close all open dialogs when the location hash changes' , ( ) => {
294+ dialog . open ( PizzaMsg ) ;
295+ dialog . open ( PizzaMsg ) ;
296+
297+ expect ( overlayContainerElement . querySelectorAll ( 'md-dialog-container' ) . length ) . toBe ( 2 ) ;
298+
299+ mockLocation . simulateHashChange ( '' ) ;
300+
301+ expect ( overlayContainerElement . querySelectorAll ( 'md-dialog-container' ) . length ) . toBe ( 0 ) ;
302+ } ) ;
303+
277304 describe ( 'passing in data' , ( ) => {
278305 it ( 'should be able to pass in data' , ( ) => {
279306 let config = {
@@ -433,7 +460,8 @@ describe('MdDialog with a parent MdDialog', () => {
433460 { provide : OverlayContainer , useFactory : ( ) => {
434461 overlayContainerElement = document . createElement ( 'div' ) ;
435462 return { getContainerElement : ( ) => overlayContainerElement } ;
436- } }
463+ } } ,
464+ { provide : Location , useClass : SpyLocation }
437465 ] ,
438466 } ) ;
439467
0 commit comments