aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/draggable/draggable_test_helpers.js
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/draggable/draggable_test_helpers.js')
-rw-r--r--tests/unit/draggable/draggable_test_helpers.js44
1 files changed, 32 insertions, 12 deletions
diff --git a/tests/unit/draggable/draggable_test_helpers.js b/tests/unit/draggable/draggable_test_helpers.js
index dcf2d6297..1858e187b 100644
--- a/tests/unit/draggable/draggable_test_helpers.js
+++ b/tests/unit/draggable/draggable_test_helpers.js
@@ -1,14 +1,20 @@
-define( function() {
+define( [
+ "jquery",
+ "lib/helper",
+ "ui/draggable"
+], function( $, helper ) {
-var draggableTestHelpers = {
+return $.extend( helper, {
// TODO: remove the unreliable offset hacks
unreliableOffset: $.ui.ie && ( !document.documentMode || document.documentMode < 8 ) ? 2 : 0,
// Support: Opera 12.10, Safari 5.1, jQuery <1.8
+
unreliableContains: (function() {
var element = $( "<div>" );
return $.contains( element[ 0 ].ownerDocument, element[ 0 ] );
})(),
+
testDragPosition: function( el, dx, dy, expectedDX, expectedDY, msg ) {
msg = msg ? msg + "." : "";
@@ -17,6 +23,7 @@ var draggableTestHelpers = {
deepEqual( ui.position, positionExpected, "position dragged[" + dx + ", " + dy + "] " + msg );
});
},
+
testDragOffset: function( el, dx, dy, expectedDX, expectedDY, msg ) {
msg = msg ? msg + "." : "";
@@ -27,6 +34,7 @@ var draggableTestHelpers = {
deepEqual( ui.offset, offsetExpected, "offset dragged[" + dx + ", " + dy + "] " + msg );
});
},
+
testDragHelperOffset: function( el, dx, dy, expectedDX, expectedDY, msg ) {
msg = msg ? msg + "." : "";
@@ -37,33 +45,38 @@ var draggableTestHelpers = {
deepEqual( ui.helper.offset(), offsetExpected, "offset dragged[" + dx + ", " + dy + "] " + msg );
});
},
+
testDrag: function( el, handle, dx, dy, expectedDX, expectedDY, msg ) {
- draggableTestHelpers.testDragPosition( el, dx, dy, expectedDX, expectedDY, msg );
- draggableTestHelpers.testDragOffset( el, dx, dy, expectedDX, expectedDY, msg );
+ this.testDragPosition( el, dx, dy, expectedDX, expectedDY, msg );
+ this.testDragOffset( el, dx, dy, expectedDX, expectedDY, msg );
$( handle ).simulate( "drag", {
dx: dx,
dy: dy
});
},
+
shouldMovePositionButNotOffset: function( el, msg, handle ) {
handle = handle || el;
- draggableTestHelpers.testDragPosition( el, 100, 100, 100, 100, msg );
- draggableTestHelpers.testDragHelperOffset( el, 100, 100, 0, 0, msg );
+ this.testDragPosition( el, 100, 100, 100, 100, msg );
+ this.testDragHelperOffset( el, 100, 100, 0, 0, msg );
$( handle ).simulate( "drag", {
dx: 100,
dy: 100
});
},
+
shouldMove: function( el, msg, handle ) {
handle = handle || el;
- draggableTestHelpers.testDrag( el, handle, 100, 100, 100, 100, msg );
+ this.testDrag( el, handle, 100, 100, 100, 100, msg );
},
+
shouldNotMove: function( el, msg, handle ) {
handle = handle || el;
- draggableTestHelpers.testDrag( el, handle, 100, 100, 0, 0, msg );
+ this.testDrag( el, handle, 100, 100, 0, 0, msg );
},
+
shouldNotDrag: function( el, msg, handle ) {
handle = handle || el;
@@ -89,39 +102,48 @@ var draggableTestHelpers = {
element.unbind( "dragstop" );
},
+
setScrollable: function( what, isScrollable ) {
var overflow = isScrollable ? "scroll" : "hidden";
$( what ).css({ overflow: overflow, overflowX: overflow, overflowY: overflow });
},
+
testScroll: function( el, position ) {
var oldPosition = $( "#main" ).css( "position" );
$( "#main" ).css({ position: position, top: "0px", left: "0px" });
- draggableTestHelpers.shouldMove( el, position + " parent" );
+ this.shouldMove( el, position + " parent" );
$( "#main" ).css( "position", oldPosition );
},
+
restoreScroll: function( what ) {
$( what ).scrollTop( 0 ).scrollLeft( 0 );
},
+
setScroll: function( what ) {
$( what ).scrollTop( 100 ).scrollLeft( 100 );
},
+
border: function( el, side ) {
return parseInt( el.css( "border-" + side + "-width" ), 10 ) || 0;
},
+
margin: function( el, side ) {
return parseInt( el.css( "margin-" + side ), 10 ) || 0;
},
+
move: function( el, x, y ) {
$( el ).simulate( "drag", {
dx: x,
dy: y
});
},
+
trackMouseCss: function( el ) {
el.bind( "drag", function() {
el.data( "last_dragged_cursor", $( "body" ).css( "cursor" ) );
});
},
+
trackAppendedParent: function( el ) {
// TODO: appendTo is currently ignored if helper is original (see #7044)
el.draggable( "option", "helper", "clone" );
@@ -131,8 +153,6 @@ var draggableTestHelpers = {
el.data( "last_dragged_parent", ui.helper.parent()[ 0 ] );
});
}
-};
-
-return draggableTestHelpers;
+} );
} );