Draggable Tests: Cover all cursorAt option formats.

This commit is contained in:
Mike Sherov 2013-01-01 23:16:12 -05:00
parent 695358983e
commit 18b8ffd796

View File

@ -270,22 +270,16 @@ test("{ cursor: 'move' }", function() {
}); });
/* test( "cursorAt", function() {
test("{ cursorAt: false}, default", function() { expect( 24 );
expect( 1 );
ok(false, "missing test - untested code is broken code");
});
*/
test( "{ cursorAt: left, top }", function() {
expect( 16 );
var deltaX = -3, var deltaX = -3,
deltaY = -3, deltaY = -3,
tests = { tests = {
"false": { cursorAt : false },
"{ left: -5, top: -5 }": { x: -5, y: -5, cursorAt : { left: -5, top: -5 } }, "{ 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 ] },
"'10 20'": { x: 10, y: 20, cursorAt : "10 20" },
"{ left: 20, top: 40 }": { x: 20, y: 40, cursorAt : { left: 20, top: 40 } }, "{ 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 } } "{ right: 10, bottom: 20 }": { x: 10, y: 20, cursorAt : { right: 10, bottom: 20 } }
}; };
@ -295,9 +289,12 @@ test( "{ cursorAt: left, top }", function() {
var el = $( "#draggable" + ( i + 1 ) ).draggable({ var el = $( "#draggable" + ( i + 1 ) ).draggable({
cursorAt: testData.cursorAt, cursorAt: testData.cursorAt,
drag: function( event, ui ) { drag: function( event, ui ) {
if( testData.cursorAt.right ) { 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.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" ); equal( ui.helper.height() - ( event.clientY - ui.offset.top ), testData.y - TestHelpers.draggable.unreliableOffset, testName + " " +position + " top" );
} else { } else {
equal( event.clientX - ui.offset.left, testData.x + TestHelpers.draggable.unreliableOffset, testName + " " + position + " left" ); equal( event.clientX - ui.offset.left, testData.x + TestHelpers.draggable.unreliableOffset, testName + " " + position + " left" );
equal( event.clientY - ui.offset.top, testData.y + TestHelpers.draggable.unreliableOffset, testName + " " + position + " top" ); equal( event.clientY - ui.offset.top, testData.y + TestHelpers.draggable.unreliableOffset, testName + " " + position + " top" );