@@ -18,6 +18,8 @@ import {
1818}  from  '@angular/core' ; 
1919import  { By }  from  '@angular/platform-browser' ; 
2020import  { NoopAnimationsModule }  from  '@angular/platform-browser/animations' ; 
21+ import  { Location }  from  '@angular/common' ; 
22+ import  { SpyLocation }  from  '@angular/common/testing' ; 
2123import  { MdDialogModule }  from  './index' ; 
2224import  { MdDialog }  from  './dialog' ; 
2325import  { MdDialogContainer }  from  './dialog-container' ; 
@@ -33,6 +35,7 @@ describe('MdDialog', () => {
3335
3436  let  testViewContainerRef : ViewContainerRef ; 
3537  let  viewContainerFixture : ComponentFixture < ComponentWithChildViewContainer > ; 
38+   let  mockLocation : SpyLocation ; 
3639
3740  beforeEach ( async ( ( )  =>  { 
3841    TestBed . configureTestingModule ( { 
@@ -41,15 +44,17 @@ describe('MdDialog', () => {
4144        { provide : OverlayContainer ,  useFactory : ( )  =>  { 
4245          overlayContainerElement  =  document . createElement ( 'div' ) ; 
4346          return  { getContainerElement : ( )  =>  overlayContainerElement } ; 
44-         } } 
47+         } } , 
48+         { provide : Location ,  useClass : SpyLocation } 
4549      ] , 
4650    } ) ; 
4751
4852    TestBed . compileComponents ( ) ; 
4953  } ) ) ; 
5054
51-   beforeEach ( inject ( [ MdDialog ] ,  ( d : MdDialog )  =>  { 
55+   beforeEach ( inject ( [ MdDialog ,   Location ] ,  ( d : MdDialog ,   l :  Location )  =>  { 
5256    dialog  =  d ; 
57+     mockLocation  =  l  as  SpyLocation ; 
5358  } ) ) ; 
5459
5560  beforeEach ( ( )  =>  { 
@@ -334,6 +339,34 @@ describe('MdDialog', () => {
334339    expect ( dialogContainer . _state ) . toBe ( 'exit' ) ; 
335340  } ) ; 
336341
342+   it ( 'should close all dialogs when the user goes forwards/backwards in history' ,  async ( ( )  =>  { 
343+     dialog . open ( PizzaMsg ) ; 
344+     dialog . open ( PizzaMsg ) ; 
345+ 
346+     expect ( overlayContainerElement . querySelectorAll ( 'md-dialog-container' ) . length ) . toBe ( 2 ) ; 
347+ 
348+     mockLocation . simulateUrlPop ( '' ) ; 
349+     viewContainerFixture . detectChanges ( ) ; 
350+ 
351+     viewContainerFixture . whenStable ( ) . then ( ( )  =>  { 
352+       expect ( overlayContainerElement . querySelectorAll ( 'md-dialog-container' ) . length ) . toBe ( 0 ) ; 
353+     } ) ; 
354+   } ) ) ; 
355+ 
356+   it ( 'should close all open dialogs when the location hash changes' ,  async ( ( )  =>  { 
357+     dialog . open ( PizzaMsg ) ; 
358+     dialog . open ( PizzaMsg ) ; 
359+ 
360+     expect ( overlayContainerElement . querySelectorAll ( 'md-dialog-container' ) . length ) . toBe ( 2 ) ; 
361+ 
362+     mockLocation . simulateHashChange ( '' ) ; 
363+     viewContainerFixture . detectChanges ( ) ; 
364+ 
365+     viewContainerFixture . whenStable ( ) . then ( ( )  =>  { 
366+       expect ( overlayContainerElement . querySelectorAll ( 'md-dialog-container' ) . length ) . toBe ( 0 ) ; 
367+     } ) ; 
368+   } ) ) ; 
369+ 
337370  describe ( 'passing in data' ,  ( )  =>  { 
338371    it ( 'should be able to pass in data' ,  ( )  =>  { 
339372      let  config  =  { 
@@ -588,7 +621,8 @@ describe('MdDialog with a parent MdDialog', () => {
588621        { provide : OverlayContainer ,  useFactory : ( )  =>  { 
589622          overlayContainerElement  =  document . createElement ( 'div' ) ; 
590623          return  { getContainerElement : ( )  =>  overlayContainerElement } ; 
591-         } } 
624+         } } , 
625+         { provide : Location ,  useClass : SpyLocation } 
592626      ] , 
593627    } ) ; 
594628
0 commit comments