@@ -14,6 +14,7 @@ import {
1414
1515describe ( 'RepositionScrollStrategy' , ( ) => {
1616 let overlayRef : OverlayRef ;
17+ let overlay : Overlay ;
1718 let componentPortal : ComponentPortal < PastaMsg > ;
1819 let scrolledSubject = new Subject ( ) ;
1920
@@ -30,9 +31,8 @@ describe('RepositionScrollStrategy', () => {
3031 TestBed . compileComponents ( ) ;
3132 } ) ) ;
3233
33- beforeEach ( inject ( [ Overlay ] , ( overlay : Overlay ) => {
34- let overlayConfig = new OverlayConfig ( { scrollStrategy : overlay . scrollStrategies . reposition ( ) } ) ;
35- overlayRef = overlay . create ( overlayConfig ) ;
34+ beforeEach ( inject ( [ Overlay ] , ( o : Overlay ) => {
35+ overlay = o ;
3636 componentPortal = new ComponentPortal ( PastaMsg ) ;
3737 } ) ) ;
3838
@@ -42,6 +42,11 @@ describe('RepositionScrollStrategy', () => {
4242 } ) ) ;
4343
4444 it ( 'should update the overlay position when the page is scrolled' , ( ) => {
45+ const overlayConfig = new OverlayConfig ( {
46+ scrollStrategy : overlay . scrollStrategies . reposition ( )
47+ } ) ;
48+
49+ overlayRef = overlay . create ( overlayConfig ) ;
4550 overlayRef . attach ( componentPortal ) ;
4651 spyOn ( overlayRef , 'updatePosition' ) ;
4752
@@ -53,6 +58,11 @@ describe('RepositionScrollStrategy', () => {
5358 } ) ;
5459
5560 it ( 'should not be updating the position after the overlay is detached' , ( ) => {
61+ const overlayConfig = new OverlayConfig ( {
62+ scrollStrategy : overlay . scrollStrategies . reposition ( )
63+ } ) ;
64+
65+ overlayRef = overlay . create ( overlayConfig ) ;
5666 overlayRef . attach ( componentPortal ) ;
5767 spyOn ( overlayRef , 'updatePosition' ) ;
5868
@@ -63,6 +73,11 @@ describe('RepositionScrollStrategy', () => {
6373 } ) ;
6474
6575 it ( 'should not be updating the position after the overlay is destroyed' , ( ) => {
76+ const overlayConfig = new OverlayConfig ( {
77+ scrollStrategy : overlay . scrollStrategies . reposition ( )
78+ } ) ;
79+
80+ overlayRef = overlay . create ( overlayConfig ) ;
6681 overlayRef . attach ( componentPortal ) ;
6782 spyOn ( overlayRef , 'updatePosition' ) ;
6883
@@ -72,6 +87,30 @@ describe('RepositionScrollStrategy', () => {
7287 expect ( overlayRef . updatePosition ) . not . toHaveBeenCalled ( ) ;
7388 } ) ;
7489
90+ it ( 'should be able to close the overlay once it is out of view' , ( ) => {
91+ const overlayConfig = new OverlayConfig ( {
92+ scrollStrategy : overlay . scrollStrategies . reposition ( {
93+ autoClose : true
94+ } )
95+ } ) ;
96+
97+ overlayRef = overlay . create ( overlayConfig ) ;
98+ overlayRef . attach ( componentPortal ) ;
99+ spyOn ( overlayRef , 'updatePosition' ) ;
100+ spyOn ( overlayRef , 'detach' ) ;
101+ spyOn ( overlayRef . overlayElement , 'getBoundingClientRect' ) . and . returnValue ( {
102+ top : - 1000 ,
103+ bottom : - 900 ,
104+ left : 0 ,
105+ right : 100 ,
106+ width : 100 ,
107+ height : 100
108+ } ) ;
109+
110+ scrolledSubject . next ( ) ;
111+ expect ( overlayRef . detach ) . toHaveBeenCalledTimes ( 1 ) ;
112+ } ) ;
113+
75114} ) ;
76115
77116
0 commit comments