@@ -32,7 +32,6 @@ describe('overlay_position', () => {
3232 background: lightgray;
3333 margin: 20px;
3434 width: 800px;
35- height: 600px;
3635 position: relative;
3736 }
3837 .hover-overlay-element {
@@ -62,20 +61,78 @@ describe('overlay_position', () => {
6261 } )
6362 afterEach ( ( ) => {
6463 relativeElement . remove ( )
64+ document . scrollingElement ! . scrollTop = 0
6565 } )
6666
67- it ( 'should return a position above the given target if the overlay fits above' , ( ) => {
68- const target = createTarget ( { left : 100 , top : 200 } )
69- const position = calculateOverlayPosition ( { relativeElement, target, hoverOverlayElement } )
70- applyOffsets ( hoverOverlayElement , position )
71- assert . deepStrictEqual ( position , { left : 100 , top : 50 } )
67+ describe ( 'with the scrolling element being document' , ( ) => {
68+ describe ( 'not scrolled' , ( ) => {
69+ beforeEach ( ( ) => {
70+ relativeElement . style . height = '600px'
71+ } )
72+
73+ it ( 'should return a position above the given target if the overlay fits above' , ( ) => {
74+ const target = createTarget ( { left : 100 , top : 200 } )
75+ const position = calculateOverlayPosition ( { relativeElement, target, hoverOverlayElement } )
76+ applyOffsets ( hoverOverlayElement , position )
77+ assert . deepStrictEqual ( position , { left : 100 , top : 50 } )
78+ } )
79+
80+ it ( 'should return a position below the a given target if the overlay does not fit above' , ( ) => {
81+ const target = createTarget ( { left : 100 , top : 100 } )
82+ const position = calculateOverlayPosition ( { relativeElement, target, hoverOverlayElement } )
83+ applyOffsets ( hoverOverlayElement , position )
84+ assert . deepStrictEqual ( position , { left : 100 , top : 116 } )
85+ } )
86+ } )
87+ describe ( 'scrolled' , ( ) => {
88+ beforeEach ( ( ) => {
89+ relativeElement . style . height = '3000px'
90+ document . scrollingElement ! . scrollTop = 400
91+ } )
92+
93+ it ( 'should return a position above the given target if the overlay fits above' , ( ) => {
94+ const target = createTarget ( { left : 100 , top : 600 } )
95+ const position = calculateOverlayPosition ( { relativeElement, target, hoverOverlayElement } )
96+ applyOffsets ( hoverOverlayElement , position )
97+ assert . deepStrictEqual ( position , { left : 100 , top : 450 } )
98+ } )
99+
100+ it ( 'should return a position below the a given target if the overlay does not fit above' , ( ) => {
101+ const target = createTarget ( { left : 100 , top : 450 } )
102+ const position = calculateOverlayPosition ( { relativeElement, target, hoverOverlayElement } )
103+ applyOffsets ( hoverOverlayElement , position )
104+ assert . deepStrictEqual ( position , { left : 100 , top : 466 } )
105+ } )
106+ } )
72107 } )
73108
74- it ( 'should return a position below the a given target if the overlay does not fit above' , ( ) => {
75- const target = createTarget ( { left : 100 , top : 100 } )
76- const position = calculateOverlayPosition ( { relativeElement, target, hoverOverlayElement } )
77- applyOffsets ( hoverOverlayElement , position )
78- assert . deepStrictEqual ( position , { left : 100 , top : 116 } )
109+ describe ( 'with the scrolling element being the relativeElement' , ( ) => {
110+ beforeEach ( ( ) => {
111+ relativeElement . style . height = '600px'
112+ relativeElement . style . overflow = 'auto'
113+
114+ const content = document . createElement ( 'div' )
115+ content . style . height = '3000px'
116+ content . style . width = '3000px'
117+ relativeElement . appendChild ( content )
118+
119+ relativeElement . scrollTop = 400
120+ relativeElement . scrollLeft = 200
121+ } )
122+
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+ } )
129+
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 } )
135+ } )
79136 } )
80137 } )
81138} )
0 commit comments