aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorFelix Nagel <info@felixnagel.com>2013-03-07 23:56:48 +0100
committerFelix Nagel <info@felixnagel.com>2013-03-07 23:56:48 +0100
commit0bf91a41c6ea0025cdb25b55ada0dde7b8fdc0ff (patch)
treeafdfd77c7bdc18baae90aed731c6c59c2af4e184 /tests
parent6acc6bdd7f2fcf56d02699683de6fbec62316294 (diff)
parent5b2da7c127aa1afd9852063b6e4701ec6607e941 (diff)
downloadjquery-ui-0bf91a41c6ea0025cdb25b55ada0dde7b8fdc0ff.tar.gz
jquery-ui-0bf91a41c6ea0025cdb25b55ada0dde7b8fdc0ff.zip
Merge branch 'master' into selectmenu
Diffstat (limited to 'tests')
-rw-r--r--tests/.jshintrc1
-rw-r--r--tests/jquery.simulate.js22
-rw-r--r--tests/unit/draggable/draggable.html22
-rw-r--r--tests/unit/draggable/draggable_common.js10
-rw-r--r--tests/unit/draggable/draggable_core.js69
-rw-r--r--tests/unit/draggable/draggable_events.js134
-rw-r--r--tests/unit/draggable/draggable_methods.js123
-rw-r--r--tests/unit/draggable/draggable_options.js1228
-rw-r--r--tests/unit/draggable/draggable_test_helpers.js26
-rw-r--r--tests/unit/sortable/sortable.html7
-rw-r--r--tests/unit/sortable/sortable_options.js21
11 files changed, 1144 insertions, 519 deletions
diff --git a/tests/.jshintrc b/tests/.jshintrc
index 7c79a5c04..c196d86ef 100644
--- a/tests/.jshintrc
+++ b/tests/.jshintrc
@@ -23,6 +23,7 @@
"Globalize",
"module",
"notEqual",
+ "notDeepEqual",
"notStrictEqual",
"ok",
"QUnit",
diff --git a/tests/jquery.simulate.js b/tests/jquery.simulate.js
index 0ae88c20f..6e2f3ba8e 100644
--- a/tests/jquery.simulate.js
+++ b/tests/jquery.simulate.js
@@ -277,18 +277,30 @@ function findCenter( elem ) {
};
}
+function findCorner( elem ) {
+ var offset,
+ document = $( elem.ownerDocument );
+ elem = $( elem );
+ offset = elem.offset();
+
+ return {
+ x: offset.left - document.scrollLeft(),
+ y: offset.top - document.scrollTop()
+ };
+}
+
$.extend( $.simulate.prototype, {
simulateDrag: function() {
var i = 0,
target = this.target,
options = this.options,
- center = findCenter( target ),
+ center = options.handle === "corner" ? findCorner( target ) : findCenter( target ),
x = Math.floor( center.x ),
y = Math.floor( center.y ),
- dx = options.dx || 0,
- dy = options.dy || 0,
- moves = options.moves || 3,
- coord = { clientX: x, clientY: y };
+ coord = { clientX: x, clientY: y },
+ dx = options.dx || ( options.x !== undefined ? options.x - x : 0 ),
+ dy = options.dy || ( options.y !== undefined ? options.y - y : 0 ),
+ moves = options.moves || 3;
this.simulateEvent( target, "mousedown", coord );
diff --git a/tests/unit/draggable/draggable.html b/tests/unit/draggable/draggable.html
index 50bed8caf..6380f3e85 100644
--- a/tests/unit/draggable/draggable.html
+++ b/tests/unit/draggable/draggable.html
@@ -6,12 +6,12 @@
<script src="../../jquery.js"></script>
<link rel="stylesheet" href="../../../external/qunit.css">
-
+
<style>
/* See #9077 */
#draggable3, #draggable4 { z-index: 100; }
</style>
-
+
<script src="../../../external/qunit.js"></script>
<script src="../../jquery.simulate.js"></script>
<script src="../testsuite.js"></script>
@@ -23,7 +23,8 @@
"ui/jquery.ui.widget.js",
"ui/jquery.ui.mouse.js",
"ui/jquery.ui.resizable.js",
- "ui/jquery.ui.draggable.js"
+ "ui/jquery.ui.draggable.js",
+ "ui/jquery.ui.droppable.js"
]
});
</script>
@@ -45,15 +46,12 @@
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">
-<div id="main"></div>
-
-<div id="draggable1" style="background: green; width: 200px; height: 100px;">Relative</div>
-<div id="draggable2" style="background: green; width: 200px; height: 100px; position: absolute; top: 10px; left: 10px;"><span>Absolute</span></div>
-<div style='width: 1px; height: 1000px;'></div>
-<div style="position: absolute; width: 1px; height: 2000px;"></div>
-<div id="draggable3"></div>
-<div id="draggable4"></div>
-
+ <div id="main"></div>
+ <div id="draggable1" style="background: green; width: 200px; height: 100px;">Relative</div>
+ <div id="draggable2" style="background: green; width: 200px; height: 100px; position: absolute; top: 10px; left: 10px;"><span>Absolute</span></div>
+ <div id="droppable" style="background: green; width: 200px; height: 100px; position: absolute; top: 110px; left: 110px;"><span>Absolute</span></div>
+ <div style="width: 1px; height: 1000px;"></div>
+ <div style="position: absolute; width: 1px; height: 2000px;"></div>
</div>
</body>
diff --git a/tests/unit/draggable/draggable_common.js b/tests/unit/draggable/draggable_common.js
index 7c6961af2..5abd09e49 100644
--- a/tests/unit/draggable/draggable_common.js
+++ b/tests/unit/draggable/draggable_common.js
@@ -1,6 +1,5 @@
TestHelpers.commonWidgetTests( "draggable", {
defaults: {
- addClasses: true,
appendTo: "parent",
axis: false,
cancel: "input,textarea,button,select,option",
@@ -8,13 +7,10 @@ TestHelpers.commonWidgetTests( "draggable", {
containment: false,
cursor: "auto",
cursorAt: false,
- delay: 0,
disabled: false,
- distance: 1,
grid: false,
handle: false,
helper: "original",
- iframeFix: false,
opacity: false,
refreshPositions: false,
revert: false,
@@ -29,6 +25,12 @@ TestHelpers.commonWidgetTests( "draggable", {
stack: false,
zIndex: false,
+ //todo: remove the following option checks when interactions are rewritten:
+ addClasses: true,
+ delay: 0,
+ distance: 1,
+ iframeFix: false,
+
// callbacks
create: null,
drag: null,
diff --git a/tests/unit/draggable/draggable_core.js b/tests/unit/draggable/draggable_core.js
index 00d914194..2090f2fd9 100644
--- a/tests/unit/draggable/draggable_core.js
+++ b/tests/unit/draggable/draggable_core.js
@@ -2,24 +2,40 @@
* draggable_core.js
*/
-(function($) {
+(function( $ ) {
-module("draggable");
+var relativeElement, absoluteElement;
-test("element types", function() {
- var typeNames = ("p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form" +
- ",table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr" +
- ",acronym,code,samp,kbd,var,img,hr" +
- ",input,button,label,select,iframe").split(",");
+module( "draggable: core", {
+ setup: function() {
+ relativeElement = $("<div style='width: 200px; height: 100px;'>Relative</div>").appendTo("#qunit-fixture");
+ absoluteElement = $("<div style='background: green; width: 200px; height: 100px; position: absolute; top: 10px; left: 10px;'><span>Absolute</span></div>").appendTo("#qunit-fixture");
+ },
+ teardown: function() {
+ relativeElement.remove();
+ absoluteElement.remove();
+ }
+});
+
+test( "element types", function() {
+ var typeNames = (
+ "p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form" +
+ ",table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr" +
+ ",acronym,code,samp,kbd,var,img,hr" +
+ ",input,button,label,select,iframe"
+ ).split(",");
expect( typeNames.length * 2 );
- $.each(typeNames, function(i) {
+ $.each( typeNames, function( i ) {
var offsetBefore, offsetAfter,
- typeName = typeNames[i],
- el = $(document.createElement(typeName)).appendTo("#qunit-fixture");
+ typeName = typeNames[ i ],
+ el = $( document.createElement( typeName ) ).appendTo("#qunit-fixture");
+
+ if ( typeName === "table" ) {
+ el.append("<tr><td>content</td></tr>");
+ }
- (typeName === "table" && el.append("<tr><td>content</td></tr>"));
el.draggable({ cancel: "" });
offsetBefore = el.offset();
el.simulate( "drag", {
@@ -27,39 +43,38 @@ test("element types", function() {
dy: 50
});
offsetAfter = el.offset();
- // there are some rounding errors in FF, Chrome, and IE9, so we can't say equal, we have to settle for close enough
- closeEnough(offsetBefore.left, offsetAfter.left - 50, 1, "dragged[50, 50] " + "<" + typeName + ">");
- closeEnough(offsetBefore.top, offsetAfter.top - 50, 1, "dragged[50, 50] " + "<" + typeName + ">");
+
+ // Support: FF, Chrome, and IE9,
+ // there are some rounding errors in so we can't say equal, we have to settle for close enough
+ closeEnough( offsetBefore.left, offsetAfter.left - 50, 1, "dragged[50, 50] " + "<" + typeName + ">" );
+ closeEnough( offsetBefore.top, offsetAfter.top - 50, 1, "dragged[50, 50] " + "<" + typeName + ">" );
el.draggable("destroy");
el.remove();
});
});
-test("No options, relative", function() {
+test( "No options, relative", function() {
expect( 1 );
- var el = $("#draggable1").draggable();
- TestHelpers.draggable.shouldMove(el);
+ TestHelpers.draggable.shouldMove( relativeElement.draggable() );
});
-test("No options, absolute", function() {
+test( "No options, absolute", function() {
expect( 1 );
- var el = $("#draggable2").draggable();
- TestHelpers.draggable.shouldMove(el);
+ TestHelpers.draggable.shouldMove( absoluteElement.draggable() );
});
-test("resizable handle with complex markup (#8756 / #8757)", function() {
+test( "resizable handle with complex markup (#8756 / #8757)", function() {
expect( 2 );
- $("#draggable1")
+ relativeElement
.append(
$("<div>")
- .addClass("ui-resizable-handle")
- .addClass("ui-resizable-w")
- .append($("<div>"))
+ .addClass("ui-resizable-handle ui-resizable-w")
+ .append( $("<div>") )
);
var handle = $(".ui-resizable-w div"),
- target = $("#draggable1").draggable().resizable({ handles: "all" });
+ target = relativeElement.draggable().resizable({ handles: "all" });
// todo: fix resizable so it doesn't require a mouseover
handle.simulate("mouseover").simulate( "drag", { dx: -50 } );
@@ -70,4 +85,4 @@ test("resizable handle with complex markup (#8756 / #8757)", function() {
equal( target.width(), 200, "compare width" );
});
-})(jQuery);
+})( jQuery );
diff --git a/tests/unit/draggable/draggable_events.js b/tests/unit/draggable/draggable_events.js
index f4ab3a8ea..199561be3 100644
--- a/tests/unit/draggable/draggable_events.js
+++ b/tests/unit/draggable/draggable_events.js
@@ -1,99 +1,125 @@
/*
* draggable_events.js
*/
-(function($) {
+(function( $ ) {
-module("draggable: events");
+var element;
-test("callbacks occurrence count", function() {
+module( "draggable: events", {
+ setup: function() {
+ element = $("<div>").appendTo("#qunit-fixture");
+ },
+ teardown: function() {
+ element.draggable("destroy");
+ }
+});
- expect(3);
+test( "callbacks occurrence count", function() {
+ expect( 3 );
var start = 0,
stop = 0,
- dragc = 0,
- el = $("#draggable2").draggable({
- start: function() { start++; },
- drag: function() { dragc++; },
- stop: function() { stop++; }
- });
-
- el.simulate( "drag", {
+ dragc = 0;
+
+ element.draggable({
+ start: function() {
+ start++;
+ },
+ drag: function() {
+ dragc++;
+ },
+ stop: function() {
+ stop++;
+ }
+ });
+
+ element.simulate( "drag", {
dx: 10,
dy: 10
});
- equal(start, 1, "start callback should happen exactly once");
- equal(dragc, 3, "drag callback should happen exactly once per mousemove");
- equal(stop, 1, "stop callback should happen exactly once");
-
+ equal( start, 1, "start callback should happen exactly once" );
+ equal( dragc, 3, "drag callback should happen exactly once per mousemove" );
+ equal( stop, 1, "stop callback should happen exactly once" );
});
-test("stopping the start callback", function() {
-
- expect(3);
+test( "stopping the start callback", function() {
+ expect( 3 );
var start = 0,
stop = 0,
- dragc = 0,
- el = $("#draggable2").draggable({
- start: function() { start++; return false; },
- drag: function() { dragc++; },
- stop: function() { stop++; }
- });
-
- el.simulate( "drag", {
+ dragc = 0;
+
+ element.draggable({
+ start: function() {
+ start++;
+ return false;
+ },
+ drag: function() {
+ dragc++;
+ },
+ stop: function() {
+ stop++;
+ }
+ });
+
+ element.simulate( "drag", {
dx: 10,
dy: 10
});
- equal(start, 1, "start callback should happen exactly once");
- equal(dragc, 0, "drag callback should not happen at all");
- equal(stop, 0, "stop callback should not happen if there wasnt even a start");
-
+ equal( start, 1, "start callback should happen exactly once" );
+ equal( dragc, 0, "drag callback should not happen at all" );
+ equal( stop, 0, "stop callback should not happen if there wasnt even a start" );
});
-test("stopping the drag callback", function() {
-
- expect(3);
+test( "stopping the drag callback", function() {
+ expect( 2 );
var start = 0,
stop = 0,
- dragc = 0,
- el = $("#draggable2").draggable({
- start: function() { start++;},
- drag: function() { dragc++; return false; },
- stop: function() { stop++; }
- });
-
- el.simulate( "drag", {
+ dragc = 0;
+
+ element.draggable({
+ start: function() {
+ start++;
+ },
+ drag: function() {
+ dragc++;
+ return false;
+ },
+ stop: function() {
+ stop++;
+ }
+ });
+
+ element.simulate( "drag", {
dx: 10,
dy: 10
});
- equal(start, 1, "start callback should happen exactly once");
- equal(dragc, 1, "drag callback should happen exactly once");
- equal(stop, 1, "stop callback should happen, as we need to actively stop the drag");
-
+ equal( start, 1, "start callback should happen exactly once" );
+ equal( stop, 1, "stop callback should happen, as we need to actively stop the drag" );
});
-test("stopping the stop callback", function() {
-
- expect(1);
+test( "stopping the stop callback", function() {
+ expect( 1 );
- var el = $("#draggable2").draggable({
+ element.draggable({
helper: "clone",
- stop: function() { return false; }
+ stop: function() {
+ return false;
+ }
});
- el.simulate( "drag", {
+ element.simulate( "drag", {
dx: 10,
dy: 10
});
- ok($("#draggable2").data("ui-draggable").helper, "the clone should not be deleted if the stop callback is stopped");
+ ok( element.data("ui-draggable").helper, "the clone should not be deleted if the stop callback is stopped" );
});
-})(jQuery);
+})( jQuery );
diff --git a/tests/unit/draggable/draggable_methods.js b/tests/unit/draggable/draggable_methods.js
index 43db285ce..901c261d6 100644
--- a/tests/unit/draggable/draggable_methods.js
+++ b/tests/unit/draggable/draggable_methods.js
@@ -1,94 +1,99 @@
/*
* draggable_methods.js
*/
-(function($) {
+(function( $ ) {
-module("draggable: methods");
+var element;
-test("init", function() {
- expect(5);
+module( "draggable: methods", {
+ setup: function() {
+ element = $("<div style='background: green; width: 200px; height: 100px; position: absolute; top: 10px; left: 10px;'><span>Absolute</span></div>").appendTo("#qunit-fixture");
+ },
+ teardown: function() {
+ element.remove();
+ }
+});
+
+test( "init", function() {
+ expect( 5 );
- $("<div></div>").appendTo("body").draggable().remove();
- ok(true, ".draggable() called on element");
+ element.draggable();
+ ok( true, ".draggable() called on element" );
$([]).draggable();
- ok(true, ".draggable() called on empty collection");
+ ok( true, ".draggable() called on empty collection" );
$("<div></div>").draggable();
- ok(true, ".draggable() called on disconnected DOMElement");
+ ok( true, ".draggable() called on disconnected DOMElement" );
- $("<div></div>").draggable().draggable("option", "foo");
- ok(true, "arbitrary option getter after init");
+ element.draggable( "option", "foo" );
+ ok( true, "arbitrary option getter after init" );
- $("<div></div>").draggable().draggable("option", "foo", "bar");
- ok(true, "arbitrary option setter after init");
+ element.draggable( "option", "foo", "bar" );
+ ok( true, "arbitrary option setter after init" );
});
-test("destroy", function() {
- expect(4);
- $("<div></div>").appendTo("body").draggable().draggable("destroy").remove();
- ok(true, ".draggable('destroy') called on element");
+test( "destroy", function() {
+ expect( 4 );
+
+ element.draggable().draggable("destroy");
+ ok( true, ".draggable('destroy') called on element" );
$([]).draggable().draggable("destroy");
- ok(true, ".draggable('destroy') called on empty collection");
+ ok( true, ".draggable('destroy') called on empty collection" );
- $("<div></div>").draggable().draggable("destroy");
- ok(true, ".draggable('destroy') called on disconnected DOMElement");
+ element.draggable().draggable("destroy");
+ ok( true, ".draggable('destroy') called on disconnected DOMElement" );
- var expected = $("<div></div>").draggable(),
+ var expected = element.draggable(),
actual = expected.draggable("destroy");
- equal(actual, expected, "destroy is chainable");
+ equal( actual, expected, "destroy is chainable" );
});
-test("enable", function() {
- expect(7);
+test( "enable", function() {
+ expect( 7 );
- var expected, actual, el;
+ element.draggable({ disabled: true });
+ TestHelpers.draggable.shouldNotMove( element, ".draggable({ disabled: true })" );
- el = $("#draggable2").draggable({ disabled: true });
- TestHelpers.draggable.shouldNotMove(el, ".draggable({ disabled: true })");
+ element.draggable("enable");
+ TestHelpers.draggable.shouldMove( element, ".draggable('enable')" );
+ equal( element.draggable( "option", "disabled" ), false, "disabled option getter" );
- el.draggable("enable");
- TestHelpers.draggable.shouldMove(el, ".draggable('enable')");
- equal(el.draggable("option", "disabled"), false, "disabled option getter");
+ element.draggable("destroy");
+ element.draggable({ disabled: true });
+ TestHelpers.draggable.shouldNotMove( element, ".draggable({ disabled: true })" );
- el.draggable("destroy");
- el.draggable({ disabled: true });
- TestHelpers.draggable.shouldNotMove(el, ".draggable({ disabled: true })");
+ element.draggable( "option", "disabled", false );
+ equal(element.draggable( "option", "disabled" ), false, "disabled option setter" );
+ TestHelpers.draggable.shouldMove( element, ".draggable('option', 'disabled', false)" );
- el.draggable("option", "disabled", false);
- equal(el.draggable("option", "disabled"), false, "disabled option setter");
- TestHelpers.draggable.shouldMove(el, ".draggable('option', 'disabled', false)");
-
- expected = $("<div></div>").draggable(),
- actual = expected.draggable("enable");
- equal(actual, expected, "enable is chainable");
+ var expected = element.draggable(),
+ actual = expected.draggable("enable");
+ equal( actual, expected, "enable is chainable" );
});
-test("disable", function() {
- expect(7);
-
- var expected, actual, el;
-
- el = $("#draggable2").draggable({ disabled: false });
- TestHelpers.draggable.shouldMove(el, ".draggable({ disabled: false })");
+test( "disable", function() {
+ expect( 7 );
- el.draggable("disable");
- TestHelpers.draggable.shouldNotMove(el, ".draggable('disable')");
- equal(el.draggable("option", "disabled"), true, "disabled option getter");
+ element = $("#draggable2").draggable({ disabled: false });
+ TestHelpers.draggable.shouldMove( element, ".draggable({ disabled: false })" );
- el.draggable("destroy");
+ element.draggable("disable");
+ TestHelpers.draggable.shouldNotMove( element, ".draggable('disable')" );
+ equal( element.draggable( "option", "disabled" ), true, "disabled option getter" );
- el.draggable({ disabled: false });
- TestHelpers.draggable.shouldMove(el, ".draggable({ disabled: false })");
+ element.draggable("destroy");
+ element.draggable({ disabled: false });
+ TestHelpers.draggable.shouldMove( element, ".draggable({ disabled: false })" );
- el.draggable("option", "disabled", true);
- equal(el.draggable("option", "disabled"), true, "disabled option setter");
- TestHelpers.draggable.shouldNotMove(el, ".draggable('option', 'disabled', true)");
+ element.draggable( "option", "disabled", true );
+ equal( element.draggable( "option", "disabled" ), true, "disabled option setter" );
+ TestHelpers.draggable.shouldNotMove( element, ".draggable('option', 'disabled', true)" );
- expected = $("<div></div>").draggable(),
- actual = expected.draggable("disable");
- equal(actual, expected, "disable is chainable");
+ var expected = element.draggable(),
+ actual = expected.draggable("disable");
+ equal( actual, expected, "disable is chainable" );
});
-})(jQuery);
+})( jQuery );
diff --git a/tests/unit/draggable/draggable_options.js b/tests/unit/draggable/draggable_options.js
index 8496d6182..ccbe7224a 100644
--- a/tests/unit/draggable/draggable_options.js
+++ b/tests/unit/draggable/draggable_options.js
@@ -1,74 +1,124 @@
-/*
- * draggable_options.js
- */
-(function($) {
+(function( $ ) {
-module("draggable: options");
+module( "draggable: options" );
-test("{ addClasses: true }, default", function() {
- expect( 1 );
- var el = $("<div></div>").draggable({ addClasses: true });
- ok(el.is(".ui-draggable"), "'ui-draggable' class added");
+// TODO: This doesn't actually test whether append happened, possibly remove
+test( "{ appendTo: 'parent' }, default, no clone", function() {
+ expect( 2 );
+ var element = $( "#draggable2" ).draggable({ appendTo: "parent" });
+ TestHelpers.draggable.shouldMove( element );
- el.draggable("destroy");
+ element = $( "#draggable1" ).draggable({ appendTo: "parent" });
+ TestHelpers.draggable.shouldMove( element );
});
-test("{ addClasses: false }", function() {
- expect( 1 );
- var el = $("<div></div>").draggable({ addClasses: false });
- ok(!el.is(".ui-draggable"), "'ui-draggable' class not added");
+// TODO: This doesn't actually test whether append happened, possibly remove
+test( "{ appendTo: Element }, no clone", function() {
+ expect( 2 );
+ var element = $( "#draggable2" ).draggable({ appendTo: $( "#draggable2" ).parent()[ 0 ] });
+
+ TestHelpers.draggable.shouldMove( element );
- el.draggable("destroy");
+ element = $( "#draggable1" ).draggable({ appendTo: $( "#draggable2" ).parent()[ 0 ] });
+ TestHelpers.draggable.shouldMove( element );
});
-test("{ appendTo: 'parent' }, default", function() {
+// TODO: This doesn't actually test whether append happened, possibly remove
+test( "{ appendTo: Selector }, no clone", function() {
expect( 2 );
- var el = $("#draggable2").draggable({ appendTo: "parent" });
- TestHelpers.draggable.shouldMove(el);
-
- el = $("#draggable1").draggable({ appendTo: "parent" });
- TestHelpers.draggable.shouldMove(el);
+ var element = $( "#draggable2" ).draggable({ appendTo: "#main" });
+ TestHelpers.draggable.shouldMove( element );
+ element = $( "#draggable1" ).draggable({ appendTo: "#main" });
+ TestHelpers.draggable.shouldMove( element );
});
-test("{ appendTo: Element }", function() {
+test( "{ appendTo: 'parent' }, default", function() {
expect( 2 );
- var el = $("#draggable2").draggable({ appendTo: $("#draggable2").parent()[0] });
- TestHelpers.draggable.shouldMove(el);
- el = $("#draggable1").draggable({ appendTo: $("#draggable2").parent()[0] });
- TestHelpers.draggable.shouldMove(el);
+ var element = $( "#draggable1" ).draggable();
+
+ TestHelpers.draggable.trackAppendedParent( element );
+
+ equal( element.draggable( "option", "appendTo" ), "parent" );
+
+ TestHelpers.draggable.move( element, 1, 1 );
+ equal( element.data( "last_dragged_parent" ), $( "#qunit-fixture" )[ 0 ] );
+});
+
+test( "{ appendTo: Element }", function() {
+ expect( 1 );
+
+ var appendTo = $( "#draggable2" ).parent()[ 0 ],
+ element = $( "#draggable1" ).draggable({ appendTo: appendTo });
+
+ TestHelpers.draggable.trackAppendedParent( element );
+
+ TestHelpers.draggable.move( element, 1, 1 );
+ equal( element.data( "last_dragged_parent" ), appendTo );
+});
+
+test( "{ appendTo: jQuery }", function() {
+ expect( 1 );
+
+ var appendTo = $( "#draggable2" ).parent(),
+ element = $( "#draggable1" ).draggable({ appendTo: appendTo });
+
+ TestHelpers.draggable.trackAppendedParent( element );
+
+ TestHelpers.draggable.move( element, 1, 1 );
+ equal( element.data( "last_dragged_parent" ), appendTo[ 0 ] );
});
-test("{ appendTo: Selector }", function() {
+test( "{ appendTo: Selector }", function() {
+ expect( 1 );
+
+ var appendTo = "#main",
+ element = $( "#draggable1" ).draggable({ appendTo: appendTo });
+
+ TestHelpers.draggable.trackAppendedParent( element );
+
+ TestHelpers.draggable.move( element, 1, 1 );
+ equal( element.data( "last_dragged_parent" ), $(appendTo)[ 0 ] );
+});
+
+test( "appendTo, default, switching after initialization", function() {
expect( 2 );
- var el = $("#draggable2").draggable({ appendTo: "#main" });
- TestHelpers.draggable.shouldMove(el);
- el = $("#draggable1").draggable({ appendTo: "#main" });
- TestHelpers.draggable.shouldMove(el);
+ var element = $( "#draggable1" ).draggable({ helper : "clone" });
+
+ TestHelpers.draggable.trackAppendedParent( element );
+
+ // Move and make sure element was appended to fixture
+ TestHelpers.draggable.move( element, 1, 1 );
+ equal( element.data( "last_dragged_parent" ), $( "#qunit-fixture" )[ 0 ] );
+
+ // Move and make sure element was appended to main
+ element.draggable( "option", "appendTo", $( "#main" ) );
+ TestHelpers.draggable.move( element, 2, 2 );
+ equal( element.data( "last_dragged_parent" ), $( "#main" )[ 0 ] );
});
-test("{ axis: false }, default", function() {
+test( "{ axis: false }, default", function() {
expect( 1 );
- var el = $("#draggable2").draggable({ axis: false });
- TestHelpers.draggable.shouldMove(el);
+ var element = $( "#draggable2" ).draggable({ axis: false });
+ TestHelpers.draggable.shouldMove( element );
});
-test("{ axis: 'x' }", function() {
+test( "{ axis: 'x' }", function() {
expect( 1 );
- var el = $("#draggable2").draggable({ axis: "x" });
- TestHelpers.draggable.testDrag(el, el, 50, 50, 50, 0);
+ var element = $( "#draggable2" ).draggable({ axis: "x" });
+ TestHelpers.draggable.testDrag( element, element, 50, 50, 50, 0 );
});
-test("{ axis: 'y' }", function() {
+test( "{ axis: 'y' }", function() {
expect( 1 );
- var el = $("#draggable2").draggable({ axis: "y" });
- TestHelpers.draggable.testDrag(el, el, 50, 50, 0, 50);
+ var element = $( "#draggable2" ).draggable({ axis: "y" });
+ TestHelpers.draggable.testDrag( element, element, 50, 50, 0, 50 );
});
-test("{ axis: ? }, unexpected", function() {
- var el,
+test( "{ axis: ? }, unexpected", function() {
+ var element,
unexpected = {
"true": true,
"{}": {},
@@ -81,193 +131,313 @@ test("{ axis: ? }, unexpected", function() {
expect( 6 );
$.each(unexpected, function(key, val) {
- el = $("#draggable2").draggable({ axis: val });
- TestHelpers.draggable.testDrag(el, el, 50, 50, 50, 50, "axis: " + key);
- el.draggable("destroy");
+ element = $( "#draggable2" ).draggable({ axis: val });
+ TestHelpers.draggable.testDrag( element, element, 50, 50, 50, 50, "axis: " + key );
+ element.draggable( "destroy" );
});
});
-test("{ cancel: 'input,textarea,button,select,option' }, default", function() {
+test( "axis, default, switching after initialization", function() {
+ expect( 3 );
+
+ var element = $( "#draggable1" ).draggable({ axis : false });
+
+ // Any Direction
+ TestHelpers.draggable.testDrag( element, element, 50, 50, 50, 50 );
+
+ // Only horizontal
+ element.draggable( "option", "axis", "x" );
+ TestHelpers.draggable.testDrag( element, element, 50, 50, 50, 0 );
+
+ // Vertical only
+ element.draggable( "option", "axis", "y" );
+ TestHelpers.draggable.testDrag( element, element, 50, 50, 0, 50 );
+
+});
+
+test( "{ cancel: 'input,textarea,button,select,option' }, default", function() {
expect( 2 );
- $("<div id='draggable-option-cancel-default'><input type='text'></div>").appendTo("#main");
+ $( "<div id='draggable-option-cancel-default'><input type='text'></div>" ).appendTo( "#main" );
- var el = $("#draggable-option-cancel-default").draggable({ cancel: "input,textarea,button,select,option" });
- TestHelpers.draggable.shouldMove(el);
+ var element = $( "#draggable-option-cancel-default" ).draggable({ cancel: "input,textarea,button,select,option" });
+ TestHelpers.draggable.shouldMove( element );
- el.draggable("destroy");
+ element.draggable( "destroy" );
- el = $("#draggable-option-cancel-default").draggable({ cancel: "input,textarea,button,select,option" });
- TestHelpers.draggable.testDrag(el, "#draggable-option-cancel-default input", 50, 50, 0, 0);
- el.draggable("destroy");
+ element = $( "#draggable-option-cancel-default" ).draggable({ cancel: "input,textarea,button,select,option" });
+ TestHelpers.draggable.testDrag( element, "#draggable-option-cancel-default input", 50, 50, 0, 0 );
+ element.draggable( "destroy" );
});
-test("{ cancel: 'span' }", function() {
+test( "{ cancel: 'span' }", function() {
expect( 2 );
- var el = $("#draggable2").draggable();
- TestHelpers.draggable.testDrag(el, "#draggable2 span", 50, 50, 50, 50);
+ var element = $( "#draggable2" ).draggable();
+ TestHelpers.draggable.testDrag( element, "#draggable2 span", 50, 50, 50, 50 );
- el.draggable("destroy");
+ element.draggable( "destroy" );
- el = $("#draggable2").draggable({ cancel: "span" });
- TestHelpers.draggable.testDrag(el, "#draggable2 span", 50, 50, 0, 0);
+ element = $( "#draggable2" ).draggable({ cancel: "span" });
+ TestHelpers.draggable.testDrag( element, "#draggable2 span", 50, 50, 0, 0 );
});
-test("{ cancel: ? }, unexpected", function() {
- var el,
+test( "{ cancel: ? }, unexpected", function() {
+ expect( 6 );
+
+ var element,
unexpected = {
"true": true,
"false": false,
"{}": {},
"[]": [],
"null": null,
- "undefined": undefined,
- "function() {return '';}": function() {return "";},
- "function() {return true;}": function() {return true;},
- "function() {return false;}": function() {return false;}
+ "undefined": undefined
};
- expect( 9 );
-
- $.each(unexpected, function(key, val) {
- el = $("#draggable2").draggable({ cancel: val });
- TestHelpers.draggable.shouldMove(el, "cancel: " + key);
- el.draggable("destroy");
+ $.each( unexpected, function( key, val ) {
+ element = $( "#draggable2" ).draggable({ cancel: val });
+ TestHelpers.draggable.shouldMove( element, "cancel: " + key );
+ element.draggable( "destroy" );
});
});
-/*
-test("{ containment: false }, default", function() {
- expect( 1 );
+/**
+test( "{ cancel: Selectors }, matching parent selector", function() {
+
+ expect( 5 );
+
+ var element = $( "#draggable2" ).draggable({ cancel: "span a" });
+
+ $( "#qunit-fixture" ).append( "<span id='wrapping'><a></a></span>" );
+
+ element.find( "span" ).append( "<a>" );
+
+ $( "#wrapping a" ).append( element );
+
+ TestHelpers.draggable.testDrag( element, "#draggable2 span", 50, 50, 50, 50, "drag span child" );
+ TestHelpers.draggable.shouldNotMove( $( "#draggable2 span a" ) );
+ TestHelpers.draggable.shouldNotMove( $( "#wrapping a" ) );
+
+ $( "#draggable2" ).draggable( "option", "cancel", "span > a" );
+ $( "#draggable2" ).find( "a" ).append( "<a>" );
+
+
+ TestHelpers.draggable.testDrag( element, $( "#draggable2 span a" ).last(), 50, 50, 50, 50, "drag span child" );
+ TestHelpers.draggable.shouldNotMove( $( "#draggable2 span a" ).first() );
- ok(false, "missing test - untested code is broken code");
});
+*/
+
+test( "cancelement, default, switching after initialization", function() {
+ expect( 3 );
+
+ $( "<div id='draggable-option-cancel-default'><input type='text'></div>" ).appendTo( "#main" );
+
+ var input = $( "#draggable-option-cancel-default input" ),
+ element = $( "#draggable-option-cancel-default" ).draggable();
-test("{ containment: Element }", function() {
+ TestHelpers.draggable.testDrag( element, input, 50, 50, 0, 0 );
+
+ element.draggable( "option", "cancel", "textarea" );
+ TestHelpers.draggable.testDrag( element, input, 50, 50, 50, 50 );
+
+ element.draggable( "option", "cancel", "input" );
+ TestHelpers.draggable.testDrag( element, input, 50, 50, 0, 0 );
+});
+
+/*
+
+test( "{ connectToSortable: selector }, default", function() {
expect( 1 );
- ok(false, "missing test - untested code is broken code");
+ ok(false, "missing test - untested code is broken code" );
});
*/
-test("{ containment: 'parent' }, relative", function() {
+test( "{ containment: Element }", function() {
expect( 1 );
var offsetAfter,
- el = $("#draggable1").draggable({ containment: "parent" }),
- p = el.parent(),
+ element = $( "#draggable1" ).draggable({ containment: $( "#draggable1" ).parent()[ 0 ] }),
+ p = element.parent(),
po = p.offset(),
expected = {
- left: po.left + TestHelpers.draggable.border(p, "left") + TestHelpers.draggable.margin(el, "left"),
- top: po.top + TestHelpers.draggable.border(p, "top") + TestHelpers.draggable.margin(el, "top")
+ left: po.left + TestHelpers.draggable.border( p, "left" ) + TestHelpers.draggable.margin( element, "left" ),
+ top: po.top + TestHelpers.draggable.border( p, "top" ) + TestHelpers.draggable.margin( element, "top" )
};
- el.simulate( "drag", {
+ element.simulate( "drag", {
dx: -100,
dy: -100
});
- offsetAfter = el.offset();
- deepEqual(offsetAfter, expected, "compare offset to parent");
+ offsetAfter = element.offset();
+ deepEqual( offsetAfter, expected, "compare offset to parent" );
});
-test("{ containment: 'parent' }, absolute", function() {
+test( "{ containment: Selector }", function() {
expect( 1 );
var offsetAfter,
- el = $("#draggable2").draggable({ containment: "parent" }),
- p = el.parent(),
+ element = $( "#draggable1" ).draggable({ containment: $( "#qunit-fixture" ) }),
+ p = element.parent(),
po = p.offset(),
expected = {
- left: po.left + TestHelpers.draggable.border(p, "left") + TestHelpers.draggable.margin(el, "left"),
- top: po.top + TestHelpers.draggable.border(p, "top") + TestHelpers.draggable.margin(el, "top")
+ left: po.left + TestHelpers.draggable.border( p, "left" ) + TestHelpers.draggable.margin( element, "left" ),
+ top: po.top + TestHelpers.draggable.border( p, "top" ) + TestHelpers.draggable.margin( element, "top" )
};
- el.simulate( "drag", {
+ element.simulate( "drag", {
dx: -100,
dy: -100
});
- offsetAfter = el.offset();
- deepEqual(offsetAfter, expected, "compare offset to parent");
+ offsetAfter = element.offset();
+ deepEqual( offsetAfter, expected, "compare offset to parent" );
});
-/*
-test("{ containment: 'document' }", function() {
+test( "{ containment: [x1, y1, x2, y2] }", function() {
expect( 1 );
- ok(false, "missing test - untested code is broken code");
+ var element = $( "#draggable1" ).draggable(),
+ eo = element.offset();
+
+ 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 );
});
-test("{ containment: 'window' }", function() {
+test( "{ containment: 'parent' }, relative", function() {
expect( 1 );
- ok(false, "missing test - untested code is broken code");
+ var offsetAfter,
+ element = $( "#draggable1" ).draggable({ containment: "parent" }),
+ p = element.parent(),
+ po = p.offset(),
+ expected = {
+ left: po.left + TestHelpers.draggable.border( p, "left" ) + TestHelpers.draggable.margin( element, "left" ),
+ top: po.top + TestHelpers.draggable.border( p, "top" ) + TestHelpers.draggable.margin( element, "top" )
+ };
+
+ element.simulate( "drag", {
+ dx: -100,
+ dy: -100
+ });
+ offsetAfter = element.offset();
+ deepEqual( offsetAfter, expected, "compare offset to parent" );
});
-test("{ containment: Selector }", function() {
+test( "{ containment: 'parent' }, absolute", function() {
expect( 1 );
- ok(false, "missing test - untested code is broken code");
+ var offsetAfter,
+ element = $( "#draggable2" ).draggable({ containment: "parent" }),
+ p = element.parent(),
+ po = p.offset(),
+ expected = {
+ left: po.left + TestHelpers.draggable.border( p, "left" ) + TestHelpers.draggable.margin( element, "left" ),
+ top: po.top + TestHelpers.draggable.border( p, "top" ) + TestHelpers.draggable.margin( element, "top" )
+ };
+
+ element.simulate( "drag", {
+ dx: -100,
+ dy: -100
+ });
+ offsetAfter = element.offset();
+ deepEqual( offsetAfter, expected, "compare offset to parent" );
});
-test("{ containment: [x1, y1, x2, y2] }", function() {
- expect( 1 );
+test( "containment, default, switching after initialization", function() {
+ expect( 2 );
+
+ var element = $( "#draggable1" ).draggable({ containment: false });
+
+ TestHelpers.draggable.testDrag( element, element, -100, -100, -100, -100 );
- ok(false, "missing test - untested code is broken code");
+ element.draggable( "option", "containment", "parent" )
+ .css({
+ top: 0,
+ left: 0
+ })
+ .appendTo( $( "#main" ) );
+
+ TestHelpers.draggable.testDrag( element, element, -100, -100, 0, 0 );
+
+ // TODO: Switching back to false does not update to false
+ // element.draggable( "option", "containment", false );
+ // TestHelpers.draggable.testDrag( element, element, -100, -100, -100, -100 );
});
-*/
-test("{ cursor: 'auto' }, default", function() {
- function getCursor() { return $("#draggable2").css("cursor"); }
+test( "{ cursor: 'auto' }, default", function() {
+ function getCursor() {
+ return $( "#draggable2" ).css( "cursor" );
+ }
- expect(2);
+ expect( 2 );
- var actual, before, after,
+ var actual, after,
expected = "auto",
- el = $("#draggable2").draggable({
+ element = $( "#draggable2" ).draggable({
cursor: expected,
start: function() {
actual = getCursor();
}
- });
+ }),
+ before = getCursor();
- before = getCursor();
- el.simulate( "drag", {
+ element.simulate( "drag", {
dx: -1,
dy: -1
});
after = getCursor();
- equal(actual, expected, "start callback: cursor '" + expected + "'");
- equal(after, before, "after drag: cursor restored");
-
+ equal( actual, expected, "start callback: cursor '" + expected + "'" );
+ equal( after, before, "after drag: cursor restored" );
});
-test("{ cursor: 'move' }", function() {
+test( "{ cursor: 'move' }", function() {
+ function getCursor() {
+ return $( "body" ).css( "cursor" );
+ }
- function getCursor() { return $("body").css("cursor"); }
-
- expect(2);
+ expect( 2 );
- var actual, before, after,
+ var actual, after,
expected = "move",
- el = $("#draggable2").draggable({
+ element = $( "#draggable2" ).draggable({
cursor: expected,
start: function() {
actual = getCursor();
}
- });
+ }),
+ before = getCursor();
- before = getCursor();
- el.simulate( "drag", {
+ element.simulate( "drag", {
dx: -1,
dy: -1
});
after = getCursor();
- equal(actual, expected, "start callback: cursor '" + expected + "'");
- equal(after, before, "after drag: cursor restored");
+ equal( actual, expected, "start callback: cursor '" + expected + "'" );
+ equal( after, before, "after drag: cursor restored" );
+});
+
+test( "cursor, default, switching after initialization", function() {
+ expect( 3 );
+
+ var element = $( "#draggable1" ).draggable();
+
+ TestHelpers.draggable.trackMouseCss( element );
+ TestHelpers.draggable.move( element, 1, 1 );
+ equal( element.data( "last_dragged_cursor" ), "auto" );
+
+ element.draggable( "option", "cursor", "move" );
+ TestHelpers.draggable.move( element, 1, 1 );
+ equal( element.data( "last_dragged_cursor" ), "move" );
+
+ element.draggable( "option", "cursor", "ns-resize" );
+ TestHelpers.draggable.move( element, 1, 1 );
+ equal( element.data( "last_dragged_cursor" ), "ns-resize" );
});
test( "cursorAt", function() {
@@ -286,7 +456,7 @@ test( "cursorAt", function() {
$.each( tests, function( testName, testData ) {
$.each( [ "relative", "absolute" ], function( i, position ) {
- var el = $( "#draggable" + ( i + 1 ) ).draggable({
+ var element = $( "#draggable" + ( i + 1 ) ).draggable({
cursorAt: testData.cursorAt,
drag: function( event, ui ) {
if( !testData.cursorAt ) {
@@ -302,7 +472,52 @@ test( "cursorAt", function() {
}
});
- el.simulate( "drag", {
+ element.simulate( "drag", {
+ moves: 1,
+ dx: deltaX,
+ dy: deltaY
+ });
+ });
+ });
+});
+
+test( "cursorAt, switching after initialization", function() {
+ expect( 24 );
+
+ var deltaX = -3,
+ deltaY = -3,
+ tests = {
+ "false": { cursorAt : false },
+ "{ left: -5, top: -5 }": { x: -5, y: -5, cursorAt : { left: -5, top: -5 } },
+ "[ 10, 20 ]": { x: 10, y: 20, cursorAt : [ 10, 20 ] },
+ "'10 20'": { x: 10, y: 20, cursorAt : "10 20" },
+ "{ left: 20, top: 40 }": { x: 20, y: 40, cursorAt : { left: 20, top: 40 } },
+ "{ right: 10, bottom: 20 }": { x: 10, y: 20, cursorAt : { right: 10, bottom: 20 } }
+ };
+
+ $.each( tests, function( testName, testData ) {
+ $.each( [ "relative", "absolute" ], function( i, position ) {
+ var element = $( "#draggable" + ( i + 1 ) );
+
+ element.draggable({
+ drag: function( event, ui ) {
+ if( !testData.cursorAt ) {
+ equal( ui.position.left - ui.originalPosition.left, deltaX, testName + " " + position + " left" );
+ equal( ui.position.top - ui.originalPosition.top, deltaY, testName + " " + position + " top" );
+ } 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.height() - ( event.clientY - ui.offset.top ), testData.y - TestHelpers.draggable.unreliableOffset, testName + " " +position + " top" );
+ } else {
+ equal( event.clientX - ui.offset.left, testData.x + TestHelpers.draggable.unreliableOffset, testName + " " + position + " left" );
+ equal( event.clientY - ui.offset.top, testData.y + TestHelpers.draggable.unreliableOffset, testName + " " + position + " top" );
+ }
+ }
+ });
+
+ element.draggable( "option", "cursorAt", false );
+ element.draggable( "option", "cursorAt", testData.cursorAt );
+
+ element.simulate( "drag", {
moves: 1,
dx: deltaX,
dy: deltaY
@@ -311,451 +526,758 @@ test( "cursorAt", function() {
});
});
-test("{ distance: 10 }", function() {
+test( "disabled", function() {
expect( 3 );
- var el = $("#draggable2").draggable({ distance: 10 });
- TestHelpers.draggable.testDrag(el, el, -9, -9, 0, 0, "distance not met");
+ var element = $( "#draggable1" ).draggable();
- TestHelpers.draggable.testDrag(el, el, -10, -10, -10, -10, "distance met");
+ TestHelpers.draggable.shouldMove( element );
- TestHelpers.draggable.testDrag(el, el, 9, 9, 0, 0, "distance not met");
+ element.draggable( "option", "disabled", true );
+ TestHelpers.draggable.shouldNotMove( element );
+ element.draggable( "option", "disabled", false );
+ TestHelpers.draggable.shouldMove( element );
});
-test("{ grid: [50, 50] }, relative", function() {
+test( "{ grid: [50, 50] }, relative", function() {
expect( 2 );
- var el = $("#draggable1").draggable({ grid: [50, 50] });
- TestHelpers.draggable.testDrag(el, el, 24, 24, 0, 0);
- TestHelpers.draggable.testDrag(el, el, 26, 25, 50, 50);
+ var element = $( "#draggable1" ).draggable({ grid: [ 50, 50 ] });
+ TestHelpers.draggable.testDrag( element, element, 24, 24, 0, 0 );
+ TestHelpers.draggable.testDrag( element, element, 26, 25, 50, 50 );
});
-test("{ grid: [50, 50] }, absolute", function() {
+test( "{ grid: [50, 50] }, absolute", function() {
expect( 2 );
- var el = $("#draggable2").draggable({ grid: [50, 50] });
- TestHelpers.draggable.testDrag(el, el, 24, 24, 0, 0);
- TestHelpers.draggable.testDrag(el, el, 26, 25, 50, 50);
+ var element = $( "#draggable2" ).draggable({ grid: [ 50, 50 ] });
+ TestHelpers.draggable.testDrag( element, element, 24, 24, 0, 0 );
+ TestHelpers.draggable.testDrag( element, element, 26, 25, 50, 50 );
+});
+
+test( "grid, switching after initialization", function() {
+ expect( 4 );
+
+ var element = $( "#draggable1" ).draggable();
+
+ // Forward
+ TestHelpers.draggable.testDrag( element, element, 24, 24, 24, 24 );
+ TestHelpers.draggable.testDrag( element, element, 0, 0, 0, 0 );
+
+ element.draggable( "option", "grid", [ 50,50 ] );
+
+ TestHelpers.draggable.testDrag( element, element, 24, 24, 0, 0 );
+ TestHelpers.draggable.testDrag( element, element, 26, 25, 50, 50 );
});
-test("{ handle: 'span' }", function() {
+test( "{ handle: 'span' }", function() {
expect( 2 );
- var el = $("#draggable2").draggable({ handle: "span" });
+ var element = $( "#draggable2" ).draggable({ handle: "span" });
+
+ TestHelpers.draggable.testDrag( element, "#draggable2 span", 50, 50, 50, 50, "drag span" );
+ TestHelpers.draggable.shouldNotMove( element, "drag element" );
+});
+
+/*
+test( "{ handle: Selectors }, matching parent selector", function() {
+
+ expect( 4 );
+
+ var element = $( "#draggable2" ).draggable({ handle: "span a" });
+
+ $( "#qunit-fixture" ).append( "<span id='wrapping'><a></a></span>" );
+
+ element.find( "span" ).append( "<a>" );
+
+ $( "#wrapping a" ).append( element );
+
+ TestHelpers.draggable.testDrag( element, "#draggable2 span a", 50, 50, 50, 50, "drag span child" );
+ TestHelpers.draggable.shouldNotMove( $( "#wrapping a" ) );
+
+ $( "#draggable2" ).draggable( "option", "handle", "span > a" );
+ $( "#draggable2" ).find( "a" ).append( "<a>" );
+
+ TestHelpers.draggable.testDrag( element, $( "#draggable2 span a" ).first(), 50, 50, 50, 50, "drag span child" );
+ TestHelpers.draggable.shouldNotMove( $( "#draggable2 span a" ).last() );
+
+});
+*/
+
+test( "handle, default, switching after initialization", function() {
+ expect( 6 );
+
+ var element = $( "#draggable2" ).draggable();
+
+ TestHelpers.draggable.testDrag( element, element, 50, 50, 50, 50 );
+ TestHelpers.draggable.testDrag( element, "#draggable2 span", 100, 100, 100, 100 );
+
+ // Switch
+ element.draggable( "option", "handle", "span" );
+ TestHelpers.draggable.testDrag( element, element, 50, 50, 0, 0 );
+ TestHelpers.draggable.testDrag( element, "#draggable2 span", 100, 100, 100, 100 );
- TestHelpers.draggable.testDrag(el, "#draggable2 span", 50, 50, 50, 50, "drag span");
- TestHelpers.draggable.shouldNotMove(el, "drag element");
+ // And back
+ element.draggable( "option", "handle", false );
+ TestHelpers.draggable.testDrag( element, element, 50, 50, 50, 50 );
+ TestHelpers.draggable.testDrag( element, "#draggable2 span", 100, 100, 100, 100 );
});
-test("{ helper: 'clone' }, relative", function() {
+test( "helper, default, switching after initialization", function() {
+ expect( 3 );
+
+ var element = $( "#draggable1" ).draggable();
+ TestHelpers.draggable.shouldMove( element );
+
+ element.draggable( "option", "helper", "clone" );
+ TestHelpers.draggable.shouldNotMove( element );
+
+ element.draggable( "option", "helper", "original" );
+ TestHelpers.draggable.shouldMove( element );
+});
+
+test( "{ helper: 'clone' }, relative", function() {
expect( 1 );
- var el = $("#draggable1").draggable({ helper: "clone" });
- TestHelpers.draggable.shouldNotMove(el);
+ var element = $( "#draggable1" ).draggable({ helper: "clone" });
+ TestHelpers.draggable.shouldNotMove( element );
});
-test("{ helper: 'clone' }, absolute", function() {
+test( "{ helper: 'clone' }, absolute", function() {
expect( 1 );
- var el = $("#draggable2").draggable({ helper: "clone" });
- TestHelpers.draggable.shouldNotMove(el);
+ var element = $( "#draggable2" ).draggable({ helper: "clone" });
+ TestHelpers.draggable.shouldNotMove( element );
});
-test("{ helper: 'original' }, relative, with scroll offset on parent", function() {
+test( "{ helper: 'original' }, relative, with scroll offset on parent", function() {
expect( 3 );
- var el = $("#draggable1").draggable({ helper: "original" });
+ var element = $( "#draggable1" ).draggable({ helper: "original" });
TestHelpers.draggable.setScroll();
- TestHelpers.draggable.testScroll(el, "relative");
+ TestHelpers.draggable.testScroll( element, "relative" );
TestHelpers.draggable.setScroll();
- TestHelpers.draggable.testScroll(el, "static");
+ TestHelpers.draggable.testScroll( element, "static" );
TestHelpers.draggable.setScroll();
- TestHelpers.draggable.testScroll(el, "absolute");
+ TestHelpers.draggable.testScroll( element, "absolute" );
TestHelpers.draggable.restoreScroll();
-
});
-test("{ helper: 'original' }, relative, with scroll offset on root", function() {
+test( "{ helper: 'original' }, relative, with scroll offset on root", function() {
expect( 3 );
- var el = $("#draggable1").draggable({ helper: "original" });
-
- TestHelpers.draggable.setScroll("root");
- TestHelpers.draggable.testScroll(el, "relative");
+ var element = $( "#draggable1" ).draggable({ helper: "original" });
- TestHelpers.draggable.setScroll("root");
- TestHelpers.draggable.testScroll(el, "static");
+ TestHelpers.draggable.setScroll( "root" );
+ TestHelpers.draggable.testScroll( element, "relative" );
- TestHelpers.draggable.setScroll("root");
- TestHelpers.draggable.testScroll(el, "absolute");
+ TestHelpers.draggable.setScroll( "root" );
+ TestHelpers.draggable.testScroll( element, "static" );
- TestHelpers.draggable.restoreScroll("root");
+ TestHelpers.draggable.setScroll( "root" );
+ TestHelpers.draggable.testScroll( element, "absolute" );
+ TestHelpers.draggable.restoreScroll( "root" );
});
-test("{ helper: 'original' }, relative, with scroll offset on root and parent", function() {
-
- expect(3);
+test( "{ helper: 'original' }, relative, with scroll offset on root and parent", function() {
+ expect( 3 );
- var el = $("#draggable1").draggable({ helper: "original" });
+ var element = $( "#draggable1" ).draggable({ helper: "original" });
TestHelpers.draggable.setScroll();
- TestHelpers.draggable.setScroll("root");
- TestHelpers.draggable.testScroll(el, "relative");
+ TestHelpers.draggable.setScroll( "root" );
+ TestHelpers.draggable.testScroll( element, "relative" );
TestHelpers.draggable.setScroll();
- TestHelpers.draggable.setScroll("root");
- TestHelpers.draggable.testScroll(el, "static");
+ TestHelpers.draggable.setScroll( "root" );
+ TestHelpers.draggable.testScroll( element, "static" );
TestHelpers.draggable.setScroll();
- TestHelpers.draggable.setScroll("root");
- TestHelpers.draggable.testScroll(el, "absolute");
+ TestHelpers.draggable.setScroll( "root" );
+ TestHelpers.draggable.testScroll( element, "absolute" );
TestHelpers.draggable.restoreScroll();
- TestHelpers.draggable.restoreScroll("root");
-
+ TestHelpers.draggable.restoreScroll( "root" );
});
-test("{ helper: 'original' }, absolute, with scroll offset on parent", function() {
-
- expect(3);
+test( "{ helper: 'original' }, absolute, with scroll offset on parent", function() {
+ expect( 3 );
- var el = $("#draggable1").css({ position: "absolute", top: 0, left: 0 }).draggable({ helper: "original" });
+ var element = $( "#draggable1" ).css({ position: "absolute", top: 0, left: 0 }).draggable({ helper: "original" });
TestHelpers.draggable.setScroll();
- TestHelpers.draggable.testScroll(el, "relative");
+ TestHelpers.draggable.testScroll( element, "relative" );
TestHelpers.draggable.setScroll();
- TestHelpers.draggable.testScroll(el, "static");
+ TestHelpers.draggable.testScroll( element, "static" );
TestHelpers.draggable.setScroll();
- TestHelpers.draggable.testScroll(el, "absolute");
+ TestHelpers.draggable.testScroll( element, "absolute" );
TestHelpers.draggable.restoreScroll();
-
});
-test("{ helper: 'original' }, absolute, with scroll offset on root", function() {
-
- expect(3);
-
- var el = $("#draggable1").css({ position: "absolute", top: 0, left: 0 }).draggable({ helper: "original" });
+test( "{ helper: 'original' }, absolute, with scroll offset on root", function() {
+ expect( 3 );
- TestHelpers.draggable.setScroll("root");
- TestHelpers.draggable.testScroll(el, "relative");
+ var element = $( "#draggable1" ).css({ position: "absolute", top: 0, left: 0 }).draggable({ helper: "original" });
- TestHelpers.draggable.setScroll("root");
- TestHelpers.draggable.testScroll(el, "static");
+ TestHelpers.draggable.setScroll( "root" );
+ TestHelpers.draggable.testScroll( element, "relative" );
- TestHelpers.draggable.setScroll("root");
- TestHelpers.draggable.testScroll(el, "absolute");
+ TestHelpers.draggable.setScroll( "root" );
+ TestHelpers.draggable.testScroll( element, "static" );
- TestHelpers.draggable.restoreScroll("root");
+ TestHelpers.draggable.setScroll( "root" );
+ TestHelpers.draggable.testScroll( element, "absolute" );
+ TestHelpers.draggable.restoreScroll( "root" );
});
-test("{ helper: 'original' }, absolute, with scroll offset on root and parent", function() {
-
- expect(3);
+test( "{ helper: 'original' }, absolute, with scroll offset on root and parent", function() {
+ expect( 3 );
- var el = $("#draggable1").css({ position: "absolute", top: 0, left: 0 }).draggable({ helper: "original" });
+ var element = $( "#draggable1" ).css({ position: "absolute", top: 0, left: 0 }).draggable({ helper: "original" });
TestHelpers.draggable.setScroll();
- TestHelpers.draggable.setScroll("root");
- TestHelpers.draggable.testScroll(el, "relative");
+ TestHelpers.draggable.setScroll( "root" );
+ TestHelpers.draggable.testScroll( element, "relative" );
TestHelpers.draggable.setScroll();
- TestHelpers.draggable.setScroll("root");
- TestHelpers.draggable.testScroll(el, "static");
+ TestHelpers.draggable.setScroll( "root" );
+ TestHelpers.draggable.testScroll( element, "static" );
TestHelpers.draggable.setScroll();
- TestHelpers.draggable.setScroll("root");
- TestHelpers.draggable.testScroll(el, "absolute");
+ TestHelpers.draggable.setScroll( "root" );
+ TestHelpers.draggable.testScroll( element, "absolute" );
TestHelpers.draggable.restoreScroll();
- TestHelpers.draggable.restoreScroll("root");
-
+ TestHelpers.draggable.restoreScroll( "root" );
});
-test("{ helper: 'original' }, fixed, with scroll offset on parent", function() {
-
- expect(3);
+test( "{ helper: 'original' }, fixed, with scroll offset on parent", function() {
+ expect( 3 );
- var el = $("#draggable1").css({ position: "fixed", top: 0, left: 0 }).draggable({ helper: "original" });
+ var element = $( "#draggable1" ).css({ position: "fixed", top: 0, left: 0 }).draggable({ helper: "original" });
TestHelpers.draggable.setScroll();
- TestHelpers.draggable.testScroll(el, "relative");
+ TestHelpers.draggable.testScroll( element, "relative" );
TestHelpers.draggable.setScroll();
- TestHelpers.draggable.testScroll(el, "static");
+ TestHelpers.draggable.testScroll( element, "static" );
TestHelpers.draggable.setScroll();
- TestHelpers.draggable.testScroll(el, "absolute");
+ TestHelpers.draggable.testScroll( element, "absolute" );
TestHelpers.draggable.restoreScroll();
-
});
-test("{ helper: 'original' }, fixed, with scroll offset on root", function() {
-
- expect(3);
+test( "{ helper: 'original' }, fixed, with scroll offset on root", function() {
+ expect( 3 );
- var el = $("#draggable1").css({ position: "fixed", top: 0, left: 0 }).draggable({ helper: "original" });
+ var element = $( "#draggable1" ).css({ position: "fixed", top: 0, left: 0 }).draggable({ helper: "original" });
- TestHelpers.draggable.setScroll("root");
- TestHelpers.draggable.testScroll(el, "relative");
+ TestHelpers.draggable.setScroll( "root" );
+ TestHelpers.draggable.testScroll( element, "relative" );
- TestHelpers.draggable.setScroll("root");
- TestHelpers.draggable.testScroll(el, "static");
+ TestHelpers.draggable.setScroll( "root" );
+ TestHelpers.draggable.testScroll( element, "static" );
- TestHelpers.draggable.setScroll("root");
- TestHelpers.draggable.testScroll(el, "absolute");
+ TestHelpers.draggable.setScroll( "root" );
+ TestHelpers.draggable.testScroll( element, "absolute" );
- TestHelpers.draggable.restoreScroll("root");
+ TestHelpers.draggable.restoreScroll( "root" );
});
-test("{ helper: 'original' }, fixed, with scroll offset on root and parent", function() {
-
- expect(3);
+test( "{ helper: 'original' }, fixed, with scroll offset on root and parent", function() {
+ expect( 3 );
- var el = $("#draggable1").css({ position: "fixed", top: 0, left: 0 }).draggable({ helper: "original" });
+ var element = $( "#draggable1" ).css({ position: "fixed", top: 0, left: 0 }).draggable({ helper: "original" });
TestHelpers.draggable.setScroll();
- TestHelpers.draggable.setScroll("root");
- TestHelpers.draggable.testScroll(el, "relative");
+ TestHelpers.draggable.setScroll( "root" );
+ TestHelpers.draggable.testScroll( element, "relative" );
TestHelpers.draggable.setScroll();
- TestHelpers.draggable.setScroll("root");
- TestHelpers.draggable.testScroll(el, "static");
+ TestHelpers.draggable.setScroll( "root" );
+ TestHelpers.draggable.testScroll( element, "static" );
TestHelpers.draggable.setScroll();
- TestHelpers.draggable.setScroll("root");
- TestHelpers.draggable.testScroll(el, "absolute");
+ TestHelpers.draggable.setScroll( "root" );
+ TestHelpers.draggable.testScroll( element, "absolute" );
TestHelpers.draggable.restoreScroll();
- TestHelpers.draggable.restoreScroll("root");
-
+ TestHelpers.draggable.restoreScroll( "root" );
});
-test("{ helper: 'clone' }, absolute", function() {
-
- expect(1);
+test( "{ helper: 'clone' }, absolute", function() {
+ expect( 1 );
var helperOffset = null,
- origOffset = $("#draggable1").offset(),
- el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) {
+ origOffset = $( "#draggable1" ).offset(),
+ element = $( "#draggable1" ).draggable({ helper: "clone", drag: function( event, ui) {
helperOffset = ui.helper.offset();
} });
- el.simulate( "drag", {
+ element.simulate( "drag", {
dx: 1,
dy: 1
});
- deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, "dragged[1, 1] ");
-
+ deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" );
});
-test("{ helper: 'clone' }, absolute with scroll offset on parent", function() {
-
- expect(3);
+test( "{ helper: 'clone' }, absolute with scroll offset on parent", function() {
+ expect( 3 );
TestHelpers.draggable.setScroll();
var helperOffset = null,
origOffset = null,
- el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) {
- helperOffset = ui.helper.offset();
- } });
+ element = $( "#draggable1" ).draggable({
+ helper: "clone",
+ drag: function( event, ui) {
+ helperOffset = ui.helper.offset();
+ }
+ });
- $("#main").css("position", "relative");
- origOffset = $("#draggable1").offset();
- el.simulate( "drag", {
+ $( "#main" ).css( "position", "relative" );
+ origOffset = $( "#draggable1" ).offset();
+ element.simulate( "drag", {
dx: 1,
dy: 1
});
- deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, "dragged[1, 1] ");
+ deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" );
- $("#main").css("position", "static");
- origOffset = $("#draggable1").offset();
- el.simulate( "drag", {
+ $( "#main" ).css( "position", "static" );
+ origOffset = $( "#draggable1" ).offset();
+ element.simulate( "drag", {
dx: 1,
dy: 1
});
- deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, "dragged[1, 1] ");
+ deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" );
- $("#main").css("position", "absolute");
- origOffset = $("#draggable1").offset();
- el.simulate( "drag", {
+ $( "#main" ).css( "position", "absolute" );
+ origOffset = $( "#draggable1" ).offset();
+ element.simulate( "drag", {
dx: 1,
dy: 1
});
- deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, "dragged[1, 1] ");
+ deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" );
TestHelpers.draggable.restoreScroll();
-
});
-test("{ helper: 'clone' }, absolute with scroll offset on root", function() {
-
- expect(3);
+test( "{ helper: 'clone' }, absolute with scroll offset on root", function() {
+ expect( 3 );
- TestHelpers.draggable.setScroll("root");
+ TestHelpers.draggable.setScroll( "root" );
var helperOffset = null,
origOffset = null,
- el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) {
- helperOffset = ui.helper.offset();
- } });
+ element = $( "#draggable1" ).draggable({
+ helper: "clone",
+ drag: function( event, ui) {
+ helperOffset = ui.helper.offset();
+ }
+ });
- $("#main").css("position", "relative");
- origOffset = $("#draggable1").offset();
- el.simulate( "drag", {
+ $( "#main" ).css( "position", "relative" );
+ origOffset = $( "#draggable1" ).offset();
+ element.simulate( "drag", {
dx: 1,
dy: 1
});
- deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, "dragged[1, 1] ");
+ deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" );
- $("#main").css("position", "static");
- origOffset = $("#draggable1").offset();
- el.simulate( "drag", {
+ $( "#main" ).css( "position", "static" );
+ origOffset = $( "#draggable1" ).offset();
+ element.simulate( "drag", {
dx: 1,
dy: 1
});
- deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, "dragged[1, 1] ");
+ deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" );
- $("#main").css("position", "absolute");
- origOffset = $("#draggable1").offset();
- el.simulate( "drag", {
+ $( "#main" ).css( "position", "absolute" );
+ origOffset = $( "#draggable1" ).offset();
+ element.simulate( "drag", {
dx: 1,
dy: 1
});
- deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, "dragged[1, 1] ");
-
- TestHelpers.draggable.restoreScroll("root");
+ deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" );
+ TestHelpers.draggable.restoreScroll( "root" );
});
-test("{ helper: 'clone' }, absolute with scroll offset on root and parent", function() {
-
- expect(3);
+test( "{ helper: 'clone' }, absolute with scroll offset on root and parent", function() {
+ expect( 3 );
- TestHelpers.draggable.setScroll("root");
+ TestHelpers.draggable.setScroll( "root" );
TestHelpers.draggable.setScroll();
var helperOffset = null,
origOffset = null,
- el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) {
- helperOffset = ui.helper.offset();
- } });
+ element = $( "#draggable1" ).draggable({
+ helper: "clone",
+ drag: function( event, ui) {
+ helperOffset = ui.helper.offset();
+ }
+ });
- $("#main").css("position", "relative");
- origOffset = $("#draggable1").offset();
- el.simulate( "drag", {
+ $( "#main" ).css( "position", "relative" );
+ origOffset = $( "#draggable1" ).offset();
+ element.simulate( "drag", {
dx: 1,
dy: 1
});
- deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, "dragged[1, 1] ");
+ deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" );
- $("#main").css("position", "static");
- origOffset = $("#draggable1").offset();
- el.simulate( "drag", {
+ $( "#main" ).css( "position", "static" );
+ origOffset = $( "#draggable1" ).offset();
+ element.simulate( "drag", {
dx: 1,
dy: 1
});
- deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, "dragged[1, 1] ");
+ deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" );
- $("#main").css("position", "absolute");
- origOffset = $("#draggable1").offset();
- el.simulate( "drag", {
+ $( "#main" ).css( "position", "absolute" );
+ origOffset = $( "#draggable1" ).offset();
+ element.simulate( "drag", {
dx: 1,
dy: 1
});
- deepEqual({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, "dragged[1, 1] ");
+ deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" );
- TestHelpers.draggable.restoreScroll("root");
+ TestHelpers.draggable.restoreScroll( "root" );
TestHelpers.draggable.restoreScroll();
-
});
-test("{ opacity: 0.5 }", function() {
-
- expect(1);
+test( "{ opacity: 0.5 }", function() {
+ expect( 1 );
var opacity = null,
- el = $("#draggable2").draggable({
+ element = $( "#draggable2" ).draggable({
opacity: 0.5,
start: function() {
- opacity = $(this).css("opacity");
+ opacity = $(this).css( "opacity" );
}
});
- el.simulate( "drag", {
+ element.simulate( "drag", {
dx: -1,
dy: -1
});
- equal(opacity, 0.5, "start callback: opacity is");
+ equal( opacity, 0.5, "start callback: opacity is" );
+});
+
+test( "opacity, default, switching after initialization", function() {
+ expect( 3 );
+ var opacity = null,
+ element = $( "#draggable2" ).draggable({
+ start: function() {
+ opacity = $(this).css( "opacity" );
+ }
+ });
+
+ TestHelpers.draggable.move( element, 1, 1 );
+ equal( opacity, 1 );
+
+ element.draggable( "option", "opacity", 0.5 );
+ TestHelpers.draggable.move( element, 2, 1 );
+ equal( opacity, 0.5 );
+
+ element.draggable( "option", "opacity", false );
+ TestHelpers.draggable.move( element, 3, 1 );
+ equal( opacity, 1 );
});
-test("{ zIndex: 10 }", function() {
+asyncTest( "revert and revertDuration", function() {
+ expect( 4 );
+
+ var element = $( "#draggable2" ).draggable({
+ revert: true,
+ revertDuration: 0
+ });
+ TestHelpers.draggable.shouldNotMove( element, "revert: true, revertDuration: 0 should revert immediately" );
+
+ $( "#draggable2" ).draggable( "option", "revert", "invalid" );
+ TestHelpers.draggable.shouldNotMove( element, "revert: invalid, revertDuration: 0 should revert immediately" );
+
+ $( "#draggable2" ).draggable( "option", "revert", false );
+ TestHelpers.draggable.shouldMove( element, "revert: false should allow movement" );
+
+ $( "#draggable2" ).draggable( "option", {
+ revert: true,
+ revertDuration: 200,
+ stop: function() {
+ start();
+ }
+ });
+
+ // animation are async, so test for it asynchronously
+ TestHelpers.draggable.move( element, 50, 50 );
+ setTimeout( function() {
+ ok( $( "#draggable2" ).is( ":animated" ), "revert: true with revertDuration should animate" );
+ });
+});
+
+test( "revert: valid", function() {
+ expect( 1 );
+
+ var element = $( "#draggable2" ).draggable({
+ revert: "valid",
+ revertDuration: 0
+ });
+
+ $( "#droppable" ).droppable();
+
+ TestHelpers.draggable.testDrag( element, element, 100, 100, 0, 0, "revert: valid reverts when dropped on a droppable" );
+});
+
+test( "scope", function() {
+ expect( 2 );
+
+ var element = $( "#draggable2" ).draggable({
+ scope: "tasks",
+ revert: "valid",
+ revertDuration: 0
+ });
+
+ $( "#droppable" ).droppable({ scope: "tasks" });
+
+ TestHelpers.draggable.testDrag( element, element, 100, 100, 0, 0, "revert: valid reverts when dropped on a droppable" );
- expect(1);
+ $( "#droppable" ).droppable( "destroy" ).droppable({ scope: "nottasks" });
+
+ TestHelpers.draggable.testDrag( element, element, 100, 100, 100, 100, "revert: valid reverts when dropped on a droppable" );
+});
+
+test( "scroll, scrollSensitivity, and scrollSpeed", function() {
+ expect( 2 );
+
+ var viewportHeight = $( window ).height(),
+ element = $( "#draggable1" ).draggable({ scroll: true }),
+ scrollSensitivity = element.draggable( "option", "scrollSensitivity" ),
+ scrollSpeed = element.draggable( "option", "scrollSpeed" );
+
+ element.offset({
+ top: viewportHeight - scrollSensitivity - 1,
+ left: 1
+ });
+
+ element.simulate( "drag", {
+ dx: 1,
+ y: viewportHeight - scrollSensitivity - 1,
+ moves: 1
+ });
+
+ ok( $( window ).scrollTop() === 0, "scroll: true doesn't scroll when the element is dragged outside of scrollSensitivity" );
+
+ element.draggable( "option", "scrollSensitivity", scrollSensitivity + 10 );
+
+ element.offset({
+ top: viewportHeight - scrollSensitivity - 1,
+ left: 1
+ });
+
+ element.simulate( "drag", {
+ dx: 1,
+ y: viewportHeight - scrollSensitivity - 1,
+ moves: 1
+ });
+
+ ok( $( window ).scrollTop() === scrollSpeed, "scroll: true scrolls when the element is dragged within scrollSensitivity" );
+
+ TestHelpers.draggable.restoreScroll( document );
+});
+
+test( "snap, snapMode, and snapTolerance", function() {
+ expect( 9 );
+
+ var newX, newY,
+ snapTolerance = 15,
+ element = $( "#draggable1" ).draggable({
+ snap: true,
+ snapMode: "both",
+ snapTolerance: snapTolerance
+ }),
+ element2 = $( "#draggable2" ).draggable();
+
+ element.offset({
+ top: 1,
+ left: 1
+ });
+
+ newX = element2.offset().left - element.outerWidth() - snapTolerance - 2;
+ newY = element2.offset().top;
+
+ element.simulate( "drag", {
+ handle: "corner",
+ x: newX,
+ y: newY,
+ moves: 1
+ });
+
+ deepEqual( element.offset(), { top: newY, left: newX }, "doesn't snap outside the snapTolerance" );
+
+ newX += 3;
+
+ element.simulate( "drag", {
+ handle: "corner",
+ x: newX,
+ y: newY,
+ moves: 1
+ });
+
+ notDeepEqual( element.offset(), { top: newY, left: newX }, "snaps inside the snapTolerance" );
+
+ element.draggable( "option", "snap", "#draggable2" );
+
+ element.simulate( "drag", {
+ handle: "corner",
+ x: newX,
+ y: newY,
+ moves: 1
+ });
+
+ notDeepEqual( element.offset(), { top: newY, left: newX }, "snaps based on selector" );
+
+ element.draggable( "option", "snap", "#draggable3" );
+
+ element.simulate( "drag", {
+ handle: "corner",
+ x: newX,
+ y: newY,
+ moves: 1
+ });
+
+ deepEqual( element.offset(), { top: newY, left: newX }, "doesn't snap based on invalid selector" );
+
+ element.draggable( "option", "snap", true );
+ element.draggable( "option", "snapTolerance", snapTolerance - 2 );
+ element.simulate( "drag", {
+ handle: "corner",
+ x: newX,
+ y: newY,
+ moves: 1
+ });
+
+ deepEqual( element.offset(), { top: newY, left: newX }, "doesn't snap outside the modified snapTolerance" );
+
+ element.draggable( "option", "snapTolerance", snapTolerance );
+ element.draggable( "option", "snapMode", "inner" );
+
+ element.simulate( "drag", {
+ handle: "corner",
+ x: newX,
+ y: newY,
+ moves: 1
+ });
+
+ deepEqual( element.offset(), { top: newY, left: newX }, "doesn't snap inside the outer snapTolerance area when snapMode is inner" );
+
+ newX = element2.offset().left - snapTolerance - 1;
+ newY = element2.offset().top;
+
+ element.simulate( "drag", {
+ handle: "corner",
+ x: newX,
+ y: newY,
+ moves: 1
+ });
+
+ deepEqual( element.offset(), { top: newY, left: newX }, "doesn't snap inside the outer snapTolerance area when snapMode is inner" );
+
+ newX++;
+
+ element.simulate( "drag", {
+ handle: "corner",
+ x: newX,
+ y: newY,
+ moves: 1
+ });
+
+ notDeepEqual( element.offset(), { top: newY, left: newX }, "snaps inside the inner snapTolerance area when snapMode is inner" );
+
+ element.draggable( "option", "snapMode", "outer" );
+
+ element.simulate( "drag", {
+ handle: "corner",
+ x: newX,
+ y: newY,
+ moves: 1
+ });
+
+ deepEqual( element.offset(), { top: newY, left: newX }, "doesn't snap on the inner snapTolerance area when snapMode is outer" );
+});
+
+test( "stack", function() {
+ expect( 2 );
+
+ var element = $( "#draggable1" ).draggable({
+ stack: "#draggable1, #draggable2"
+ }),
+ element2 = $( "#draggable2" ).draggable({
+ stack: "#draggable1, #draggable2"
+ });
+
+ TestHelpers.draggable.move( element, 1, 1 );
+ equal( element.css( "zIndex" ), "2", "stack increments zIndex correctly" );
+
+ TestHelpers.draggable.move( element2, 1, 1 );
+ equal( element2.css( "zIndex" ), "3", "stack increments zIndex correctly" );
+});
+
+test( "{ zIndex: 10 }", function() {
+ expect( 1 );
var actual,
expected = 10,
- el = $("#draggable2").draggable({
+ element = $( "#draggable2" ).draggable({
zIndex: expected,
start: function() {
- actual = $(this).css("zIndex");
+ actual = $(this).css( "zIndex" );
}
});
- el.simulate( "drag", {
+ element.simulate( "drag", {
dx: -1,
dy: -1
});
- equal(actual, expected, "start callback: zIndex is");
+ equal( actual, expected, "start callback: zIndex is" );
});
-test( "{ stack }", function() {
- expect( 4 );
+test( "zIndex, default, switching after initialization", function() {
- var draggable1 = $( "#draggable1" ),
- draggable2 = $( "#draggable2" ),
- draggable3 = $( "#draggable3" ),
- draggable4 = $( "#draggable4" );
+ expect( 3 );
- // Set z-index as an inline style.
- $( "#draggable1, #draggable2" )
- .css( "zIndex", 100 )
- .draggable({
- stack: "#draggable1, #draggable2"
- });
- // Have z-index applied via CSS, see #9077
- $( "#draggable3, #draggable4" )
- .draggable({
- stack: "#draggable3, #draggable4"
+ var zindex = null,
+ element = $( "#draggable2" ).draggable({
+ start: function() {
+ zindex = $(this).css( "z-index" );
+ }
});
- draggable1.simulate( "drag", {
- dx: 1,
- dy: 1
- });
- draggable3.simulate( "drag", {
- dx: 1,
- dy: 1
- });
+ element.css( "z-index", 1 );
+
+ TestHelpers.draggable.move( element, 1, 1 );
+ equal( zindex, 1 );
+
+ element.draggable( "option", "zIndex", 5 );
+ TestHelpers.draggable.move( element, 2, 1 );
+ equal( zindex, 5 );
+
+ element.draggable( "option", "zIndex", false );
+ TestHelpers.draggable.move( element, 3, 1 );
+ equal( zindex, 1 );
- equal( draggable1.css( "zIndex" ), 102);
- equal( draggable2.css( "zIndex" ), 101);
- equal( draggable3.css( "zIndex" ), 102);
- equal( draggable4.css( "zIndex" ), 101);
});
-})(jQuery);
+})( jQuery );
diff --git a/tests/unit/draggable/draggable_test_helpers.js b/tests/unit/draggable/draggable_test_helpers.js
index c1ac0ab88..e1c79c6cc 100644
--- a/tests/unit/draggable/draggable_test_helpers.js
+++ b/tests/unit/draggable/draggable_test_helpers.js
@@ -11,7 +11,7 @@ TestHelpers.draggable = {
});
offsetAfter = el.offset();
- actual = { left: offsetAfter.left, top: offsetAfter.top },
+ actual = { left: offsetAfter.left, top: offsetAfter.top };
expected = { left: offsetBefore.left + expectedDX, top: offsetBefore.top + expectedDY };
msg = msg ? msg + "." : "";
@@ -50,5 +50,29 @@ TestHelpers.draggable = {
},
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.on( "drag", function() {
+ el.data( "last_dragged_cursor", $("body").css("cursor") );
+ });
+ },
+ trackAppendedParent : function( el ) {
+
+ // appendTo ignored without being clone
+ el.draggable( "option", "helper", "clone" );
+
+ el.on( "drag", function(e,ui) {
+ // Get what parent is at time of drag
+ el.data( "last_dragged_parent", ui.helper.parent()[0] );
+ });
+
}
}; \ No newline at end of file
diff --git a/tests/unit/sortable/sortable.html b/tests/unit/sortable/sortable.html
index 6e326a865..7db14d482 100644
--- a/tests/unit/sortable/sortable.html
+++ b/tests/unit/sortable/sortable.html
@@ -84,6 +84,13 @@
</tbody>
</table>
+<div id="sortable-images">
+ <img src="../images/jqueryui_32x32.png" alt="">
+ <img src="../images/jqueryui_32x32.png" alt="">
+ <img src="../images/jqueryui_32x32.png" alt="">
+ <img src="../images/jqueryui_32x32.png" alt="">
+</div>
+
</div>
</body>
</html>
diff --git a/tests/unit/sortable/sortable_options.js b/tests/unit/sortable/sortable_options.js
index fe50be002..caba0a777 100644
--- a/tests/unit/sortable/sortable_options.js
+++ b/tests/unit/sortable/sortable_options.js
@@ -5,10 +5,6 @@
module("sortable: options");
-// this is here to make JSHint pass "unused", and we don't want to
-// remove the parameter for when we finally implement
-$.noop();
-
/*
test("{ appendTo: 'parent' }, default", function() {
ok(false, "missing test - untested code is broken code.");
@@ -186,6 +182,23 @@ test("{ placeholder: false }, default", function() {
ok(false, "missing test - untested code is broken code.");
});
*/
+
+test( "{ placeholder: false } img", function() {
+ expect( 3 );
+
+ var element = $( "#sortable-images" ).sortable({
+ start: function( event, ui ) {
+ equal( ui.placeholder.attr( "src" ), "../images/jqueryui_32x32.png", "placeholder img has correct src" );
+ equal( ui.placeholder.height(), 32, "placeholder has correct height" );
+ equal( ui.placeholder.width(), 32, "placeholder has correct width" );
+ }
+ });
+
+ element.find( "img" ).eq( 0 ).simulate( "drag", {
+ dy: 1
+ });
+});
+
test( "{ placeholder: String }", function() {
expect( 1 );