@@ -16,6 +16,8 @@ import {NgModule,
16
16
Inject ,
17
17
} from '@angular/core' ;
18
18
import { By } from '@angular/platform-browser' ;
19
+ import { Location } from '@angular/common' ;
20
+ import { SpyLocation } from '@angular/common/testing' ;
19
21
import { MdDialogModule } from './index' ;
20
22
import { MdDialog } from './dialog' ;
21
23
import { OverlayContainer } from '../core' ;
@@ -30,6 +32,7 @@ describe('MdDialog', () => {
30
32
31
33
let testViewContainerRef : ViewContainerRef ;
32
34
let viewContainerFixture : ComponentFixture < ComponentWithChildViewContainer > ;
35
+ let mockLocation : SpyLocation ;
33
36
34
37
beforeEach ( async ( ( ) => {
35
38
TestBed . configureTestingModule ( {
@@ -38,15 +41,17 @@ describe('MdDialog', () => {
38
41
{ provide : OverlayContainer , useFactory : ( ) => {
39
42
overlayContainerElement = document . createElement ( 'div' ) ;
40
43
return { getContainerElement : ( ) => overlayContainerElement } ;
41
- } }
44
+ } } ,
45
+ { provide : Location , useClass : SpyLocation }
42
46
] ,
43
47
} ) ;
44
48
45
49
TestBed . compileComponents ( ) ;
46
50
} ) ) ;
47
51
48
- beforeEach ( inject ( [ MdDialog ] , ( d : MdDialog ) => {
52
+ beforeEach ( inject ( [ MdDialog , Location ] , ( d : MdDialog , l : Location ) => {
49
53
dialog = d ;
54
+ mockLocation = l as SpyLocation ;
50
55
} ) ) ;
51
56
52
57
beforeEach ( ( ) => {
@@ -279,6 +284,28 @@ describe('MdDialog', () => {
279
284
expect ( overlayContainerElement . querySelectorAll ( 'md-dialog-container' ) . length ) . toBe ( 0 ) ;
280
285
} ) ;
281
286
287
+ it ( 'should close all open dialogs when the user goes forwards/backwards in history' , ( ) => {
288
+ dialog . open ( PizzaMsg ) ;
289
+ dialog . open ( PizzaMsg ) ;
290
+
291
+ expect ( overlayContainerElement . querySelectorAll ( 'md-dialog-container' ) . length ) . toBe ( 2 ) ;
292
+
293
+ mockLocation . simulateUrlPop ( '' ) ;
294
+
295
+ expect ( overlayContainerElement . querySelectorAll ( 'md-dialog-container' ) . length ) . toBe ( 0 ) ;
296
+ } ) ;
297
+
298
+ it ( 'should close all open dialogs when the location hash changes' , ( ) => {
299
+ dialog . open ( PizzaMsg ) ;
300
+ dialog . open ( PizzaMsg ) ;
301
+
302
+ expect ( overlayContainerElement . querySelectorAll ( 'md-dialog-container' ) . length ) . toBe ( 2 ) ;
303
+
304
+ mockLocation . simulateHashChange ( '' ) ;
305
+
306
+ expect ( overlayContainerElement . querySelectorAll ( 'md-dialog-container' ) . length ) . toBe ( 0 ) ;
307
+ } ) ;
308
+
282
309
describe ( 'passing in data' , ( ) => {
283
310
it ( 'should be able to pass in data' , ( ) => {
284
311
let config = {
0 commit comments