Draggable: Convert tests to new infrastructure

Ref #10119
Ref gh-1528
This commit is contained in:
Scott González 2015-04-06 12:42:49 -04:00
parent 9fb04e42a2
commit fbc55446fb
7 changed files with 245 additions and 252 deletions

View File

@ -4,94 +4,65 @@
<meta charset="utf-8"> <meta charset="utf-8">
<title>jQuery UI Draggable Test Suite</title> <title>jQuery UI Draggable Test Suite</title>
<script src="../../jquery.js"></script> <script src="../../lib/css.js" data-modules="core"></script>
<link rel="stylesheet" href="../../../external/qunit/qunit.css"> <script src="../../lib/bootstrap.js" data-widget="draggable"></script>
<style> <style>
#main { #main {
width: 1000px; width: 1000px;
height: 1000px; height: 1000px;
overflow: scroll; overflow: scroll;
overflow-x: scroll; overflow-x: scroll;
overflow-y: scroll; overflow-y: scroll;
position: relative; position: relative;
left: 0; left: 0;
top: 0; top: 0;
} }
#main-forceScrollable { #main-forceScrollable {
position: absolute; position: absolute;
left: 0; left: 0;
top: 0; top: 0;
width: 1100px; width: 1100px;
height: 1100px; height: 1100px;
} }
#scrollParent { #scrollParent {
width: 1200px; width: 1200px;
height: 1200px; height: 1200px;
position: relative; position: relative;
left: 0; left: 0;
top: 0; top: 0;
overflow: hidden; overflow: hidden;
overflow-x: hidden; overflow-x: hidden;
overflow-y: hidden; overflow-y: hidden;
} }
#scrollParent-forceScrollable { #scrollParent-forceScrollable {
position: absolute; position: absolute;
left: 0; left: 0;
top: 0; top: 0;
width: 1300px; width: 1300px;
height: 1300px; height: 1300px;
} }
/* See #9077 */ /* See #9077 */
#draggable3, #draggable4 { #draggable3, #draggable4 {
z-index: 100; z-index: 100;
} }
.sortable { .sortable {
position: relative; position: relative;
top: 8000px; top: 8000px;
left: 10px; left: 10px;
width: 300px; width: 300px;
padding: 0; padding: 0;
margin: 0; margin: 0;
border: 0; border: 0;
} }
.sortable li { .sortable li {
height: 100px; height: 100px;
padding: 0; padding: 0;
margin: 0; margin: 0;
border: 0; border: 0;
list-style: none; list-style: none;
display: inline-block; display: inline-block;
} }
</style> </style>
<script src="../../../external/qunit/qunit.js"></script>
<script src="../../../external/jquery-simulate/jquery.simulate.js"></script>
<script src="../testsuite.js"></script>
<script src="../../../external/qunit-assert-classes/qunit-assert-classes.js"></script>
<script>
TestHelpers.loadResources({
css: [ "core" ],
js: [
"ui/core.js",
"ui/widget.js",
"ui/mouse.js",
"ui/resizable.js",
"ui/draggable.js",
"ui/droppable.js",
"ui/sortable.js"
]
});
</script>
<script src="draggable_common.js"></script>
<script src="draggable_core.js"></script>
<script src="draggable_events.js"></script>
<script src="draggable_methods.js"></script>
<script src="draggable_options.js"></script>
<script src="draggable_test_helpers.js"></script>
<script src="../swarminject.js"></script>
</head> </head>
<body> <body>

View File

@ -1,4 +1,9 @@
TestHelpers.commonWidgetTests( "draggable", { define( [
"lib/common",
"ui/draggable"
], function( common ) {
common.testWidget( "draggable", {
defaults: { defaults: {
appendTo: "parent", appendTo: "parent",
axis: false, axis: false,
@ -39,3 +44,5 @@ TestHelpers.commonWidgetTests( "draggable", {
stop: null stop: null
} }
}); });
} );

View File

@ -1,8 +1,11 @@
/* define( [
* draggable_core.js "jquery",
*/ "lib/helper",
"./draggable_test_helpers",
(function( $ ) { "ui/draggable",
"ui/droppable",
"ui/resizable"
], function( $, testHelpers, draggableTestHelpers ) {
module( "draggable: core" ); module( "draggable: core" );
@ -44,12 +47,12 @@ test( "element types", function( assert ) {
test( "No options, relative", function() { test( "No options, relative", function() {
expect( 2 ); expect( 2 );
TestHelpers.draggable.shouldMove( $( "#draggable1" ).draggable(), "no options, relative" ); draggableTestHelpers.shouldMove( $( "#draggable1" ).draggable(), "no options, relative" );
}); });
test( "No options, absolute", function() { test( "No options, absolute", function() {
expect( 2 ); expect( 2 );
TestHelpers.draggable.shouldMove( $( "#draggable2" ).draggable(), "no options, absolute" ); draggableTestHelpers.shouldMove( $( "#draggable2" ).draggable(), "no options, absolute" );
}); });
test( "resizable handle with complex markup (#8756 / #8757)", function() { test( "resizable handle with complex markup (#8756 / #8757)", function() {
@ -92,7 +95,7 @@ test( "#8269: Removing draggable element on drop", function() {
}); });
// Support: Opera 12.10, Safari 5.1, jQuery <1.8 // Support: Opera 12.10, Safari 5.1, jQuery <1.8
if ( TestHelpers.draggable.unreliableContains ) { if ( draggableTestHelpers.unreliableContains ) {
ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" ); ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" );
ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" ); ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" );
} else { } else {
@ -118,7 +121,7 @@ test( "Stray mousemove after mousedown still drags", function() {
$( document ).simulate( "mousemove", { button: -1 }); $( document ).simulate( "mousemove", { button: -1 });
}); });
TestHelpers.draggable.shouldMove( element, "element is draggable" ); draggableTestHelpers.shouldMove( element, "element is draggable" );
}); });
test( "#6258: not following mouse when scrolled and using overflow-y: scroll", function() { test( "#6258: not following mouse when scrolled and using overflow-y: scroll", function() {
@ -138,7 +141,7 @@ test( "#6258: not following mouse when scrolled and using overflow-y: scroll", f
oldOverflowY = $( "html" ).css( "overflow-y" ), oldOverflowY = $( "html" ).css( "overflow-y" ),
oldOverflowX = $( "html" ).css( "overflow-x" ); oldOverflowX = $( "html" ).css( "overflow-x" );
TestHelpers.forceScrollableWindow(); testHelpers.forceScrollableWindow();
$( "html" ) $( "html" )
.css( "overflow-y", "scroll" ) .css( "overflow-y", "scroll" )
@ -164,7 +167,7 @@ test( "#9315: jumps down with offset of scrollbar", function() {
} }
}); });
TestHelpers.forceScrollableWindow(); testHelpers.forceScrollableWindow();
$( "html" ).scrollTop( 300 ).scrollLeft( 300 ); $( "html" ).scrollTop( 300 ).scrollLeft( 300 );
@ -198,7 +201,7 @@ test( "scroll offset with fixed ancestors", function() {
} }
}); });
TestHelpers.forceScrollableWindow(); testHelpers.forceScrollableWindow();
$( "#wrapper" ).css( "position", "fixed" ); $( "#wrapper" ).css( "position", "fixed" );
$( "#wrapper2" ).css( "position", "absolute" ); $( "#wrapper2" ).css( "position", "absolute" );
@ -269,8 +272,8 @@ test( "#5727: draggable from iframe", function() {
equal( draggable1.closest( iframeBody ).length, 1 ); equal( draggable1.closest( iframeBody ).length, 1 );
// TODO: fix draggable within an IFRAME to fire events on the element properly // TODO: fix draggable within an IFRAME to fire events on the element properly
// and these TestHelpers.draggable.shouldMove relies on events for testing // and these draggableTestHelpers.shouldMove relies on events for testing
//TestHelpers.draggable.shouldMove( draggable1, "draggable from an iframe" ); //draggableTestHelpers.shouldMove( draggable1, "draggable from an iframe" );
}); });
test( "#8399: A draggable should become the active element after you are finished interacting with it, but not before.", function() { test( "#8399: A draggable should become the active element after you are finished interacting with it, but not before.", function() {
@ -282,7 +285,7 @@ test( "#8399: A draggable should become the active element after you are finishe
notStrictEqual( document.activeElement, element.get( 0 ), "moving a draggable anchor did not make it the active element" ); notStrictEqual( document.activeElement, element.get( 0 ), "moving a draggable anchor did not make it the active element" );
}); });
TestHelpers.draggable.move( element, 50, 50 ); draggableTestHelpers.move( element, 50, 50 );
strictEqual( document.activeElement, element.get( 0 ), "finishing moving a draggable anchor made it the active element" ); strictEqual( document.activeElement, element.get( 0 ), "finishing moving a draggable anchor made it the active element" );
}); });
@ -293,16 +296,16 @@ asyncTest( "blur behavior", function() {
var element = $( "#draggable1" ).draggable(), var element = $( "#draggable1" ).draggable(),
focusElement = $( "<div tabindex='1'></div>" ).appendTo( element ); focusElement = $( "<div tabindex='1'></div>" ).appendTo( element );
TestHelpers.onFocus( focusElement, function() { testHelpers.onFocus( focusElement, function() {
strictEqual( document.activeElement, focusElement.get( 0 ), "test element is focused before mousing down on a draggable" ); strictEqual( document.activeElement, focusElement.get( 0 ), "test element is focused before mousing down on a draggable" );
TestHelpers.draggable.move( focusElement, 1, 1 ); draggableTestHelpers.move( focusElement, 1, 1 );
// http://bugs.jqueryui.com/ticket/10527 // http://bugs.jqueryui.com/ticket/10527
// Draggable: Can't select option in modal dialog (IE8) // Draggable: Can't select option in modal dialog (IE8)
strictEqual( document.activeElement, focusElement.get( 0 ), "test element is focused after mousing down on itself" ); strictEqual( document.activeElement, focusElement.get( 0 ), "test element is focused after mousing down on itself" );
TestHelpers.draggable.move( element, 50, 50 ); draggableTestHelpers.move( element, 50, 50 );
// http://bugs.jqueryui.com/ticket/4261 // http://bugs.jqueryui.com/ticket/4261
// active element should blur when mousing down on a draggable // active element should blur when mousing down on a draggable
@ -341,4 +344,4 @@ test( "ui-draggable-handle managed correctly in nested draggables", function( as
assert.hasClasses( child, "ui-draggable-handle", "child retains class name on destroy" ); assert.hasClasses( child, "ui-draggable-handle", "child retains class name on destroy" );
}); });
})( jQuery ); } );

