@@ -14,6 +14,7 @@ import {
14
14
15
15
describe ( 'RepositionScrollStrategy' , ( ) => {
16
16
let overlayRef : OverlayRef ;
17
+ let overlay : Overlay ;
17
18
let componentPortal : ComponentPortal < PastaMsg > ;
18
19
let scrolledSubject = new Subject ( ) ;
19
20
@@ -30,9 +31,8 @@ describe('RepositionScrollStrategy', () => {
30
31
TestBed . compileComponents ( ) ;
31
32
} ) ) ;
32
33
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 ;
36
36
componentPortal = new ComponentPortal ( PastaMsg ) ;
37
37
} ) ) ;
38
38
@@ -42,6 +42,11 @@ describe('RepositionScrollStrategy', () => {
42
42
} ) ) ;
43
43
44
44
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 ) ;
45
50
overlayRef . attach ( componentPortal ) ;
46
51
spyOn ( overlayRef , 'updatePosition' ) ;
47
52
@@ -53,6 +58,11 @@ describe('RepositionScrollStrategy', () => {
53
58
} ) ;
54
59
55
60
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 ) ;
56
66
overlayRef . attach ( componentPortal ) ;
57
67
spyOn ( overlayRef , 'updatePosition' ) ;
58
68
@@ -63,6 +73,11 @@ describe('RepositionScrollStrategy', () => {
63
73
} ) ;
64
74
65
75
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 ) ;
66
81
overlayRef . attach ( componentPortal ) ;
67
82
spyOn ( overlayRef , 'updatePosition' ) ;
68
83
@@ -72,6 +87,30 @@ describe('RepositionScrollStrategy', () => {
72
87
expect ( overlayRef . updatePosition ) . not . toHaveBeenCalled ( ) ;
73
88
} ) ;
74
89
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
+
75
114
} ) ;
76
115
77
116
0 commit comments