Draggable Tests: Ensure scrolling and dragging tests assert correctly

This commit is contained in:
Dave Stein 2014-08-22 11:51:15 -04:00 committed by Mike Sherov
parent aa425ab95d
commit 49c3fb7403
5 changed files with 31 additions and 14 deletions

View File

@ -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 );

View File

@ -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 })" );

View File

@ -156,7 +156,7 @@ test( "axis, default, switching after initialization", function() {
});
test( "{ cancel: 'input,textarea,button,select,option' }, default", function() {
expect( 2 );
expect( 4 );
$( "<div id='draggable-option-cancel-default'><input type='text'></div>" ).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 );
$( "<div id='draggable-option-cancel-default'><input type='text'></div>" ).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();

View File

@ -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";

View File

@ -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 $( "<div>" ).css({
height: "10000px",
width: "10000px"
height: "11000px",
width: "11000px"
}).appendTo( appendTo || "#qunit-fixture" );
};