View File

@ -1,7 +1,7 @@
/* define( [
* draggable_events.js "jquery",
*/ "ui/draggable"
(function( $ ) { ], function( $ ) {
var element; var element;
@ -161,4 +161,4 @@ test( "position and offset in hash is consistent between start, drag, and stop",
deepEqual( dragOffset, stopOffset, "drag offset equals stop offset" ); deepEqual( dragOffset, stopOffset, "drag offset equals stop offset" );
}); });
})( jQuery ); } );

View File

@ -1,7 +1,8 @@
/* define( [
* draggable_methods.js "jquery",
*/ "./draggable_test_helpers",
(function( $ ) { "ui/draggable"
], function( $, draggableTestHelpers ) {
var element; var element;
@ -54,19 +55,19 @@ test( "enable", function() {
expect( 11 ); expect( 11 );
element.draggable({ disabled: true }); element.draggable({ disabled: true });
TestHelpers.draggable.shouldNotDrag( element, ".draggable({ disabled: true })" ); draggableTestHelpers.shouldNotDrag( element, ".draggable({ disabled: true })" );
element.draggable("enable"); element.draggable("enable");
TestHelpers.draggable.shouldMove( element, ".draggable('enable')" ); draggableTestHelpers.shouldMove( element, ".draggable('enable')" );
equal( element.draggable( "option", "disabled" ), false, "disabled option getter" ); equal( element.draggable( "option", "disabled" ), false, "disabled option getter" );
element.draggable("destroy"); element.draggable("destroy");
element.draggable({ disabled: true }); element.draggable({ disabled: true });
TestHelpers.draggable.shouldNotDrag( element, ".draggable({ disabled: true })" ); draggableTestHelpers.shouldNotDrag( element, ".draggable({ disabled: true })" );
element.draggable( "option", "disabled", false ); element.draggable( "option", "disabled", false );
equal(element.draggable( "option", "disabled" ), false, "disabled option setter" ); equal(element.draggable( "option", "disabled" ), false, "disabled option setter" );
TestHelpers.draggable.shouldMove( element, ".draggable('option', 'disabled', false)" ); draggableTestHelpers.shouldMove( element, ".draggable('option', 'disabled', false)" );
var expected = element.draggable(), var expected = element.draggable(),
actual = expected.draggable("enable"); actual = expected.draggable("enable");
@ -77,19 +78,19 @@ test( "disable", function( assert ) {
expect( 14 ); expect( 14 );
element = $( "#draggable2" ).draggable({ disabled: false }); element = $( "#draggable2" ).draggable({ disabled: false });
TestHelpers.draggable.shouldMove( element, ".draggable({ disabled: false })" ); draggableTestHelpers.shouldMove( element, ".draggable({ disabled: false })" );
element.draggable( "disable" ); element.draggable( "disable" );
TestHelpers.draggable.shouldNotDrag( element, ".draggable('disable')" ); draggableTestHelpers.shouldNotDrag( element, ".draggable('disable')" );
equal( element.draggable( "option", "disabled" ), true, "disabled option getter" ); equal( element.draggable( "option", "disabled" ), true, "disabled option getter" );
element.draggable( "destroy" ); element.draggable( "destroy" );
element.draggable({ disabled: false }); element.draggable({ disabled: false });
TestHelpers.draggable.shouldMove( element, ".draggable({ disabled: false })" ); draggableTestHelpers.shouldMove( element, ".draggable({ disabled: false })" );
element.draggable( "option", "disabled", true ); element.draggable( "option", "disabled", true );
equal( element.draggable( "option", "disabled" ), true, "disabled option setter" ); equal( element.draggable( "option", "disabled" ), true, "disabled option setter" );
TestHelpers.draggable.shouldNotDrag( element, ".draggable('option', 'disabled', true)" ); draggableTestHelpers.shouldNotDrag( element, ".draggable('option', 'disabled', true)" );
assert.lacksClasses( element.draggable( "widget" ), "ui-state-disabled" ); assert.lacksClasses( element.draggable( "widget" ), "ui-state-disabled" );
ok( !element.draggable( "widget" ).attr( "aria-disabled" ), "element does not get aria-disabled" ); ok( !element.draggable( "widget" ).attr( "aria-disabled" ), "element does not get aria-disabled" );
@ -100,4 +101,4 @@ test( "disable", function( assert ) {
equal( actual, expected, "disable is chainable" ); equal( actual, expected, "disable is chainable" );
}); });
})( jQuery ); } );

View File

