Skip to content

Commit 67fd40e

Browse files
committed
Tests: extract TestHelpers.forceScrollableWindow for tests that need the window to scroll
1 parent 52307eb commit 67fd40e

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

tests/unit/draggable/draggable_core.js

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,11 @@ test( "#6258: not following mouse when scrolled and using overflow-y: scroll", f
118118
.scrollLeft( 0 );
119119
}
120120
}),
121-
contentToForceScroll = $( "<div>" ).css({
122-
height: "10000px",
123-
width: "10000px"
124-
}),
125121
oldOverflowY = $( "html" ).css( "overflow-y" ),
126122
oldOverflowX = $( "html" ).css( "overflow-x" );
127123

128-
contentToForceScroll.appendTo( "#qunit-fixture" );
124+
TestHelpers.forceScrollableWindow();
125+
129126
$( "html" )
130127
.css( "overflow-y", "scroll" )
131128
.css( "overflow-x", "scroll" )
@@ -148,13 +145,10 @@ test( "#9315: Draggable: jumps down with offset of scrollbar", function() {
148145
equal( ui.position.top, 11, "top position is correct when position is absolute" );
149146
$( "html" ).scrollTop( 0 ).scrollLeft( 0 );
150147
}
151-
}),
152-
contentToForceScroll = $( "<div>" ).css({
153-
height: "10000px",
154-
width: "10000px"
155148
});
156149

157-
contentToForceScroll.appendTo( "#qunit-fixture" );
150+
TestHelpers.forceScrollableWindow();
151+
158152
$( "html" ).scrollTop( 300 ).scrollLeft( 300 );
159153

160154
element.simulate( "drag", {
@@ -178,13 +172,11 @@ test( "#5009: scroll not working with parent's position fixed", function() {
178172
equal( ui.position.top, 10, "top position is correct when parent position is fixed" );
179173
$( document ).scrollTop( 0 ).scrollLeft( 0 );
180174
}
181-
}),
182-
contentToForceScroll = $( "<div>" ).css({
183-
height: "20000px",
184-
width: "20000px"
185175
});
186176

187-
$( "#qunit-fixture" ).append( contentToForceScroll );
177+
178+
TestHelpers.forceScrollableWindow();
179+
188180
$( "#wrapper" ).css( "position", "fixed" );
189181

190182
element.simulate( "drag", {

tests/unit/selectable/selectable_events.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,8 @@ test( "mousedown: initial position of helper", function() {
4040

4141
var helperOffset,
4242
element = $( "#selectable1" ).selectable(),
43-
contentToForceScroll = $( "<div>" ).css({
44-
height: "10000px",
45-
width: "10000px"
46-
});
43+
contentToForceScroll = TestHelpers.forceScrollableWindow( "body" );
4744

48-
contentToForceScroll.appendTo( "body" );
4945
$( window ).scrollTop( 100 ).scrollLeft( 100 );
5046

5147
element.simulate( "mousedown", {

tests/unit/testsuite.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,13 @@ TestHelpers.onFocus= function( element, onFocus ) {
191191
element.bind( "focus", fn )[ 0 ].focus();
192192
};
193193

194+
TestHelpers.forceScrollableWindow = function( appendTo ) {
195+
return $( "<div>" ).css({
196+
height: "10000px",
197+
width: "10000px"
198+
}).appendTo( appendTo || "#qunit-fixture" );
199+
};
200+
194201
/*
195202
* Taken from https://github.com/jquery/qunit/tree/master/addons/close-enough
196203
*/

0 commit comments

Comments
 (0)