@@ -110,28 +110,53 @@ describe('overlay_position', () => {
110110 beforeEach ( ( ) => {
111111 relativeElement . style . height = '600px'
112112 relativeElement . style . overflow = 'auto'
113+ } )
114+ describe ( 'not scrolled' , ( ) => {
115+ beforeEach ( ( ) => {
116+ const content = document . createElement ( 'div' )
117+ content . style . height = '500px'
118+ content . style . width = '700px'
119+ relativeElement . appendChild ( content )
120+ } )
113121
114- const content = document . createElement ( 'div' )
115- content . style . height = '3000px'
116- content . style . width = '3000px'
117- relativeElement . appendChild ( content )
122+ it ( 'should return a position above the given target if the overlay fits above' , ( ) => {
123+ const target = createTarget ( { left : 100 , top : 200 } )
124+ const position = calculateOverlayPosition ( { relativeElement, target, hoverOverlayElement } )
125+ applyOffsets ( hoverOverlayElement , position )
126+ assert . deepStrictEqual ( position , { left : 100 , top : 50 } )
127+ } )
118128
119- relativeElement . scrollTop = 400
120- relativeElement . scrollLeft = 200
129+ it ( 'should return a position below the a given target if the overlay does not fit above' , ( ) => {
130+ const target = createTarget ( { left : 100 , top : 140 } )
131+ const position = calculateOverlayPosition ( { relativeElement, target, hoverOverlayElement } )
132+ applyOffsets ( hoverOverlayElement , position )
133+ assert . deepStrictEqual ( position , { left : 100 , top : 156 } )
134+ } )
121135 } )
136+ describe ( 'scrolled' , ( ) => {
137+ beforeEach ( ( ) => {
138+ const content = document . createElement ( 'div' )
139+ content . style . height = '3000px'
140+ content . style . width = '3000px'
141+ relativeElement . appendChild ( content )
122142
123- it ( 'should return a position above the given target if the overlay fits above' , ( ) => {
124- const target = createTarget ( { left : 300 , top : 600 } )
125- const position = calculateOverlayPosition ( { relativeElement, target, hoverOverlayElement } )
126- applyOffsets ( hoverOverlayElement , position )
127- assert . deepStrictEqual ( position , { left : 300 , top : 450 } )
128- } )
143+ relativeElement . scrollTop = 400
144+ relativeElement . scrollLeft = 200
145+ } )
129146
130- it ( 'should return a position below the a given target if the overlay does not fit above' , ( ) => {
131- const target = createTarget ( { left : 300 , top : 450 } )
132- const position = calculateOverlayPosition ( { relativeElement, target, hoverOverlayElement } )
133- applyOffsets ( hoverOverlayElement , position )
134- assert . deepStrictEqual ( position , { left : 300 , top : 466 } )
147+ it ( 'should return a position above the given target if the overlay fits above' , ( ) => {
148+ const target = createTarget ( { left : 300 , top : 600 } )
149+ const position = calculateOverlayPosition ( { relativeElement, target, hoverOverlayElement } )
150+ applyOffsets ( hoverOverlayElement , position )
151+ assert . deepStrictEqual ( position , { left : 300 , top : 450 } )
152+ } )
153+
154+ it ( 'should return a position below the a given target if the overlay does not fit above' , ( ) => {
155+ const target = createTarget ( { left : 300 , top : 450 } )
156+ const position = calculateOverlayPosition ( { relativeElement, target, hoverOverlayElement } )
157+ applyOffsets ( hoverOverlayElement , position )
158+ assert . deepStrictEqual ( position , { left : 300 , top : 466 } )
159+ } )
135160 } )
136161 } )
137162 } )
0 commit comments