@ -1,15 +1,19 @@
(function( $ ) { define( [
"jquery",
module( "draggable: options" ); "./draggable_test_helpers",
"ui/draggable",
"ui/droppable",
"ui/sortable"
], function( $, draggableTestHelpers ) {
// TODO: This doesn't actually test whether append happened, possibly remove // TODO: This doesn't actually test whether append happened, possibly remove
test( "{ appendTo: 'parent' }, default, no clone", function() { test( "{ appendTo: 'parent' }, default, no clone", function() {
expect( 4 ); expect( 4 );
var element = $( "#draggable2" ).draggable({ appendTo: "parent" }); var element = $( "#draggable2" ).draggable({ appendTo: "parent" });
TestHelpers.draggable.shouldMove( element, "absolute appendTo: parent" ); draggableTestHelpers.shouldMove( element, "absolute appendTo: parent" );
element = $( "#draggable1" ).draggable({ appendTo: "parent" }); element = $( "#draggable1" ).draggable({ appendTo: "parent" });
TestHelpers.draggable.shouldMove( element, "relative appendTo: parent" ); draggableTestHelpers.shouldMove( element, "relative appendTo: parent" );
}); });
// TODO: This doesn't actually test whether append happened, possibly remove // TODO: This doesn't actually test whether append happened, possibly remove
@ -17,20 +21,20 @@ test( "{ appendTo: Element }, no clone", function() {
expect( 4 ); expect( 4 );
var element = $( "#draggable2" ).draggable({ appendTo: $( "#draggable2" ).parent()[ 0 ] }); var element = $( "#draggable2" ).draggable({ appendTo: $( "#draggable2" ).parent()[ 0 ] });
TestHelpers.draggable.shouldMove( element, "absolute appendTo: Element" ); draggableTestHelpers.shouldMove( element, "absolute appendTo: Element" );
element = $( "#draggable1" ).draggable({ appendTo: $( "#draggable2" ).parent()[ 0 ] }); element = $( "#draggable1" ).draggable({ appendTo: $( "#draggable2" ).parent()[ 0 ] });
TestHelpers.draggable.shouldMove( element, "relative appendTo: Element" ); draggableTestHelpers.shouldMove( element, "relative appendTo: Element" );
}); });
// TODO: This doesn't actually test whether append happened, possibly remove // TODO: This doesn't actually test whether append happened, possibly remove
test( "{ appendTo: Selector }, no clone", function() { test( "{ appendTo: Selector }, no clone", function() {
expect( 4 ); expect( 4 );
var element = $( "#draggable2" ).draggable({ appendTo: "#main" }); var element = $( "#draggable2" ).draggable({ appendTo: "#main" });
TestHelpers.draggable.shouldMove( element, "absolute appendTo: Selector" ); draggableTestHelpers.shouldMove( element, "absolute appendTo: Selector" );
element = $( "#draggable1" ).draggable({ appendTo: "#main" }); element = $( "#draggable1" ).draggable({ appendTo: "#main" });
TestHelpers.draggable.shouldMove( element, "relative appendTo: Selector" ); draggableTestHelpers.shouldMove( element, "relative appendTo: Selector" );
}); });
test( "{ appendTo: 'parent' }, default", function() { test( "{ appendTo: 'parent' }, default", function() {
@ -38,11 +42,11 @@ test( "{ appendTo: 'parent' }, default", function() {
var element = $( "#draggable1" ).draggable(); var element = $( "#draggable1" ).draggable();
TestHelpers.draggable.trackAppendedParent( element ); draggableTestHelpers.trackAppendedParent( element );
equal( element.draggable( "option", "appendTo" ), "parent" ); equal( element.draggable( "option", "appendTo" ), "parent" );
TestHelpers.draggable.move( element, 1, 1 ); draggableTestHelpers.move( element, 1, 1 );
equal( element.data( "last_dragged_parent" ), $( "#main" )[ 0 ] ); equal( element.data( "last_dragged_parent" ), $( "#main" )[ 0 ] );
}); });
@ -52,9 +56,9 @@ test( "{ appendTo: Element }", function() {
var appendTo = $( "#draggable2" ).parent()[ 0 ], var appendTo = $( "#draggable2" ).parent()[ 0 ],
element = $( "#draggable1" ).draggable({ appendTo: appendTo }); element = $( "#draggable1" ).draggable({ appendTo: appendTo });
TestHelpers.draggable.trackAppendedParent( element ); draggableTestHelpers.trackAppendedParent( element );
TestHelpers.draggable.move( element, 1, 1 ); draggableTestHelpers.move( element, 1, 1 );
equal( element.data( "last_dragged_parent" ), appendTo ); equal( element.data( "last_dragged_parent" ), appendTo );
}); });
@ -64,9 +68,9 @@ test( "{ appendTo: jQuery }", function() {
var appendTo = $( "#draggable2" ).parent(), var appendTo = $( "#draggable2" ).parent(),
element = $( "#draggable1" ).draggable({ appendTo: appendTo }); element = $( "#draggable1" ).draggable({ appendTo: appendTo });
TestHelpers.draggable.trackAppendedParent( element ); draggableTestHelpers.trackAppendedParent( element );
TestHelpers.draggable.move( element, 1, 1 ); draggableTestHelpers.move( element, 1, 1 );
equal( element.data( "last_dragged_parent" ), appendTo[ 0 ] ); equal( element.data( "last_dragged_parent" ), appendTo[ 0 ] );
}); });
@ -76,9 +80,9 @@ test( "{ appendTo: Selector }", function() {
var appendTo = "#main", var appendTo = "#main",
element = $( "#draggable1" ).draggable({ appendTo: appendTo }); element = $( "#draggable1" ).draggable({ appendTo: appendTo });
TestHelpers.draggable.trackAppendedParent( element ); draggableTestHelpers.trackAppendedParent( element );
TestHelpers.draggable.move( element, 1, 1 ); draggableTestHelpers.move( element, 1, 1 );
equal( element.data( "last_dragged_parent" ), $(appendTo)[ 0 ] ); equal( element.data( "last_dragged_parent" ), $(appendTo)[ 0 ] );
}); });
@ -87,34 +91,34 @@ test( "appendTo, default, switching after initialization", function() {
var element = $( "#draggable1" ).draggable({ helper: "clone" }); var element = $( "#draggable1" ).draggable({ helper: "clone" });
TestHelpers.draggable.trackAppendedParent( element ); draggableTestHelpers.trackAppendedParent( element );
// Move and make sure element was appended to fixture // Move and make sure element was appended to fixture
TestHelpers.draggable.move( element, 1, 1 ); draggableTestHelpers.move( element, 1, 1 );
equal( element.data( "last_dragged_parent" ), $( "#main" )[ 0 ] ); equal( element.data( "last_dragged_parent" ), $( "#main" )[ 0 ] );
// Move and make sure element was appended to main // Move and make sure element was appended to main
element.draggable( "option", "appendTo", $( "#qunit-fixture" ) ); element.draggable( "option", "appendTo", $( "#qunit-fixture" ) );
TestHelpers.draggable.move( element, 2, 2 ); draggableTestHelpers.move( element, 2, 2 );
equal( element.data( "last_dragged_parent" ), $( "#qunit-fixture" )[ 0 ] ); equal( element.data( "last_dragged_parent" ), $( "#qunit-fixture" )[ 0 ] );
}); });
test( "{ axis: false }, default", function() { test( "{ axis: false }, default", function() {
expect( 2 ); expect( 2 );
var element = $( "#draggable2" ).draggable({ axis: false }); var element = $( "#draggable2" ).draggable({ axis: false });
TestHelpers.draggable.shouldMove( element, "axis: false" ); draggableTestHelpers.shouldMove( element, "axis: false" );
}); });
test( "{ axis: 'x' }", function() { test( "{ axis: 'x' }", function() {
expect( 2 ); expect( 2 );
var element = $( "#draggable2" ).draggable({ axis: "x" }); var element = $( "#draggable2" ).draggable({ axis: "x" });
TestHelpers.draggable.testDrag( element, element, 50, 50, 50, 0, "axis: x" ); draggableTestHelpers.testDrag( element, element, 50, 50, 50, 0, "axis: x" );
}); });
test( "{ axis: 'y' }", function() { test( "{ axis: 'y' }", function() {
expect( 2 ); expect( 2 );
var element = $( "#draggable2" ).draggable({ axis: "y" }); var element = $( "#draggable2" ).draggable({ axis: "y" });
TestHelpers.draggable.testDrag( element, element, 50, 50, 0, 50, "axis: y" ); draggableTestHelpers.testDrag( element, element, 50, 50, 0, 50, "axis: y" );
}); });
test( "{ axis: ? }, unexpected", function() { test( "{ axis: ? }, unexpected", function() {
@ -132,7 +136,7 @@ test( "{ axis: ? }, unexpected", function() {
$.each(unexpected, function(key, val) { $.each(unexpected, function(key, val) {
element = $( "#draggable2" ).draggable({ axis: val }); element = $( "#draggable2" ).draggable({ axis: val });
TestHelpers.draggable.shouldMove( element, "axis: " + key ); draggableTestHelpers.shouldMove( element, "axis: " + key );
element.draggable( "destroy" ); element.draggable( "destroy" );
}); });
}); });
@ -143,15 +147,15 @@ test( "axis, default, switching after initialization", function() {
var element = $( "#draggable1" ).draggable({ axis: false }); var element = $( "#draggable1" ).draggable({ axis: false });
// Any Direction // Any Direction
TestHelpers.draggable.shouldMove( element, "axis: default" ); draggableTestHelpers.shouldMove( element, "axis: default" );
// Only horizontal // Only horizontal
element.draggable( "option", "axis", "x" ); element.draggable( "option", "axis", "x" );
TestHelpers.draggable.testDrag( element, element, 50, 50, 50, 0, "axis: x as option" ); draggableTestHelpers.testDrag( element, element, 50, 50, 50, 0, "axis: x as option" );
// Vertical only // Vertical only
element.draggable( "option", "axis", "y" ); element.draggable( "option", "axis", "y" );
TestHelpers.draggable.testDrag( element, element, 50, 50, 0, 50, "axis: y as option" ); draggableTestHelpers.testDrag( element, element, 50, 50, 0, 50, "axis: y as option" );
}); });
@ -161,12 +165,12 @@ test( "{ cancel: 'input,textarea,button,select,option' }, default", function() {
$( "<div id='draggable-option-cancel-default'><input type='text'></div>" ).appendTo( "#qunit-fixture" ); $( "<div id='draggable-option-cancel-default'><input type='text'></div>" ).appendTo( "#qunit-fixture" );
var element = $( "#draggable-option-cancel-default" ).draggable({ cancel: "input,textarea,button,select,option" }); var element = $( "#draggable-option-cancel-default" ).draggable({ cancel: "input,textarea,button,select,option" });
TestHelpers.draggable.shouldMove( element, "cancel: default, element dragged" ); draggableTestHelpers.shouldMove( element, "cancel: default, element dragged" );
element.draggable( "destroy" ); element.draggable( "destroy" );
element = $( "#draggable-option-cancel-default" ).draggable({ cancel: "input,textarea,button,select,option" }); element = $( "#draggable-option-cancel-default" ).draggable({ cancel: "input,textarea,button,select,option" });
TestHelpers.draggable.shouldNotDrag( element, "cancel: default, input dragged", "#draggable-option-cancel-default input" ); draggableTestHelpers.shouldNotDrag( element, "cancel: default, input dragged", "#draggable-option-cancel-default input" );
element.draggable( "destroy" ); element.draggable( "destroy" );
}); });
@ -174,12 +178,12 @@ test( "{ cancel: 'span' }", function() {
expect( 4 ); expect( 4 );
var element = $( "#draggable2" ).draggable(); var element = $( "#draggable2" ).draggable();
TestHelpers.draggable.shouldMove( element, "cancel: default, span dragged", "#draggable2 span" ); draggableTestHelpers.shouldMove( element, "cancel: default, span dragged", "#draggable2 span" );
element.draggable( "destroy" ); element.draggable( "destroy" );
element = $( "#draggable2" ).draggable({ cancel: "span" }); element = $( "#draggable2" ).draggable({ cancel: "span" });
TestHelpers.draggable.shouldNotDrag( element, "cancel: span, span dragged", "#draggable2 span" ); draggableTestHelpers.shouldNotDrag( element, "cancel: span, span dragged", "#draggable2 span" );
}); });
test( "{ cancel: ? }, unexpected", function() { test( "{ cancel: ? }, unexpected", function() {
@ -197,7 +201,7 @@ test( "{ cancel: ? }, unexpected", function() {
$.each( unexpected, function( key, val ) { $.each( unexpected, function( key, val ) {
element = $( "#draggable2" ).draggable({ cancel: val }); element = $( "#draggable2" ).draggable({ cancel: val });
TestHelpers.draggable.shouldMove( element, "cancel: " + key ); draggableTestHelpers.shouldMove( element, "cancel: " + key );
element.draggable( "destroy" ); element.draggable( "destroy" );
}); });
}); });
@ -215,15 +219,15 @@ test( "{ cancel: Selectors }, matching parent selector", function() {
$( "#wrapping a" ).append( element ); $( "#wrapping a" ).append( element );
TestHelpers.draggable.shouldMove( element, "drag span child", "#draggable2 span" ); draggableTestHelpers.shouldMove( element, "drag span child", "#draggable2 span" );
TestHelpers.draggable.shouldNotDrag( $( "#draggable2 span a" ), "drag span a" ); draggableTestHelpers.shouldNotDrag( $( "#draggable2 span a" ), "drag span a" );
TestHelpers.draggable.shouldNotDrag( $( "#wrapping a" ), "drag wrapping a" ); draggableTestHelpers.shouldNotDrag( $( "#wrapping a" ), "drag wrapping a" );
$( "#draggable2" ).draggable( "option", "cancel", "span > a" ); $( "#draggable2" ).draggable( "option", "cancel", "span > a" );
$( "#draggable2" ).find( "a" ).append( "<a>" ); $( "#draggable2" ).find( "a" ).append( "<a>" );
TestHelpers.draggable.shouldMove( element, "drag span child", $( "#draggable2 span a" ).last() ); draggableTestHelpers.shouldMove( element, "drag span child", $( "#draggable2 span a" ).last() );
TestHelpers.draggable.shouldNotDrag( $( "#draggable2 span a" ).first(), "drag span a first child" ); draggableTestHelpers.shouldNotDrag( $( "#draggable2 span a" ).first(), "drag span a first child" );
}); });
*/ */
@ -235,13 +239,13 @@ test( "cancelement, default, switching after initialization", function() {
var input = $( "#draggable-option-cancel-default input" ), var input = $( "#draggable-option-cancel-default input" ),
element = $( "#draggable-option-cancel-default" ).draggable(); element = $( "#draggable-option-cancel-default" ).draggable();
TestHelpers.draggable.shouldNotDrag( element, "cancel: default, input dragged", input ); draggableTestHelpers.shouldNotDrag( element, "cancel: default, input dragged", input );
element.draggable( "option", "cancel", "textarea" ); element.draggable( "option", "cancel", "textarea" );
TestHelpers.draggable.shouldMove( element, "cancel: textarea, input dragged", input ); draggableTestHelpers.shouldMove( element, "cancel: textarea, input dragged", input );
element.draggable( "option", "cancel", "input" ); element.draggable( "option", "cancel", "input" );
TestHelpers.draggable.shouldNotDrag( element, "cancel: input, input dragged", input ); draggableTestHelpers.shouldNotDrag( element, "cancel: input, input dragged", input );
}); });
test( "connectToSortable, dragging out of a sortable", function() { test( "connectToSortable, dragging out of a sortable", function() {
@ -436,8 +440,8 @@ test( "{ containment: Element }", function() {
p = element.parent(), p = element.parent(),
po = p.offset(), po = p.offset(),
expected = { expected = {
left: po.left + TestHelpers.draggable.border( p, "left" ) + TestHelpers.draggable.margin( element, "left" ), left: po.left + draggableTestHelpers.border( p, "left" ) + draggableTestHelpers.margin( element, "left" ),
top: po.top + TestHelpers.draggable.border( p, "top" ) + TestHelpers.draggable.margin( element, "top" ) top: po.top + draggableTestHelpers.border( p, "top" ) + draggableTestHelpers.margin( element, "top" )
}; };
element.simulate( "drag", { element.simulate( "drag", {
@ -456,8 +460,8 @@ test( "{ containment: Selector }", function() {
p = element.parent(), p = element.parent(),
po = p.offset(), po = p.offset(),
expected = { expected = {
left: po.left + TestHelpers.draggable.border( p, "left" ) + TestHelpers.draggable.margin( element, "left" ), left: po.left + draggableTestHelpers.border( p, "left" ) + draggableTestHelpers.margin( element, "left" ),
top: po.top + TestHelpers.draggable.border( p, "top" ) + TestHelpers.draggable.margin( element, "top" ) top: po.top + draggableTestHelpers.border( p, "top" ) + draggableTestHelpers.margin( element, "top" )
}; };
element.simulate( "drag", { element.simulate( "drag", {
@ -476,7 +480,7 @@ test( "{ containment: [x1, y1, x2, y2] }", function() {
element.draggable( "option", "containment", [ eo.left, eo.top, eo.left + element.width() + 5, eo.top + element.height() + 5 ] ); element.draggable( "option", "containment", [ eo.left, eo.top, eo.left + element.width() + 5, eo.top + element.height() + 5 ] );
TestHelpers.draggable.testDrag( element, element, -100, -100, 0, 0, "containment: [x1, y1, x2, y2]" ); draggableTestHelpers.testDrag( element, element, -100, -100, 0, 0, "containment: [x1, y1, x2, y2]" );
}); });
test( "{ containment: 'parent' }, relative", function() { test( "{ containment: 'parent' }, relative", function() {
@ -487,8 +491,8 @@ test( "{ containment: 'parent' }, relative", function() {
p = element.parent(), p = element.parent(),
po = p.offset(), po = p.offset(),
expected = { expected = {
left: po.left + TestHelpers.draggable.border( p, "left" ) + TestHelpers.draggable.margin( element, "left" ), left: po.left + draggableTestHelpers.border( p, "left" ) + draggableTestHelpers.margin( element, "left" ),
top: po.top + TestHelpers.draggable.border( p, "top" ) + TestHelpers.draggable.margin( element, "top" ) top: po.top + draggableTestHelpers.border( p, "top" ) + draggableTestHelpers.margin( element, "top" )
}; };
element.simulate( "drag", { element.simulate( "drag", {
@ -507,8 +511,8 @@ test( "{ containment: 'parent' }, absolute", function() {
p = element.parent(), p = element.parent(),
po = p.offset(), po = p.offset(),
expected = { expected = {
left: po.left + TestHelpers.draggable.border( p, "left" ) + TestHelpers.draggable.margin( element, "left" ), left: po.left + draggableTestHelpers.border( p, "left" ) + draggableTestHelpers.margin( element, "left" ),
top: po.top + TestHelpers.draggable.border( p, "top" ) + TestHelpers.draggable.margin( element, "top" ) top: po.top + draggableTestHelpers.border( p, "top" ) + draggableTestHelpers.margin( element, "top" )
}; };
element.simulate( "drag", { element.simulate( "drag", {
@ -531,8 +535,8 @@ test( "containment, account for border", function( assert ) {
}), }),
parentBottom = parent.offset().top + parent.outerHeight(), parentBottom = parent.offset().top + parent.outerHeight(),
parentRight = parent.offset().left + parent.outerWidth(), parentRight = parent.offset().left + parent.outerWidth(),
parentBorderBottom = TestHelpers.draggable.border( parent, "bottom" ), parentBorderBottom = draggableTestHelpers.border( parent, "bottom" ),
parentBorderRight = TestHelpers.draggable.border( parent, "right" ); parentBorderRight = draggableTestHelpers.border( parent, "right" );
el.css({ el.css({
height: "5px", height: "5px",
@ -587,16 +591,16 @@ test( "containment, default, switching after initialization", function() {
po = element.parent().offset(), po = element.parent().offset(),
containment = [ po.left - 100, po.top - 100, po.left + 500, po.top + 500 ]; containment = [ po.left - 100, po.top - 100, po.left + 500, po.top + 500 ];
TestHelpers.draggable.testDrag( element, element, -100, -100, -100, -100, "containment: default" ); draggableTestHelpers.testDrag( element, element, -100, -100, -100, -100, "containment: default" );
element.draggable( "option", "containment", "parent" ).css({ top: 0, left: 0 }); element.draggable( "option", "containment", "parent" ).css({ top: 0, left: 0 });
TestHelpers.draggable.testDrag( element, element, -100, -100, 0, 0, "containment: parent as option" ); draggableTestHelpers.testDrag( element, element, -100, -100, 0, 0, "containment: parent as option" );
element.draggable( "option", "containment", containment ).css({ top: 0, left: 0 }); element.draggable( "option", "containment", containment ).css({ top: 0, left: 0 });
TestHelpers.draggable.testDrag( element, element, -100, -100, -100, -100, "containment: array as option" ); draggableTestHelpers.testDrag( element, element, -100, -100, -100, -100, "containment: array as option" );
element.draggable( "option", "containment", false ); element.draggable( "option", "containment", false );
TestHelpers.draggable.testDrag( element, element, -100, -100, -100, -100, "containment: false as option" ); draggableTestHelpers.testDrag( element, element, -100, -100, -100, -100, "containment: false as option" );
}); });
test( "{ cursor: 'auto' }, default", function() { test( "{ cursor: 'auto' }, default", function() {
@ -674,7 +678,7 @@ test( "#6889: Cursor doesn't revert to pre-dragging state after revert action wh
}), }),
expected = getCursor(); expected = getCursor();
if ( TestHelpers.draggable.unreliableContains ) { if ( draggableTestHelpers.unreliableContains ) {
ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" ); ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" );
ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" ); ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" );
} else { } else {
@ -690,17 +694,17 @@ test( "cursor, default, switching after initialization", function() {
var element = $( "#draggable1" ).draggable(); var element = $( "#draggable1" ).draggable();
TestHelpers.draggable.trackMouseCss( element ); draggableTestHelpers.trackMouseCss( element );
TestHelpers.draggable.move( element, 1, 1 ); draggableTestHelpers.move( element, 1, 1 );
equal( element.data( "last_dragged_cursor" ), "auto" ); equal( element.data( "last_dragged_cursor" ), "auto" );
element.draggable( "option", "cursor", "move" ); element.draggable( "option", "cursor", "move" );
TestHelpers.draggable.move( element, 1, 1 ); draggableTestHelpers.move( element, 1, 1 );
equal( element.data( "last_dragged_cursor" ), "move" ); equal( element.data( "last_dragged_cursor" ), "move" );
element.draggable( "option", "cursor", "ns-resize" ); element.draggable( "option", "cursor", "ns-resize" );
TestHelpers.draggable.move( element, 1, 1 ); draggableTestHelpers.move( element, 1, 1 );
equal( element.data( "last_dragged_cursor" ), "ns-resize" ); equal( element.data( "last_dragged_cursor" ), "ns-resize" );
}); });
@ -727,11 +731,11 @@ test( "cursorAt", function() {
equal( ui.position.left - ui.originalPosition.left, deltaX, testName + " " + position + " left" ); equal( ui.position.left - ui.originalPosition.left, deltaX, testName + " " + position + " left" );
equal( ui.position.top - ui.originalPosition.top, deltaY, testName + " " + position + " top" ); equal( ui.position.top - ui.originalPosition.top, deltaY, testName + " " + position + " top" );
} else if ( testData.cursorAt.right ) { } else if ( testData.cursorAt.right ) {
equal( ui.helper.width() - ( event.clientX - ui.offset.left ), testData.x - TestHelpers.draggable.unreliableOffset, testName + " " + position + " left" ); equal( ui.helper.width() - ( event.clientX - ui.offset.left ), testData.x - draggableTestHelpers.unreliableOffset, testName + " " + position + " left" );
equal( ui.helper.height() - ( event.clientY - ui.offset.top ), testData.y - TestHelpers.draggable.unreliableOffset, testName + " " + position + " top" ); equal( ui.helper.height() - ( event.clientY - ui.offset.top ), testData.y - draggableTestHelpers.unreliableOffset, testName + " " + position + " top" );
} else { } else {
equal( event.clientX - ui.offset.left, testData.x + TestHelpers.draggable.unreliableOffset, testName + " " + position + " left" ); equal( event.clientX - ui.offset.left, testData.x + draggableTestHelpers.unreliableOffset, testName + " " + position + " left" );
equal( event.clientY - ui.offset.top, testData.y + TestHelpers.draggable.unreliableOffset, testName + " " + position + " top" ); equal( event.clientY - ui.offset.top, testData.y + draggableTestHelpers.unreliableOffset, testName + " " + position + " top" );
} }
} }
}); });
@ -769,11 +773,11 @@ test( "cursorAt, switching after initialization", function() {
equal( ui.position.left - ui.originalPosition.left, deltaX, testName + " " + position + " left" ); equal( ui.position.left - ui.originalPosition.left, deltaX, testName + " " + position + " left" );
equal( ui.position.top - ui.originalPosition.top, deltaY, testName + " " + position + " top" ); equal( ui.position.top - ui.originalPosition.top, deltaY, testName + " " + position + " top" );
} else if ( testData.cursorAt.right ) { } else if ( testData.cursorAt.right ) {
equal( ui.helper.width() - ( event.clientX - ui.offset.left ), testData.x - TestHelpers.draggable.unreliableOffset, testName + " " + position + " left" ); equal( ui.helper.width() - ( event.clientX - ui.offset.left ), testData.x - draggableTestHelpers.unreliableOffset, testName + " " + position + " left" );
equal( ui.helper.height() - ( event.clientY - ui.offset.top ), testData.y - TestHelpers.draggable.unreliableOffset, testName + " " + position + " top" ); equal( ui.helper.height() - ( event.clientY - ui.offset.top ), testData.y - draggableTestHelpers.unreliableOffset, testName + " " + position + " top" );
} else { } else {
equal( event.clientX - ui.offset.left, testData.x + TestHelpers.draggable.unreliableOffset, testName + " " + position + " left" ); equal( event.clientX - ui.offset.left, testData.x + draggableTestHelpers.unreliableOffset, testName + " " + position + " left" );
equal( event.clientY - ui.offset.top, testData.y + TestHelpers.draggable.unreliableOffset, testName + " " + position + " top" ); equal( event.clientY - ui.offset.top, testData.y + draggableTestHelpers.unreliableOffset, testName + " " + position + " top" );
} }
} }
}); });
@ -795,29 +799,29 @@ test( "disabled", function() {
var element = $( "#draggable1" ).draggable(); var element = $( "#draggable1" ).draggable();
TestHelpers.draggable.shouldMove( element, "disabled: default" ); draggableTestHelpers.shouldMove( element, "disabled: default" );
element.draggable( "option", "disabled", true ); element.draggable( "option", "disabled", true );
TestHelpers.draggable.shouldNotDrag( element, "option: disabled true" ); draggableTestHelpers.shouldNotDrag( element, "option: disabled true" );
element.draggable( "option", "disabled", false ); element.draggable( "option", "disabled", false );
TestHelpers.draggable.shouldMove( element, "option: disabled false" ); draggableTestHelpers.shouldMove( element, "option: disabled false" );
}); });
test( "{ grid: [50, 50] }, relative", function() { test( "{ grid: [50, 50] }, relative", function() {
expect( 4 ); expect( 4 );
var element = $( "#draggable1" ).draggable({ grid: [ 50, 50 ] }); var element = $( "#draggable1" ).draggable({ grid: [ 50, 50 ] });
TestHelpers.draggable.testDrag( element, element, 24, 24, 0, 0, "grid: [50, 50] relative" ); draggableTestHelpers.testDrag( element, element, 24, 24, 0, 0, "grid: [50, 50] relative" );
TestHelpers.draggable.testDrag( element, element, 26, 25, 50, 50, "grid: [50, 50] relative" ); draggableTestHelpers.testDrag( element, element, 26, 25, 50, 50, "grid: [50, 50] relative" );
}); });
test( "{ grid: [50, 50] }, absolute", function() { test( "{ grid: [50, 50] }, absolute", function() {
expect( 4 ); expect( 4 );
var element = $( "#draggable2" ).draggable({ grid: [ 50, 50 ] }); var element = $( "#draggable2" ).draggable({ grid: [ 50, 50 ] });
TestHelpers.draggable.testDrag( element, element, 24, 24, 0, 0, "grid: [50, 50] absolute" ); draggableTestHelpers.testDrag( element, element, 24, 24, 0, 0, "grid: [50, 50] absolute" );
TestHelpers.draggable.testDrag( element, element, 26, 25, 50, 50, "grid: [50, 50] absolute" ); draggableTestHelpers.testDrag( element, element, 26, 25, 50, 50, "grid: [50, 50] absolute" );
}); });
test( "grid, switching after initialization", function() { test( "grid, switching after initialization", function() {
@ -826,13 +830,13 @@ test( "grid, switching after initialization", function() {
var element = $( "#draggable1" ).draggable(); var element = $( "#draggable1" ).draggable();
// Forward // Forward
TestHelpers.draggable.testDrag( element, element, 24, 24, 24, 24, "grid: default" ); draggableTestHelpers.testDrag( element, element, 24, 24, 24, 24, "grid: default" );
TestHelpers.draggable.testDrag( element, element, 0, 0, 0, 0, "grid: default" ); draggableTestHelpers.testDrag( element, element, 0, 0, 0, 0, "grid: default" );
element.draggable( "option", "grid", [ 50, 50 ] ); element.draggable( "option", "grid", [ 50, 50 ] );
TestHelpers.draggable.testDrag( element, element, 24, 24, 0, 0, "grid: [50, 50] as option" ); draggableTestHelpers.testDrag( element, element, 24, 24, 0, 0, "grid: [50, 50] as option" );
TestHelpers.draggable.testDrag( element, element, 26, 25, 50, 50, "grid: [50, 50] as option" ); draggableTestHelpers.testDrag( element, element, 26, 25, 50, 50, "grid: [50, 50] as option" );
}); });
test( "{ handle: 'span' }", function() { test( "{ handle: 'span' }", function() {
@ -840,9 +844,9 @@ test( "{ handle: 'span' }", function() {
var element = $( "#draggable2" ).draggable({ handle: "span" }); var element = $( "#draggable2" ).draggable({ handle: "span" });
TestHelpers.draggable.shouldMove( element, "handle: span", "#draggable2 span"); draggableTestHelpers.shouldMove( element, "handle: span", "#draggable2 span");
TestHelpers.draggable.shouldMove( element, "handle: span child", "#draggable2 span em" ); draggableTestHelpers.shouldMove( element, "handle: span child", "#draggable2 span em" );
TestHelpers.draggable.shouldNotDrag( element, "handle: span element" ); draggableTestHelpers.shouldNotDrag( element, "handle: span element" );
}); });
test( "handle, default, switching after initialization", function() { test( "handle, default, switching after initialization", function() {
@ -850,31 +854,31 @@ test( "handle, default, switching after initialization", function() {
var element = $( "#draggable2" ).draggable(); var element = $( "#draggable2" ).draggable();
TestHelpers.draggable.shouldMove( element, "handle: default, element dragged" ); draggableTestHelpers.shouldMove( element, "handle: default, element dragged" );
TestHelpers.draggable.shouldMove( element, "handle: default, span dragged", "#draggable2 span" ); draggableTestHelpers.shouldMove( element, "handle: default, span dragged", "#draggable2 span" );
// Switch // Switch
element.draggable( "option", "handle", "span" ); element.draggable( "option", "handle", "span" );
TestHelpers.draggable.shouldNotDrag( element, "handle: span as option, element dragged" ); draggableTestHelpers.shouldNotDrag( element, "handle: span as option, element dragged" );
TestHelpers.draggable.shouldMove( element, "handle: span as option, span dragged", "#draggable2 span" ); draggableTestHelpers.shouldMove( element, "handle: span as option, span dragged", "#draggable2 span" );
// And back // And back
element.draggable( "option", "handle", false ); element.draggable( "option", "handle", false );
TestHelpers.draggable.shouldMove( element, "handle: false as option, element dragged" ); draggableTestHelpers.shouldMove( element, "handle: false as option, element dragged" );
TestHelpers.draggable.shouldMove( element, "handle: false as option, span dragged", "#draggable2 span" ); draggableTestHelpers.shouldMove( element, "handle: false as option, span dragged", "#draggable2 span" );
}); });
test( "helper, default, switching after initialization", function() { test( "helper, default, switching after initialization", function() {
expect( 6 ); expect( 6 );
var element = $( "#draggable1" ).draggable(); var element = $( "#draggable1" ).draggable();
TestHelpers.draggable.shouldMove( element, "helper: default" ); draggableTestHelpers.shouldMove( element, "helper: default" );
element.draggable( "option", "helper", "clone" ); element.draggable( "option", "helper", "clone" );
TestHelpers.draggable.shouldMove( element, "helper: clone" ); draggableTestHelpers.shouldMove( element, "helper: clone" );
element.draggable( "option", "helper", "original" ); element.draggable( "option", "helper", "original" );
TestHelpers.draggable.shouldMove( element, "helper: original" ); draggableTestHelpers.shouldMove( element, "helper: original" );
}); });
// http://bugs.jqueryui.com/ticket/9446 // http://bugs.jqueryui.com/ticket/9446
@ -888,7 +892,7 @@ test( "helper, function returning original element", function() {
} }
}); });
TestHelpers.draggable.testDragHelperOffset( element, 100, 100, 100, 100, "original element is draggable" ); draggableTestHelpers.testDragHelperOffset( element, 100, 100, 100, 100, "original element is draggable" );
element.simulate( "drag", { element.simulate( "drag", {
dx: 100, dx: 100,
@ -907,25 +911,25 @@ function testHelperPosition( scrollPositions, position, helper, scrollElements,
}); });
if ( scrollElements.length === 1 && scrollElements[ 0 ] === "#scrollParent" ) { if ( scrollElements.length === 1 && scrollElements[ 0 ] === "#scrollParent" ) {
TestHelpers.draggable.setScrollable( "#main", false ); draggableTestHelpers.setScrollable( "#main", false );
TestHelpers.draggable.setScrollable( "#scrollParent", true ); draggableTestHelpers.setScrollable( "#scrollParent", true );
} }
for ( j = 0; j < scrollPositions.length; j++ ) { for ( j = 0; j < scrollPositions.length; j++ ) {
for ( i = 0; i < scrollElements.length; i++ ) { for ( i = 0; i < scrollElements.length; i++ ) {
TestHelpers.draggable.setScroll( scrollElements[ i ] ); draggableTestHelpers.setScroll( scrollElements[ i ] );
} }
TestHelpers.draggable.testScroll( element, scrollPositions[ j ] ); draggableTestHelpers.testScroll( element, scrollPositions[ j ] );
for ( i = 0; i < scrollElements.length; i++ ) { for ( i = 0; i < scrollElements.length; i++ ) {
TestHelpers.draggable.restoreScroll( scrollElements[ i ] ); draggableTestHelpers.restoreScroll( scrollElements[ i ] );
} }
} }
if ( scrollElements.length === 1 && scrollElements[ 1 ] === "#scrollParent" ) { if ( scrollElements.length === 1 && scrollElements[ 1 ] === "#scrollParent" ) {
TestHelpers.draggable.setScrollable( "#main", true ); draggableTestHelpers.setScrollable( "#main", true );
TestHelpers.draggable.setScrollable( "#scrollParent", false ); draggableTestHelpers.setScrollable( "#scrollParent", false );
} }
}); });
} }
@ -983,15 +987,15 @@ test( "opacity, default, switching after initialization", function() {
} }
}); });
TestHelpers.draggable.move( element, 1, 1 ); draggableTestHelpers.move( element, 1, 1 );
equal( opacity, 1 ); equal( opacity, 1 );
element.draggable( "option", "opacity", 0.5 ); element.draggable( "option", "opacity", 0.5 );
TestHelpers.draggable.move( element, 2, 1 ); draggableTestHelpers.move( element, 2, 1 );
equal( opacity, 0.5 ); equal( opacity, 0.5 );
element.draggable( "option", "opacity", false ); element.draggable( "option", "opacity", false );
TestHelpers.draggable.move( element, 3, 1 ); draggableTestHelpers.move( element, 3, 1 );
equal( opacity, 1 ); equal( opacity, 1 );
}); });
@ -1002,13 +1006,13 @@ asyncTest( "revert and revertDuration", function() {
revert: true, revert: true,
revertDuration: 0 revertDuration: 0
}); });
TestHelpers.draggable.shouldMovePositionButNotOffset( element, "revert: true, revertDuration: 0 should revert immediately" ); draggableTestHelpers.shouldMovePositionButNotOffset( element, "revert: true, revertDuration: 0 should revert immediately" );
$( "#draggable2" ).draggable( "option", "revert", "invalid" ); $( "#draggable2" ).draggable( "option", "revert", "invalid" );
TestHelpers.draggable.shouldMovePositionButNotOffset( element, "revert: invalid, revertDuration: 0 should revert immediately" ); draggableTestHelpers.shouldMovePositionButNotOffset( element, "revert: invalid, revertDuration: 0 should revert immediately" );
$( "#draggable2" ).draggable( "option", "revert", false ); $( "#draggable2" ).draggable( "option", "revert", false );
TestHelpers.draggable.shouldMove( element, "revert: false should allow movement" ); draggableTestHelpers.shouldMove( element, "revert: false should allow movement" );
$( "#draggable2" ).draggable( "option", { $( "#draggable2" ).draggable( "option", {
revert: true, revert: true,
@ -1019,7 +1023,7 @@ asyncTest( "revert and revertDuration", function() {
}); });
// animation are async, so test for it asynchronously // animation are async, so test for it asynchronously
TestHelpers.draggable.move( element, 50, 50 ); draggableTestHelpers.move( element, 50, 50 );
setTimeout( function() { setTimeout( function() {
ok( $( "#draggable2" ).is( ":animated" ), "revert: true with revertDuration should animate" ); ok( $( "#draggable2" ).is( ":animated" ), "revert: true with revertDuration should animate" );
}); });
@ -1035,7 +1039,7 @@ test( "revert: valid", function() {
$( "#droppable" ).droppable(); $( "#droppable" ).droppable();
TestHelpers.draggable.shouldMovePositionButNotOffset( element, "revert: valid reverts when dropped on a droppable" ); draggableTestHelpers.shouldMovePositionButNotOffset( element, "revert: valid reverts when dropped on a droppable" );
}); });
test( "scope", function() { test( "scope", function() {
@ -1049,17 +1053,17 @@ test( "scope", function() {
$( "#droppable" ).droppable({ scope: "tasks" }); $( "#droppable" ).droppable({ scope: "tasks" });
TestHelpers.draggable.shouldMovePositionButNotOffset( element, "revert: valid reverts when dropped on a droppable in scope" ); draggableTestHelpers.shouldMovePositionButNotOffset( element, "revert: valid reverts when dropped on a droppable in scope" );
$( "#droppable" ).droppable( "destroy" ).droppable({ scope: "nottasks" }); $( "#droppable" ).droppable( "destroy" ).droppable({ scope: "nottasks" });
TestHelpers.draggable.shouldMove( element, "revert: valid reverts when dropped on a droppable out of scope" ); draggableTestHelpers.shouldMove( element, "revert: valid reverts when dropped on a droppable out of scope" );
}); });
test( "scroll, scrollSensitivity, and scrollSpeed", function() { test( "scroll, scrollSensitivity, and scrollSpeed", function() {
expect( 2 ); expect( 2 );
TestHelpers.draggable.setScrollable( "#main", false ); draggableTestHelpers.setScrollable( "#main", false );
var currentScrollTop, var currentScrollTop,
viewportHeight = $( window ).height(), viewportHeight = $( window ).height(),
@ -1101,7 +1105,7 @@ test( "scroll, scrollSensitivity, and scrollSpeed", function() {
moves: 1 moves: 1
}); });
TestHelpers.draggable.restoreScroll( document ); draggableTestHelpers.restoreScroll( document );
}); });
test( "scroll ignores containers that are overflow: hidden", function() { test( "scroll ignores containers that are overflow: hidden", function() {
@ -1140,7 +1144,7 @@ test( "scroll ignores containers that are overflow: hidden", function() {
test( "#6817: auto scroll goes double distance when dragging", function( assert ) { test( "#6817: auto scroll goes double distance when dragging", function( assert ) {
expect( 2 ); expect( 2 );
TestHelpers.draggable.restoreScroll( document ); draggableTestHelpers.restoreScroll( document );
var offsetBefore, var offsetBefore,
distance = 10, distance = 10,
@ -1171,7 +1175,7 @@ test( "#6817: auto scroll goes double distance when dragging", function( assert
moves: 1 moves: 1
}); });
TestHelpers.draggable.restoreScroll( document ); draggableTestHelpers.restoreScroll( document );
}); });
test( "snap, snapMode, and snapTolerance", function( assert ) { test( "snap, snapMode, and snapTolerance", function( assert ) {
@ -1333,7 +1337,7 @@ test( "#8459: element can snap to an element that was removed during drag", func
}); });
// Support: Opera 12.10, Safari 5.1, jQuery <1.8 // Support: Opera 12.10, Safari 5.1, jQuery <1.8
if ( TestHelpers.draggable.unreliableContains ) { if ( draggableTestHelpers.unreliableContains ) {
ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" ); ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" );
ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" ); ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" );
} else { } else {
@ -1390,10 +1394,10 @@ test( "stack", function() {
stack: "#draggable1, #draggable2" stack: "#draggable1, #draggable2"
}); });
TestHelpers.draggable.move( element, 1, 1 ); draggableTestHelpers.move( element, 1, 1 );
equal( element.css( "zIndex" ), "2", "stack increments zIndex correctly" ); equal( element.css( "zIndex" ), "2", "stack increments zIndex correctly" );
TestHelpers.draggable.move( element2, 1, 1 ); draggableTestHelpers.move( element2, 1, 1 );
equal( element2.css( "zIndex" ), "3", "stack increments zIndex correctly" ); equal( element2.css( "zIndex" ), "3", "stack increments zIndex correctly" );
}); });
@ -1431,15 +1435,15 @@ test( "zIndex, default, switching after initialization", function() {
element.css( "z-index", 1 ); element.css( "z-index", 1 );
TestHelpers.draggable.move( element, 1, 1 ); draggableTestHelpers.move( element, 1, 1 );
equal( zindex, 1 ); equal( zindex, 1 );
element.draggable( "option", "zIndex", 5 ); element.draggable( "option", "zIndex", 5 );
TestHelpers.draggable.move( element, 2, 1 ); draggableTestHelpers.move( element, 2, 1 );
equal( zindex, 5 ); equal( zindex, 5 );
element.draggable( "option", "zIndex", false ); element.draggable( "option", "zIndex", false );
TestHelpers.draggable.move( element, 3, 1 ); draggableTestHelpers.move( element, 3, 1 );
equal( zindex, 1 ); equal( zindex, 1 );
}); });
@ -1486,4 +1490,4 @@ test( "iframeFix", function() {
}); });
}); });
})( jQuery ); } );

