@@ -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 { MdDialogContainer } from './dialog-container' ;
@@ -31,6 +33,7 @@ describe('MdDialog', () => {
31
33
32
34
let testViewContainerRef : ViewContainerRef ;
33
35
let viewContainerFixture : ComponentFixture < ComponentWithChildViewContainer > ;
36
+ let mockLocation : SpyLocation ;
34
37
35
38
beforeEach ( async ( ( ) => {
36
39
TestBed . configureTestingModule ( {
@@ -39,15 +42,17 @@ describe('MdDialog', () => {
39
42
{ provide : OverlayContainer , useFactory : ( ) => {
40
43
overlayContainerElement = document . createElement ( 'div' ) ;
41
44
return { getContainerElement : ( ) => overlayContainerElement } ;
42
- } }
45
+ } } ,
46
+ { provide : Location , useClass : SpyLocation }
43
47
] ,
44
48
} ) ;
45
49
46
50
TestBed . compileComponents ( ) ;
47
51
} ) ) ;
48
52
49
- beforeEach ( inject ( [ MdDialog ] , ( d : MdDialog ) => {
53
+ beforeEach ( inject ( [ MdDialog , Location ] , ( d : MdDialog , l : Location ) => {
50
54
dialog = d ;
55
+ mockLocation = l as SpyLocation ;
51
56
} ) ) ;
52
57
53
58
beforeEach ( ( ) => {
@@ -323,6 +328,34 @@ describe('MdDialog', () => {
323
328
} ) ;
324
329
} ) ) ;
325
330
331
+ it ( 'should close all dialogs when the user goes forwards/backwards in history' , async ( ( ) => {
332
+ dialog . open ( PizzaMsg ) ;
333
+ dialog . open ( PizzaMsg ) ;
334
+
335
+ expect ( overlayContainerElement . querySelectorAll ( 'md-dialog-container' ) . length ) . toBe ( 2 ) ;
336
+
337
+ mockLocation . simulateUrlPop ( '' ) ;
338
+ viewContainerFixture . detectChanges ( ) ;
339
+
340
+ viewContainerFixture . whenStable ( ) . then ( ( ) => {
341
+ expect ( overlayContainerElement . querySelectorAll ( 'md-dialog-container' ) . length ) . toBe ( 0 ) ;
342
+ } ) ;
343
+ } ) ) ;
344
+
345
+ it ( 'should close all open dialogs when the location hash changes' , async ( ( ) => {
346
+ dialog . open ( PizzaMsg ) ;
347
+ dialog . open ( PizzaMsg ) ;
348
+
349
+ expect ( overlayContainerElement . querySelectorAll ( 'md-dialog-container' ) . length ) . toBe ( 2 ) ;
350
+
351
+ mockLocation . simulateHashChange ( '' ) ;
352
+ viewContainerFixture . detectChanges ( ) ;
353
+
354
+ viewContainerFixture . whenStable ( ) . then ( ( ) => {
355
+ expect ( overlayContainerElement . querySelectorAll ( 'md-dialog-container' ) . length ) . toBe ( 0 ) ;
356
+ } ) ;
357
+ } ) ) ;
358
+
326
359
describe ( 'passing in data' , ( ) => {
327
360
it ( 'should be able to pass in data' , ( ) => {
328
361
let config = {
@@ -485,7 +518,8 @@ describe('MdDialog with a parent MdDialog', () => {
485
518
{ provide : OverlayContainer , useFactory : ( ) => {
486
519
overlayContainerElement = document . createElement ( 'div' ) ;
487
520
return { getContainerElement : ( ) => overlayContainerElement } ;
488
- } }
521
+ } } ,
522
+ { provide : Location , useClass : SpyLocation }
489
523
] ,
490
524
} ) ;
491
525
0 commit comments