@@ -15,6 +15,8 @@ import {NgModule,
15
15
Injector ,
16
16
Inject ,
17
17
} from '@angular/core' ;
18
+ import { Location } from '@angular/common' ;
19
+ import { SpyLocation } from '@angular/common/testing' ;
18
20
import { MdDialogModule } from './index' ;
19
21
import { MdDialog } from './dialog' ;
20
22
import { OverlayContainer } from '../core' ;
@@ -29,6 +31,7 @@ describe('MdDialog', () => {
29
31
30
32
let testViewContainerRef : ViewContainerRef ;
31
33
let viewContainerFixture : ComponentFixture < ComponentWithChildViewContainer > ;
34
+ let mockLocation : SpyLocation ;
32
35
33
36
beforeEach ( async ( ( ) => {
34
37
TestBed . configureTestingModule ( {
@@ -37,15 +40,17 @@ describe('MdDialog', () => {
37
40
{ provide : OverlayContainer , useFactory : ( ) => {
38
41
overlayContainerElement = document . createElement ( 'div' ) ;
39
42
return { getContainerElement : ( ) => overlayContainerElement } ;
40
- } }
43
+ } } ,
44
+ { provide : Location , useClass : SpyLocation }
41
45
] ,
42
46
} ) ;
43
47
44
48
TestBed . compileComponents ( ) ;
45
49
} ) ) ;
46
50
47
- beforeEach ( inject ( [ MdDialog ] , ( d : MdDialog ) => {
51
+ beforeEach ( inject ( [ MdDialog , Location ] , ( d : MdDialog , l : Location ) => {
48
52
dialog = d ;
53
+ mockLocation = l as SpyLocation ;
49
54
} ) ) ;
50
55
51
56
beforeEach ( ( ) => {
@@ -274,6 +279,28 @@ describe('MdDialog', () => {
274
279
expect ( overlayContainerElement . querySelectorAll ( 'md-dialog-container' ) . length ) . toBe ( 0 ) ;
275
280
} ) ;
276
281
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
+
277
304
describe ( 'passing in data' , ( ) => {
278
305
it ( 'should be able to pass in data' , ( ) => {
279
306
let config = {
@@ -433,7 +460,8 @@ describe('MdDialog with a parent MdDialog', () => {
433
460
{ provide : OverlayContainer , useFactory : ( ) => {
434
461
overlayContainerElement = document . createElement ( 'div' ) ;
435
462
return { getContainerElement : ( ) => overlayContainerElement } ;
436
- } }
463
+ } } ,
464
+ { provide : Location , useClass : SpyLocation }
437
465
] ,
438
466
} ) ;
439
467
0 commit comments