From 49c3fb74039d9e840125c20e27edf52b98cc2609 Mon Sep 17 00:00:00 2001 From: Dave Stein Date: Fri, 22 Aug 2014 11:51:15 -0400 Subject: [PATCH] Draggable Tests: Ensure scrolling and dragging tests assert correctly --- tests/unit/draggable/draggable_core.js | 5 +++-- tests/unit/draggable/draggable_methods.js | 4 ++-- tests/unit/draggable/draggable_options.js | 12 ++++++------ tests/unit/draggable/draggable_test_helpers.js | 18 ++++++++++++++++-- tests/unit/testsuite.js | 6 ++++-- 5 files changed, 31 insertions(+), 14 deletions(-) diff --git a/tests/unit/draggable/draggable_core.js b/tests/unit/draggable/draggable_core.js index def1526e5..de88b1947 100644 --- a/tests/unit/draggable/draggable_core.js +++ b/tests/unit/draggable/draggable_core.js @@ -344,7 +344,7 @@ test( "ui-draggable-handle managed correctly in nested draggables", function() { // http://bugs.jqueryui.com/ticket/7772 // when css 'right' is set, element resizes on drag test( "setting right/bottom css shouldn't cause resize", function() { - expect( 3 ); + expect( 4 ); var finalOffset, element = $( "#draggable3" ), @@ -362,7 +362,8 @@ test( "setting right/bottom css shouldn't cause resize", function() { closeEnough( element.width(), origWidth, 1, "element retains width" ); closeEnough( element.height(), origHeight, 1, "element retains height" ); - deepEqual( finalOffset, origOffset, "element moves the correct distance" ); + closeEnough( finalOffset.top, origOffset.top, "element moves the correct vertical distance" ); + closeEnough( finalOffset.top, origOffset.top, "element moves the correct horizontal distance" ); }); })( jQuery ); diff --git a/tests/unit/draggable/draggable_methods.js b/tests/unit/draggable/draggable_methods.js index 3f659e4ef..351d57764 100644 --- a/tests/unit/draggable/draggable_methods.js +++ b/tests/unit/draggable/draggable_methods.js @@ -51,7 +51,7 @@ test( "destroy", function() { }); test( "enable", function() { - expect( 7 ); + expect( 11 ); element.draggable({ disabled: true }); TestHelpers.draggable.shouldNotDrag( element, ".draggable({ disabled: true })" ); @@ -74,7 +74,7 @@ test( "enable", function() { }); test( "disable", function() { - expect( 10 ); + expect( 14 ); element = $( "#draggable2" ).draggable({ disabled: false }); TestHelpers.draggable.shouldMove( element, ".draggable({ disabled: false })" ); diff --git a/tests/unit/draggable/draggable_options.js b/tests/unit/draggable/draggable_options.js index 8f4bd3bbb..abce62a46 100644 --- a/tests/unit/draggable/draggable_options.js +++ b/tests/unit/draggable/draggable_options.js @@ -156,7 +156,7 @@ test( "axis, default, switching after initialization", function() { }); test( "{ cancel: 'input,textarea,button,select,option' }, default", function() { - expect( 2 ); + expect( 4 ); $( "
" ).appendTo( "#qunit-fixture" ); @@ -171,7 +171,7 @@ test( "{ cancel: 'input,textarea,button,select,option' }, default", function() { }); test( "{ cancel: 'span' }", function() { - expect( 2 ); + expect( 4 ); var element = $( "#draggable2" ).draggable(); TestHelpers.draggable.shouldMove( element, "cancel: default, span dragged", "#draggable2 span" ); @@ -228,7 +228,7 @@ test( "{ cancel: Selectors }, matching parent selector", function() { */ test( "cancelement, default, switching after initialization", function() { - expect( 2 ); + expect( 6 ); $( "
" ).appendTo( "#qunit-fixture" ); @@ -615,7 +615,7 @@ test( "cursorAt, switching after initialization", function() { }); test( "disabled", function() { - expect( 4 ); + expect( 6 ); var element = $( "#draggable1" ).draggable(); @@ -660,7 +660,7 @@ test( "grid, switching after initialization", function() { }); test( "{ handle: 'span' }", function() { - expect( 4 ); + expect( 6 ); var element = $( "#draggable2" ).draggable({ handle: "span" }); @@ -670,7 +670,7 @@ test( "{ handle: 'span' }", function() { }); test( "handle, default, switching after initialization", function() { - expect( 10 ); + expect( 12 ); var element = $( "#draggable2" ).draggable(); diff --git a/tests/unit/draggable/draggable_test_helpers.js b/tests/unit/draggable/draggable_test_helpers.js index a0fdccfca..1b004e7cf 100644 --- a/tests/unit/draggable/draggable_test_helpers.js +++ b/tests/unit/draggable/draggable_test_helpers.js @@ -63,14 +63,28 @@ TestHelpers.draggable = { }, shouldNotDrag: function( el, msg, handle ) { handle = handle || el; - $( el ).bind( "dragstop", function() { + + var newOffset, + element = $( el ), + beginOffset = element.offset(); + + element.bind( "dragstop", function() { ok( false, "should not drag " + msg ); }); + $( handle ).simulate( "drag", { dx: 100, dy: 100 }); - $( el ).unbind( "dragstop" ); + + newOffset = element.offset(); + + // Also assert that draggable did not move, to ensure it isn't just + // that drag did not fire and draggable still somehow moved + equal( newOffset.left, beginOffset.left, "Offset left should not be different" ); + equal( newOffset.top, beginOffset.top, "Offset top should not be different" ); + + element.unbind( "dragstop" ); }, setScrollable: function( what, isScrollable ) { var overflow = isScrollable ? "scroll" : "hidden"; diff --git a/tests/unit/testsuite.js b/tests/unit/testsuite.js index 9dd0b04ab..cb5397d57 100644 --- a/tests/unit/testsuite.js +++ b/tests/unit/testsuite.js @@ -205,9 +205,11 @@ TestHelpers.onFocus= function( element, onFocus ) { }; TestHelpers.forceScrollableWindow = function( appendTo ) { + // The main testable area is 10000x10000 so to enforce scrolling, + // this DIV must be greater than 10000 to work return $( "
" ).css({ - height: "10000px", - width: "10000px" + height: "11000px", + width: "11000px" }).appendTo( appendTo || "#qunit-fixture" ); }; -- 2.39.5