aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/draggable
diff options
context:
space:
mode:
authorFelix Nagel <info@felixnagel.com>2013-04-21 15:10:38 +0200
committerFelix Nagel <info@felixnagel.com>2013-04-21 15:10:38 +0200
commit4efd006e26a6cdc3bf78832c0a0832e7301c841b (patch)
tree5263fe72e9a2784410632d2dee56efd4e58b83f2 /tests/unit/draggable
parent73c7342bc4418a902bf021c89e7d2c43172e004e (diff)
parent71a332e8b83a1657521e04388f5592997e81bbcc (diff)
downloadjquery-ui-4efd006e26a6cdc3bf78832c0a0832e7301c841b.tar.gz
jquery-ui-4efd006e26a6cdc3bf78832c0a0832e7301c841b.zip
Merge branch 'master' into selectmenu
Diffstat (limited to 'tests/unit/draggable')
-rw-r--r--tests/unit/draggable/draggable_core.js85
-rw-r--r--tests/unit/draggable/draggable_options.js44
-rw-r--r--tests/unit/draggable/draggable_test_helpers.js61
3 files changed, 152 insertions, 38 deletions
diff --git a/tests/unit/draggable/draggable_core.js b/tests/unit/draggable/draggable_core.js
index f22d483a6..e7fcdfa87 100644
--- a/tests/unit/draggable/draggable_core.js
+++ b/tests/unit/draggable/draggable_core.js
@@ -75,9 +75,13 @@ test( "resizable handle with complex markup (#8756 / #8757)", function() {
});
test( "#8269: Removing draggable element on drop", function() {
- expect( 1 );
+ expect( 2 );
- var element = $( "#draggable1" ).wrap( "<div id='wrapper' />" ).draggable(),
+ var element = $( "#draggable1" ).wrap( "<div id='wrapper' />" ).draggable({
+ stop: function() {
+ ok( true, "stop still called despite element being removed from DOM on drop" );
+ }
+ }),
dropOffset = $( "#droppable" ).offset();
$( "#droppable" ).droppable({
@@ -87,10 +91,81 @@ test( "#8269: Removing draggable element on drop", function() {
}
});
+ // Support: Opera 12.10, Safari 5.1, jQuery <1.8
+ if ( TestHelpers.draggable.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" );
+ } else {
+ element.simulate( "drag", {
+ handle: "corner",
+ x: dropOffset.left,
+ y: dropOffset.top
+ });
+ }
+});
+
+test( "#6258: not following mouse when scrolled and using overflow-y: scroll", function() {
+ expect( 2 );
+
+ var element = $( "#draggable1" ).draggable({
+ stop: function( event, ui ) {
+ equal( ui.position.left, 1, "left position is correct despite overflow on HTML" );
+ equal( ui.position.top, 1, "top position is correct despite overflow on HTML" );
+ $( "html" )
+ .css( "overflow-y", oldOverflowY )
+ .css( "overflow-x", oldOverflowX )
+ .scrollTop( 0 )
+ .scrollLeft( 0 );
+ }
+ }),
+ contentToForceScroll = $( "<div>" ).css({
+ height: "10000px",
+ width: "10000px"
+ }),
+ oldOverflowY = $( "html" ).css( "overflow-y" ),
+ oldOverflowX = $( "html" ).css( "overflow-x" );
+
+ contentToForceScroll.appendTo( "#qunit-fixture" );
+ $( "html" )
+ .css( "overflow-y", "scroll" )
+ .css( "overflow-x", "scroll" )
+ .scrollTop( 300 )
+ .scrollLeft( 300 );
+
+ element.simulate( "drag", {
+ dx: 1,
+ dy: 1,
+ moves: 1
+ });
+});
+
+test( "#5009: scroll not working with parent's position fixed", function() {
+ expect( 2 );
+
+ var startValue = 300,
+ element = $( "#draggable1" ).wrap( "<div id='wrapper' />" ).draggable({
+ drag: function() {
+ startValue += 100;
+ $( document ).scrollTop( startValue ).scrollLeft( startValue );
+ },
+ stop: function( event, ui ) {
+ equal( ui.position.left, 10, "left position is correct when parent position is fixed" );
+ equal( ui.position.top, 10, "top position is correct when parent position is fixed" );
+ $( document ).scrollTop( 0 ).scrollLeft( 0 );
+ }
+ }),
+ contentToForceScroll = $( "<div>" ).css({
+ height: "20000px",
+ width: "20000px"
+ });
+
+ $( "#qunit-fixture" ).append( contentToForceScroll );
+ $( "#wrapper" ).css( "position", "fixed" );
+
element.simulate( "drag", {
- handle: "corner",
- x: dropOffset.left,
- y: dropOffset.top
+ dx: 10,
+ dy: 10,
+ moves: 3
});
});
diff --git a/tests/unit/draggable/draggable_options.js b/tests/unit/draggable/draggable_options.js
index 6a0cd593b..ef551003d 100644
--- a/tests/unit/draggable/draggable_options.js
+++ b/tests/unit/draggable/draggable_options.js
@@ -451,6 +451,38 @@ test( "{ cursor: 'move' }", function() {
equal( after, before, "after drag: cursor restored" );
});
+test( "#6889: Cursor doesn't revert to pre-dragging state after revert action when original element is removed", function() {
+ function getCursor() {
+ return $( "body" ).css( "cursor" );
+ }
+
+ expect( 2 );
+
+ var element = $( "#draggable1" ).wrap( "<div id='wrapper' />" ).draggable({
+ cursor: "move",
+ revert: true,
+ revertDuration: 0,
+ start: function() {
+ notEqual( getCursor(), expected, "start callback: cursor '" + expected + "'" );
+ $( "#wrapper" ).remove();
+ },
+ stop: function() {
+ equal( getCursor(), expected, "after drag: cursor restored" );
+ }
+ }),
+ expected = getCursor();
+
+ if ( TestHelpers.draggable.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" );
+ } else {
+ element.simulate( "drag", {
+ dx: -1,
+ dy: -1
+ });
+ }
+});
+
test( "cursor, default, switching after initialization", function() {
expect( 3 );
@@ -1289,9 +1321,15 @@ test( "#8459: element can snap to an element that was removed during drag", func
moves: 1
});
- // TODO: fix IE8 testswarm IFRAME positioning bug so closeEnough can be turned back to equal
- closeEnough( element.offset().left, newX, 1, "doesn't snap to a removed element" );
- closeEnough( element.offset().top, newY, 1, "doesn't snap to a removed element" );
+ // Support: Opera 12.10, Safari 5.1, jQuery <1.8
+ if ( TestHelpers.draggable.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" );
+ } else {
+ // TODO: fix IE8 testswarm IFRAME positioning bug so closeEnough can be turned back to equal
+ closeEnough( element.offset().left, newX, 1, "doesn't snap to a removed element" );
+ closeEnough( element.offset().top, newY, 1, "doesn't snap to a removed element" );
+ }
});
test( "#8165: Snapping large rectangles to small rectangles doesn't snap properly", function() {
diff --git a/tests/unit/draggable/draggable_test_helpers.js b/tests/unit/draggable/draggable_test_helpers.js
index 44e37c559..b36505556 100644
--- a/tests/unit/draggable/draggable_test_helpers.js
+++ b/tests/unit/draggable/draggable_test_helpers.js
@@ -1,7 +1,12 @@
TestHelpers.draggable = {
- // todo: remove the unreliable offset hacks
+ // TODO: remove the unreliable offset hacks
unreliableOffset: $.ui.ie && ( !document.documentMode || document.documentMode < 8 ) ? 2 : 0,
- testDrag: function(el, handle, dx, dy, expectedDX, expectedDY, msg) {
+ // Support: Opera 12.10, Safari 5.1, jQuery <1.8
+ unreliableContains: (function(){
+ var element = $( "<div>" );
+ return $.contains( element[ 0 ].ownerDocument, element[ 0 ] );
+ })(),
+ testDrag: function( el, handle, dx, dy, expectedDX, expectedDY, msg ) {
var offsetAfter, actual, expected,
offsetBefore = el.offset();
@@ -15,64 +20,60 @@ TestHelpers.draggable = {
expected = { left: offsetBefore.left + expectedDX, top: offsetBefore.top + expectedDY };
msg = msg ? msg + "." : "";
- deepEqual(actual, expected, "dragged[" + dx + ", " + dy + "] " + msg);
+ deepEqual( actual, expected, "dragged[" + dx + ", " + dy + "] " + msg );
},
- shouldMove: function(el, why) {
- TestHelpers.draggable.testDrag(el, el, 50, 50, 50, 50, why);
+ shouldMove: function( el, why ) {
+ TestHelpers.draggable.testDrag( el, el, 50, 50, 50, 50, why );
},
- shouldNotMove: function(el, why) {
- TestHelpers.draggable.testDrag(el, el, 50, 50, 0, 0, why);
+ shouldNotMove: function( el, why ) {
+ TestHelpers.draggable.testDrag( el, el, 50, 50, 0, 0, why );
},
- testScroll: function(el, position ) {
- var oldPosition = $("#main").css("position");
- $("#main").css("position", position);
- TestHelpers.draggable.shouldMove(el, position+" parent");
- $("#main").css("position", oldPosition);
+ testScroll: function( el, position ) {
+ var oldPosition = $( "#main" ).css( "position" );
+ $( "#main" ).css( "position", position);
+ TestHelpers.draggable.shouldMove( el, position + " parent" );
+ $( "#main" ).css( "position", oldPosition );
},
restoreScroll: function( what ) {
if( what ) {
- $(document).scrollTop(0); $(document).scrollLeft(0);
+ $( document ).scrollTop( 0 ).scrollLeft( 0 );
} else {
- $("#main").scrollTop(0); $("#main").scrollLeft(0);
+ $( "#main" ).scrollTop( 0 ).scrollLeft( 0 );
}
},
setScroll: function( what ) {
- if(what) {
- // todo: currently, the draggable interaction doesn't properly account for scrolled pages,
+ if( what ) {
+ // TODO: currently, the draggable interaction doesn't properly account for scrolled pages,
// uncomment the line below to make the tests fail that should when the page is scrolled
- // $(document).scrollTop(100); $(document).scrollLeft(100);
+ // $( document ).scrollTop( 100 ).scrollLeft( 100 );
} else {
- $("#main").scrollTop(100); $("#main").scrollLeft(100);
+ $( "#main" ).scrollTop( 100 ).scrollLeft( 100 );
}
},
- border: function(el, side) {
- return parseInt(el.css("border-" + side + "-width"), 10) || 0;
+ border: function( el, side ) {
+ return parseInt( el.css( "border-" + side + "-width" ), 10 ) || 0;
},
- margin: function(el, side) {
- return parseInt(el.css("margin-" + side), 10) || 0;
+ margin: function( el, side ) {
+ return parseInt( el.css( "margin-" + side ), 10 ) || 0;
},
move: function( el, x, y ) {
-
$( el ).simulate( "drag", {
dx: x,
dy: y
});
-
},
trackMouseCss : function( el ) {
el.bind( "drag", function() {
- el.data( "last_dragged_cursor", $("body").css("cursor") );
+ el.data( "last_dragged_cursor", $( "body" ).css( "cursor" ) );
});
},
trackAppendedParent : function( el ) {
-
- // appendTo ignored without being clone
+ // TODO: appendTo is currently ignored if helper is original (see #7044)
el.draggable( "option", "helper", "clone" );
+ // Get what parent is at time of drag
el.bind( "drag", function(e,ui) {
- // Get what parent is at time of drag
- el.data( "last_dragged_parent", ui.helper.parent()[0] );
+ el.data( "last_dragged_parent", ui.helper.parent()[ 0 ] );
});
-
}
}; \ No newline at end of file