View File

@ -1,4 +1,7 @@
TestHelpers.draggable = { define( function() {
var draggableTestHelpers = {
// TODO: remove the unreliable offset hacks // TODO: remove the unreliable offset hacks
unreliableOffset: $.ui.ie && ( !document.documentMode || document.documentMode < 8 ) ? 2 : 0, unreliableOffset: $.ui.ie && ( !document.documentMode || document.documentMode < 8 ) ? 2 : 0,
// Support: Opera 12.10, Safari 5.1, jQuery <1.8 // Support: Opera 12.10, Safari 5.1, jQuery <1.8
@ -35,8 +38,8 @@ TestHelpers.draggable = {
}); });
}, },
testDrag: function( el, handle, dx, dy, expectedDX, expectedDY, msg ) { testDrag: function( el, handle, dx, dy, expectedDX, expectedDY, msg ) {
TestHelpers.draggable.testDragPosition( el, dx, dy, expectedDX, expectedDY, msg ); draggableTestHelpers.testDragPosition( el, dx, dy, expectedDX, expectedDY, msg );
TestHelpers.draggable.testDragOffset( el, dx, dy, expectedDX, expectedDY, msg ); draggableTestHelpers.testDragOffset( el, dx, dy, expectedDX, expectedDY, msg );
$( handle ).simulate( "drag", { $( handle ).simulate( "drag", {
dx: dx, dx: dx,
@ -45,8 +48,8 @@ TestHelpers.draggable = {
}, },
shouldMovePositionButNotOffset: function( el, msg, handle ) { shouldMovePositionButNotOffset: function( el, msg, handle ) {
handle = handle || el; handle = handle || el;
TestHelpers.draggable.testDragPosition( el, 100, 100, 100, 100, msg ); draggableTestHelpers.testDragPosition( el, 100, 100, 100, 100, msg );
TestHelpers.draggable.testDragHelperOffset( el, 100, 100, 0, 0, msg ); draggableTestHelpers.testDragHelperOffset( el, 100, 100, 0, 0, msg );
$( handle ).simulate( "drag", { $( handle ).simulate( "drag", {
dx: 100, dx: 100,
@ -55,11 +58,11 @@ TestHelpers.draggable = {
}, },
shouldMove: function( el, msg, handle ) { shouldMove: function( el, msg, handle ) {
handle = handle || el; handle = handle || el;
TestHelpers.draggable.testDrag( el, handle, 100, 100, 100, 100, msg ); draggableTestHelpers.testDrag( el, handle, 100, 100, 100, 100, msg );
}, },
shouldNotMove: function( el, msg, handle ) { shouldNotMove: function( el, msg, handle ) {
handle = handle || el; handle = handle || el;
TestHelpers.draggable.testDrag( el, handle, 100, 100, 0, 0, msg ); draggableTestHelpers.testDrag( el, handle, 100, 100, 0, 0, msg );
}, },
shouldNotDrag: function( el, msg, handle ) { shouldNotDrag: function( el, msg, handle ) {
handle = handle || el; handle = handle || el;
@ -93,7 +96,7 @@ TestHelpers.draggable = {
testScroll: function( el, position ) { testScroll: function( el, position ) {
var oldPosition = $( "#main" ).css( "position" ); var oldPosition = $( "#main" ).css( "position" );
$( "#main" ).css({ position: position, top: "0px", left: "0px" }); $( "#main" ).css({ position: position, top: "0px", left: "0px" });
TestHelpers.draggable.shouldMove( el, position + " parent" ); draggableTestHelpers.shouldMove( el, position + " parent" );
$( "#main" ).css( "position", oldPosition ); $( "#main" ).css( "position", oldPosition );
}, },
restoreScroll: function( what ) { restoreScroll: function( what ) {
@ -129,3 +132,7 @@ TestHelpers.draggable = {
}); });
} }
}; };
return draggableTestHelpers;
} );