@@ -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' ;
@@ -27,12 +29,13 @@ import {MD_DIALOG_DATA} from './dialog-injector';
27
29
import { dispatchKeyboardEvent } from '../core/testing/dispatch-events' ;
28
30
29
31
30
- describe ( 'MdDialog' , ( ) => {
32
+ fdescribe ( 'MdDialog' , ( ) => {
31
33
let dialog : MdDialog ;
32
34
let overlayContainerElement : HTMLElement ;
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 = {
@@ -540,7 +573,8 @@ describe('MdDialog with a parent MdDialog', () => {
540
573
{ provide : OverlayContainer , useFactory : ( ) => {
541
574
overlayContainerElement = document . createElement ( 'div' ) ;
542
575
return { getContainerElement : ( ) => overlayContainerElement } ;
543
- } }
576
+ } } ,
577
+ { provide : Location , useClass : SpyLocation }
544
578
] ,
545
579
} ) ;
546
580
0 commit comments