@@ -18,6 +18,8 @@ import {
18
18
} from '@angular/core' ;
19
19
import { By } from '@angular/platform-browser' ;
20
20
import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
21
+ import { Location } from '@angular/common' ;
22
+ import { SpyLocation } from '@angular/common/testing' ;
21
23
import { MdDialogModule } from './index' ;
22
24
import { MdDialog } from './dialog' ;
23
25
import { MdDialogContainer } from './dialog-container' ;
@@ -33,6 +35,7 @@ describe('MdDialog', () => {
33
35
34
36
let testViewContainerRef : ViewContainerRef ;
35
37
let viewContainerFixture : ComponentFixture < ComponentWithChildViewContainer > ;
38
+ let mockLocation : SpyLocation ;
36
39
37
40
beforeEach ( async ( ( ) => {
38
41
TestBed . configureTestingModule ( {
@@ -41,15 +44,17 @@ describe('MdDialog', () => {
41
44
{ provide : OverlayContainer , useFactory : ( ) => {
42
45
overlayContainerElement = document . createElement ( 'div' ) ;
43
46
return { getContainerElement : ( ) => overlayContainerElement } ;
44
- } }
47
+ } } ,
48
+ { provide : Location , useClass : SpyLocation }
45
49
] ,
46
50
} ) ;
47
51
48
52
TestBed . compileComponents ( ) ;
49
53
} ) ) ;
50
54
51
- beforeEach ( inject ( [ MdDialog ] , ( d : MdDialog ) => {
55
+ beforeEach ( inject ( [ MdDialog , Location ] , ( d : MdDialog , l : Location ) => {
52
56
dialog = d ;
57
+ mockLocation = l as SpyLocation ;
53
58
} ) ) ;
54
59
55
60
beforeEach ( ( ) => {
@@ -334,6 +339,34 @@ describe('MdDialog', () => {
334
339
expect ( dialogContainer . _state ) . toBe ( 'exit' ) ;
335
340
} ) ;
336
341
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
+
337
370
describe ( 'passing in data' , ( ) => {
338
371
it ( 'should be able to pass in data' , ( ) => {
339
372
let config = {
@@ -588,7 +621,8 @@ describe('MdDialog with a parent MdDialog', () => {
588
621
{ provide : OverlayContainer , useFactory : ( ) => {
589
622
overlayContainerElement = document . createElement ( 'div' ) ;
590
623
return { getContainerElement : ( ) => overlayContainerElement } ;
591
- } }
624
+ } } ,
625
+ { provide : Location , useClass : SpyLocation }
592
626
] ,
593
627
} ) ;
594
628
0 commit comments