@@ -21,6 +21,8 @@ import {
21
21
TestBed ,
22
22
tick ,
23
23
} from '@angular/core/testing' ;
24
+ import { Location } from '@angular/common' ;
25
+ import { SpyLocation } from '@angular/common/testing' ;
24
26
import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
25
27
import { MatBottomSheet } from './bottom-sheet' ;
26
28
import { MAT_BOTTOM_SHEET_DATA , MatBottomSheetConfig } from './bottom-sheet-config' ;
@@ -36,19 +38,24 @@ describe('MatBottomSheet', () => {
36
38
37
39
let testViewContainerRef : ViewContainerRef ;
38
40
let viewContainerFixture : ComponentFixture < ComponentWithChildViewContainer > ;
41
+ let mockLocation : SpyLocation ;
39
42
40
43
beforeEach ( fakeAsync ( ( ) => {
41
44
TestBed
42
- . configureTestingModule ( { imports : [ MatBottomSheetModule , BottomSheetTestModule ] } )
45
+ . configureTestingModule ( {
46
+ imports : [ MatBottomSheetModule , BottomSheetTestModule ] ,
47
+ providers : [ { provide : Location , useClass : SpyLocation } ]
48
+ } )
43
49
. compileComponents ( ) ;
44
50
} ) ) ;
45
51
46
- beforeEach ( inject ( [ MatBottomSheet , OverlayContainer , ViewportRuler ] ,
47
- ( bs : MatBottomSheet , oc : OverlayContainer , vr : ViewportRuler ) => {
52
+ beforeEach ( inject ( [ MatBottomSheet , OverlayContainer , ViewportRuler , Location ] ,
53
+ ( bs : MatBottomSheet , oc : OverlayContainer , vr : ViewportRuler , l : Location ) => {
48
54
bottomSheet = bs ;
49
55
overlayContainer = oc ;
50
56
viewportRuler = vr ;
51
57
overlayContainerElement = oc . getContainerElement ( ) ;
58
+ mockLocation = l as SpyLocation ;
52
59
} ) ) ;
53
60
54
61
afterEach ( ( ) => {
@@ -349,6 +356,42 @@ describe('MatBottomSheet', () => {
349
356
expect ( spy ) . toHaveBeenCalledWith ( 1337 ) ;
350
357
} ) ) ;
351
358
359
+ it ( 'should close the bottom sheet when going forwards/backwards in history' , fakeAsync ( ( ) => {
360
+ bottomSheet . open ( PizzaMsg ) ;
361
+
362
+ expect ( overlayContainerElement . querySelector ( 'mat-bottom-sheet-container' ) ) . toBeTruthy ( ) ;
363
+
364
+ mockLocation . simulateUrlPop ( '' ) ;
365
+ viewContainerFixture . detectChanges ( ) ;
366
+ flush ( ) ;
367
+
368
+ expect ( overlayContainerElement . querySelector ( 'mat-bottom-sheet-container' ) ) . toBeFalsy ( ) ;
369
+ } ) ) ;
370
+
371
+ it ( 'should close the bottom sheet when the location hash changes' , fakeAsync ( ( ) => {
372
+ bottomSheet . open ( PizzaMsg ) ;
373
+
374
+ expect ( overlayContainerElement . querySelector ( 'mat-bottom-sheet-container' ) ) . toBeTruthy ( ) ;
375
+
376
+ mockLocation . simulateHashChange ( '' ) ;
377
+ viewContainerFixture . detectChanges ( ) ;
378
+ flush ( ) ;
379
+
380
+ expect ( overlayContainerElement . querySelector ( 'mat-bottom-sheet-container' ) ) . toBeFalsy ( ) ;
381
+ } ) ) ;
382
+
383
+ it ( 'should allow the consumer to disable closing a bottom sheet on navigation' , fakeAsync ( ( ) => {
384
+ bottomSheet . open ( PizzaMsg , { closeOnNavigation : false } ) ;
385
+
386
+ expect ( overlayContainerElement . querySelector ( 'mat-bottom-sheet-container' ) ) . toBeTruthy ( ) ;
387
+
388
+ mockLocation . simulateUrlPop ( '' ) ;
389
+ viewContainerFixture . detectChanges ( ) ;
390
+ flush ( ) ;
391
+
392
+ expect ( overlayContainerElement . querySelector ( 'mat-bottom-sheet-container' ) ) . toBeTruthy ( ) ;
393
+ } ) ) ;
394
+
352
395
describe ( 'passing in data' , ( ) => {
353
396
it ( 'should be able to pass in data' , ( ) => {
354
397
const config = {
0 commit comments