9
9
} from '@angular/core/testing' ;
10
10
import { By } from '@angular/platform-browser' ;
11
11
import { NgModule , Component , Directive , ViewChild , ViewContainerRef , Injector } from '@angular/core' ;
12
+ import { Location } from '@angular/common' ;
13
+ import { SpyLocation } from '@angular/common/testing' ;
12
14
import { MdDialogModule } from './index' ;
13
15
import { MdDialog } from './dialog' ;
14
16
import { OverlayContainer } from '../core' ;
@@ -22,6 +24,7 @@ describe('MdDialog', () => {
22
24
23
25
let testViewContainerRef : ViewContainerRef ;
24
26
let viewContainerFixture : ComponentFixture < ComponentWithChildViewContainer > ;
27
+ let mockLocation : SpyLocation ;
25
28
26
29
beforeEach ( async ( ( ) => {
27
30
TestBed . configureTestingModule ( {
@@ -30,15 +33,17 @@ describe('MdDialog', () => {
30
33
{ provide : OverlayContainer , useFactory : ( ) => {
31
34
overlayContainerElement = document . createElement ( 'div' ) ;
32
35
return { getContainerElement : ( ) => overlayContainerElement } ;
33
- } }
36
+ } } ,
37
+ { provide : Location , useClass : SpyLocation }
34
38
] ,
35
39
} ) ;
36
40
37
41
TestBed . compileComponents ( ) ;
38
42
} ) ) ;
39
43
40
- beforeEach ( inject ( [ MdDialog ] , ( d : MdDialog ) => {
44
+ beforeEach ( inject ( [ MdDialog , Location ] , ( d : MdDialog , l : Location ) => {
41
45
dialog = d ;
46
+ mockLocation = l as SpyLocation ;
42
47
} ) ) ;
43
48
44
49
beforeEach ( ( ) => {
@@ -271,6 +276,28 @@ describe('MdDialog', () => {
271
276
expect ( overlayContainerElement . querySelectorAll ( 'md-dialog-container' ) . length ) . toBe ( 0 ) ;
272
277
} ) ;
273
278
279
+ it ( 'should close all open dialogs when the user goes forwards/backwards in history' , ( ) => {
280
+ dialog . open ( PizzaMsg ) ;
281
+ dialog . open ( PizzaMsg ) ;
282
+
283
+ expect ( overlayContainerElement . querySelectorAll ( 'md-dialog-container' ) . length ) . toBe ( 2 ) ;
284
+
285
+ mockLocation . simulateUrlPop ( '' ) ;
286
+
287
+ expect ( overlayContainerElement . querySelectorAll ( 'md-dialog-container' ) . length ) . toBe ( 0 ) ;
288
+ } ) ;
289
+
290
+ it ( 'should close all open dialogs when the location hash changes' , ( ) => {
291
+ dialog . open ( PizzaMsg ) ;
292
+ dialog . open ( PizzaMsg ) ;
293
+
294
+ expect ( overlayContainerElement . querySelectorAll ( 'md-dialog-container' ) . length ) . toBe ( 2 ) ;
295
+
296
+ mockLocation . simulateHashChange ( '' ) ;
297
+
298
+ expect ( overlayContainerElement . querySelectorAll ( 'md-dialog-container' ) . length ) . toBe ( 0 ) ;
299
+ } ) ;
300
+
274
301
describe ( 'disableClose option' , ( ) => {
275
302
it ( 'should prevent closing via clicks on the backdrop' , ( ) => {
276
303
dialog . open ( PizzaMsg , {
0 commit comments