Sortable: Shift to use no globals

This commit is contained in:
Amanpreet Singh 2016-04-06 18:52:59 +05:30
parent 38d473708b
commit 749f95ee0a
5 changed files with 204 additions and 199 deletions

View File

@ -1,23 +1,24 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"./helper", "./helper",
"ui/widgets/sortable" "ui/widgets/sortable"
], function( $, testHelper ) { ], function( QUnit, $, testHelper ) {
module( "sortable: core" ); QUnit.module( "sortable: core" );
test( "#9314: Sortable: Items cannot be dragged directly into bottom position", function() { QUnit.test( "#9314: Sortable: Items cannot be dragged directly into bottom position", function( assert ) {
expect( 1 ); assert.expect( 1 );
var el = $( ".connectWith" ).sortable( { var el = $( ".connectWith" ).sortable( {
connectWith: ".connectWith" connectWith: ".connectWith"
} ); } );
testHelper.sort( $( "li", el[ 1 ] )[ 0 ], 0, -12, 5, "Dragging the sortable into connected sortable" ); testHelper.sort( assert, $( "li", el[ 1 ] )[ 0 ], 0, -12, 5, "Dragging the sortable into connected sortable" );
} ); } );
test( "ui-sortable-handle applied to appropriate element", function( assert ) { QUnit.test( "ui-sortable-handle applied to appropriate element", function( assert ) {
expect( 8 ); assert.expect( 8 );
var item = "<li><p></p></li>", var item = "<li><p></p></li>",
el = $( "<ul>" + item + item + "</ul>" ) el = $( "<ul>" + item + item + "</ul>" )
.sortable() .sortable()
@ -36,7 +37,7 @@ test( "ui-sortable-handle applied to appropriate element", function( assert ) {
assert.hasClasses( el.find( "p:last" ), "ui-sortable-handle" ); assert.hasClasses( el.find( "p:last" ), "ui-sortable-handle" );
el.sortable( "destroy" ); el.sortable( "destroy" );
equal( el.find( ".ui-sortable-handle" ).length, 0, "class name removed on destroy" ); assert.equal( el.find( ".ui-sortable-handle" ).length, 0, "class name removed on destroy" );
} ); } );
} ); } );

View File

@ -1,14 +1,15 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"./helper", "./helper",
"ui/widgets/sortable", "ui/widgets/sortable",
"ui/widgets/draggable" "ui/widgets/draggable"
], function( $, testHelper ) { ], function( QUnit, $, testHelper ) {
module( "sortable: events" ); QUnit.module( "sortable: events" );
test( "start", function() { QUnit.test( "start", function( assert ) {
expect( 7 ); assert.expect( 7 );
var hash; var hash;
$( "#sortable" ).sortable( { $( "#sortable" ).sortable( {
@ -19,19 +20,19 @@ test( "start", function() {
dy: 10 dy: 10
} ); } );
ok( hash, "start event triggered" ); assert.ok( hash, "start event triggered" );
ok( hash.helper, "UI hash includes: helper" ); assert.ok( hash.helper, "UI hash includes: helper" );
ok( hash.placeholder, "UI hash includes: placeholder" ); assert.ok( hash.placeholder, "UI hash includes: placeholder" );
ok( hash.item, "UI hash includes: item" ); assert.ok( hash.item, "UI hash includes: item" );
ok( !hash.sender, "UI hash does not include: sender" ); assert.ok( !hash.sender, "UI hash does not include: sender" );
// Todo: see if these events should actually have sane values in them // Todo: see if these events should actually have sane values in them
ok( "position" in hash, "UI hash includes: position" ); assert.ok( "position" in hash, "UI hash includes: position" );
ok( "offset" in hash, "UI hash includes: offset" ); assert.ok( "offset" in hash, "UI hash includes: offset" );
} ); } );
test( "sort", function() { QUnit.test( "sort", function( assert ) {
expect( 7 ); assert.expect( 7 );
var hash; var hash;
$( "#sortable" ).sortable( { $( "#sortable" ).sortable( {
@ -42,18 +43,18 @@ test( "sort", function() {
dy: 10 dy: 10
} ); } );
ok( hash, "sort event triggered" ); assert.ok( hash, "sort event triggered" );
ok( hash.helper, "UI hash includes: helper" ); assert.ok( hash.helper, "UI hash includes: helper" );
ok( hash.placeholder, "UI hash includes: placeholder" ); assert.ok( hash.placeholder, "UI hash includes: placeholder" );
ok( hash.position && ( "top" in hash.position && "left" in hash.position ), "UI hash includes: position" ); assert.ok( hash.position && ( "top" in hash.position && "left" in hash.position ), "UI hash includes: position" );
ok( hash.offset && ( hash.offset.top && hash.offset.left ), "UI hash includes: offset" ); assert.ok( hash.offset && ( hash.offset.top && hash.offset.left ), "UI hash includes: offset" );
ok( hash.item, "UI hash includes: item" ); assert.ok( hash.item, "UI hash includes: item" );
ok( !hash.sender, "UI hash does not include: sender" ); assert.ok( !hash.sender, "UI hash does not include: sender" );
} ); } );
test( "change", function() { QUnit.test( "change", function( assert ) {
expect( 8 ); assert.expect( 8 );
var hash; var hash;
$( "#sortable" ).sortable( { $( "#sortable" ).sortable( {
@ -65,7 +66,7 @@ test( "change", function() {
dy: 1 dy: 1
} ); } );
ok( !hash, "1px drag, change event should not be triggered" ); assert.ok( !hash, "1px drag, change event should not be triggered" );
$( "#sortable" ).sortable( { $( "#sortable" ).sortable( {
change: function( e, ui ) { change: function( e, ui ) {
@ -75,18 +76,18 @@ test( "change", function() {
dy: 22 dy: 22
} ); } );
ok( hash, "change event triggered" ); assert.ok( hash, "change event triggered" );
ok( hash.helper, "UI hash includes: helper" ); assert.ok( hash.helper, "UI hash includes: helper" );
ok( hash.placeholder, "UI hash includes: placeholder" ); assert.ok( hash.placeholder, "UI hash includes: placeholder" );
ok( hash.position && ( "top" in hash.position && "left" in hash.position ), "UI hash includes: position" ); assert.ok( hash.position && ( "top" in hash.position && "left" in hash.position ), "UI hash includes: position" );
ok( hash.offset && ( hash.offset.top && hash.offset.left ), "UI hash includes: offset" ); assert.ok( hash.offset && ( hash.offset.top && hash.offset.left ), "UI hash includes: offset" );
ok( hash.item, "UI hash includes: item" ); assert.ok( hash.item, "UI hash includes: item" );
ok( !hash.sender, "UI hash does not include: sender" ); assert.ok( !hash.sender, "UI hash does not include: sender" );
} ); } );
test( "beforeStop", function() { QUnit.test( "beforeStop", function( assert ) {
expect( 7 ); assert.expect( 7 );
var hash; var hash;
$( "#sortable" ).sortable( { $( "#sortable" ).sortable( {
@ -97,18 +98,18 @@ test( "beforeStop", function() {
dy: 20 dy: 20
} ); } );
ok( hash, "beforeStop event triggered" ); assert.ok( hash, "beforeStop event triggered" );
ok( hash.helper, "UI hash includes: helper" ); assert.ok( hash.helper, "UI hash includes: helper" );
ok( hash.placeholder, "UI hash includes: placeholder" ); assert.ok( hash.placeholder, "UI hash includes: placeholder" );
ok( hash.position && ( "top" in hash.position && "left" in hash.position ), "UI hash includes: position" ); assert.ok( hash.position && ( "top" in hash.position && "left" in hash.position ), "UI hash includes: position" );
ok( hash.offset && ( hash.offset.top && hash.offset.left ), "UI hash includes: offset" ); assert.ok( hash.offset && ( hash.offset.top && hash.offset.left ), "UI hash includes: offset" );
ok( hash.item, "UI hash includes: item" ); assert.ok( hash.item, "UI hash includes: item" );
ok( !hash.sender, "UI hash does not include: sender" ); assert.ok( !hash.sender, "UI hash does not include: sender" );
} ); } );
test( "stop", function() { QUnit.test( "stop", function( assert ) {
expect( 7 ); assert.expect( 7 );
var hash; var hash;
$( "#sortable" ).sortable( { $( "#sortable" ).sortable( {
@ -119,18 +120,18 @@ test( "stop", function() {
dy: 20 dy: 20
} ); } );
ok( hash, "stop event triggered" ); assert.ok( hash, "stop event triggered" );
ok( !hash.helper, "UI should not include: helper" ); assert.ok( !hash.helper, "UI should not include: helper" );
ok( hash.placeholder, "UI hash includes: placeholder" ); assert.ok( hash.placeholder, "UI hash includes: placeholder" );
ok( hash.position && ( "top" in hash.position && "left" in hash.position ), "UI hash includes: position" ); assert.ok( hash.position && ( "top" in hash.position && "left" in hash.position ), "UI hash includes: position" );
ok( hash.offset && ( hash.offset.top && hash.offset.left ), "UI hash includes: offset" ); assert.ok( hash.offset && ( hash.offset.top && hash.offset.left ), "UI hash includes: offset" );
ok( hash.item, "UI hash includes: item" ); assert.ok( hash.item, "UI hash includes: item" );
ok( !hash.sender, "UI hash does not include: sender" ); assert.ok( !hash.sender, "UI hash does not include: sender" );
} ); } );
test( "update", function() { QUnit.test( "update", function( assert ) {
expect( 8 ); assert.expect( 8 );
var hash; var hash;
$( "#sortable" ).sortable( { $( "#sortable" ).sortable( {
@ -142,7 +143,7 @@ test( "update", function() {
dy: 1 dy: 1
} ); } );
ok( !hash, "1px drag, update event should not be triggered" ); assert.ok( !hash, "1px drag, update event should not be triggered" );
$( "#sortable" ).sortable( { $( "#sortable" ).sortable( {
update: function( e, ui ) { update: function( e, ui ) {
@ -152,18 +153,18 @@ test( "update", function() {
dy: 22 dy: 22
} ); } );
ok( hash, "update event triggered" ); assert.ok( hash, "update event triggered" );
ok( !hash.helper, "UI hash should not include: helper" ); assert.ok( !hash.helper, "UI hash should not include: helper" );
ok( hash.placeholder, "UI hash includes: placeholder" ); assert.ok( hash.placeholder, "UI hash includes: placeholder" );
ok( hash.position && ( "top" in hash.position && "left" in hash.position ), "UI hash includes: position" ); assert.ok( hash.position && ( "top" in hash.position && "left" in hash.position ), "UI hash includes: position" );
ok( hash.offset && ( hash.offset.top && hash.offset.left ), "UI hash includes: offset" ); assert.ok( hash.offset && ( hash.offset.top && hash.offset.left ), "UI hash includes: offset" );
ok( hash.item, "UI hash includes: item" ); assert.ok( hash.item, "UI hash includes: item" );
ok( !hash.sender, "UI hash does not include: sender" ); assert.ok( !hash.sender, "UI hash does not include: sender" );
} ); } );
test( "#3019: Stop fires too early", function() { QUnit.test( "#3019: Stop fires too early", function( assert ) {
expect( 2 ); assert.expect( 2 );
var helper = null, var helper = null,
el = $( "#sortable" ).sortable( { el = $( "#sortable" ).sortable( {
@ -172,13 +173,13 @@ test( "#3019: Stop fires too early", function() {
} }
} ); } );
testHelper.sort( $( "li", el )[ 0 ], 0, 44, 2, "Dragging the sortable" ); testHelper.sort( assert, $( "li", el )[ 0 ], 0, 44, 2, "Dragging the sortable" );
equal( helper, null, "helper should be false" ); assert.equal( helper, null, "helper should be false" );
} ); } );
test( "#4752: link event firing on sortable with connect list", function() { QUnit.test( "#4752: link event firing on sortable with connect list", function( assert ) {
expect( 10 ); assert.expect( 10 );
var fired = {}, var fired = {},
hasFired = function( type ) { return ( type in fired ) && ( true === fired[ type ] ); }; hasFired = function( type ) { return ( type in fired ) && ( true === fired[ type ] ); };
@ -203,28 +204,28 @@ test( "#4752: link event firing on sortable with connect list", function() {
} ); } );
$( "#sortable li:eq(0)" ).simulate( "click" ); $( "#sortable li:eq(0)" ).simulate( "click" );
ok( !hasFired( "change" ), "Click only, change event should not have fired" ); assert.ok( !hasFired( "change" ), "Click only, change event should not have fired" );
ok( hasFired( "click" ), "Click event should have fired" ); assert.ok( hasFired( "click" ), "Click event should have fired" );
// Drag an item within the first list // Drag an item within the first list
fired = {}; fired = {};
$( "#sortable li:eq(0)" ).simulate( "drag", { dx: 0, dy: 40 } ); $( "#sortable li:eq(0)" ).simulate( "drag", { dx: 0, dy: 40 } );
ok( hasFired( "change" ), "40px drag, change event should have fired" ); assert.ok( hasFired( "change" ), "40px drag, change event should have fired" );
ok( !hasFired( "receive" ), "Receive event should not have fired" ); assert.ok( !hasFired( "receive" ), "Receive event should not have fired" );
ok( !hasFired( "remove" ), "Remove event should not have fired" ); assert.ok( !hasFired( "remove" ), "Remove event should not have fired" );
ok( !hasFired( "click" ), "Click event should not have fired" ); assert.ok( !hasFired( "click" ), "Click event should not have fired" );
// Drag an item from the first list to the second, connected list // Drag an item from the first list to the second, connected list
fired = {}; fired = {};
$( "#sortable li:eq(0)" ).simulate( "drag", { dx: 0, dy: 150 } ); $( "#sortable li:eq(0)" ).simulate( "drag", { dx: 0, dy: 150 } );
ok( hasFired( "change" ), "150px drag, change event should have fired" ); assert.ok( hasFired( "change" ), "150px drag, change event should have fired" );
ok( hasFired( "receive" ), "Receive event should have fired" ); assert.ok( hasFired( "receive" ), "Receive event should have fired" );
ok( hasFired( "remove" ), "Remove event should have fired" ); assert.ok( hasFired( "remove" ), "Remove event should have fired" );
ok( !hasFired( "click" ), "Click event should not have fired" ); assert.ok( !hasFired( "click" ), "Click event should not have fired" );
} ); } );
/* /*
test("receive", function() { Test("receive", function() {
ok(false, "missing test - untested code is broken code."); ok(false, "missing test - untested code is broken code.");
}); });
@ -233,8 +234,8 @@ test("remove", function() {
}); });
*/ */
test( "over", function() { QUnit.test( "over", function( assert ) {
expect( 8 ); assert.expect( 8 );
var hash, var hash,
overCount = 0; overCount = 0;
@ -248,20 +249,20 @@ test( "over", function() {
dy: 20 dy: 20
} ); } );
ok( hash, "over event triggered" ); assert.ok( hash, "over event triggered" );
ok( hash.helper, "UI includes: helper" ); assert.ok( hash.helper, "UI includes: helper" );
ok( hash.placeholder, "UI hash includes: placeholder" ); assert.ok( hash.placeholder, "UI hash includes: placeholder" );
ok( hash.position && ( "top" in hash.position && "left" in hash.position ), "UI hash includes: position" ); assert.ok( hash.position && ( "top" in hash.position && "left" in hash.position ), "UI hash includes: position" );
ok( hash.offset && ( hash.offset.top && hash.offset.left ), "UI hash includes: offset" ); assert.ok( hash.offset && ( hash.offset.top && hash.offset.left ), "UI hash includes: offset" );
ok( hash.item, "UI hash includes: item" ); assert.ok( hash.item, "UI hash includes: item" );
ok( hash.sender, "UI hash includes: sender" ); assert.ok( hash.sender, "UI hash includes: sender" );
equal( overCount, 1, "over fires only once" ); assert.equal( overCount, 1, "over fires only once" );
} ); } );
// http://bugs.jqueryui.com/ticket/9335 // http://bugs.jqueryui.com/ticket/9335
// Sortable: over & out events does not consistently fire // Sortable: over & out events does not consistently fire
test( "over, fires with draggable connected to sortable", function() { QUnit.test( "over, fires with draggable connected to sortable", function( assert ) {
expect( 3 ); assert.expect( 3 );
var hash, var hash,
overCount = 0, overCount = 0,
@ -282,13 +283,13 @@ test( "over, fires with draggable connected to sortable", function() {
dy: -20 dy: -20
} ); } );
ok( hash, "over event triggered" ); assert.ok( hash, "over event triggered" );
ok( !hash.sender, "UI should not include: sender" ); assert.ok( !hash.sender, "UI should not include: sender" );
equal( overCount, 1, "over fires only once" ); assert.equal( overCount, 1, "over fires only once" );
} ); } );
test( "over, with connected sortable", function() { QUnit.test( "over, with connected sortable", function( assert ) {
expect( 3 ); assert.expect( 3 );
var hash, var hash,
overCount = 0; overCount = 0;
@ -304,19 +305,19 @@ test( "over, with connected sortable", function() {
dy: 102 dy: 102
} ); } );
ok( hash, "over event triggered" ); assert.ok( hash, "over event triggered" );
equal( hash.sender[ 0 ], $( " #sortable" )[ 0 ], "UI includes: sender" ); assert.equal( hash.sender[ 0 ], $( " #sortable" )[ 0 ], "UI includes: sender" );
equal( overCount, 1, "over fires only once" ); assert.equal( overCount, 1, "over fires only once" );
} ); } );
/* /*
test("out", function() { Test("out", function() {
ok(false, "missing test - untested code is broken code."); ok(false, "missing test - untested code is broken code.");
}); });
*/ */
test( "out, with connected sortable", function() { QUnit.test( "out, with connected sortable", function( assert ) {
expect( 2 ); assert.expect( 2 );
var hash, var hash,
outCount = 0; outCount = 0;
@ -332,12 +333,12 @@ test( "out, with connected sortable", function() {
dy: 40 dy: 40
} ); } );
ok( hash, "out event triggered" ); assert.ok( hash, "out event triggered" );
equal( outCount, 1, "out fires only once" ); assert.equal( outCount, 1, "out fires only once" );
} ); } );
test( "repeated out & over between connected sortables", function() { QUnit.test( "repeated out & over between connected sortables", function( assert ) {
expect( 2 ); assert.expect( 2 );
var outCount = 0, var outCount = 0,
overCount = 0; overCount = 0;
@ -362,12 +363,12 @@ test( "repeated out & over between connected sortables", function() {
dy: -40 dy: -40
} ); } );
equal( outCount, 2, "out fires twice" ); assert.equal( outCount, 2, "out fires twice" );
equal( overCount, 4, "over fires four times" ); assert.equal( overCount, 4, "over fires four times" );
} ); } );
/* /*
test("activate", function() { Test("activate", function() {
ok(false, "missing test - untested code is broken code."); ok(false, "missing test - untested code is broken code.");
}); });

View File

@ -4,12 +4,12 @@ define( [
], function( $, helper ) { ], function( $, helper ) {
return $.extend( helper, { return $.extend( helper, {
sort: function( handle, dx, dy, index, msg ) { sort: function( assert, handle, dx, dy, index, msg ) {
$( handle ).simulate( "drag", { $( handle ).simulate( "drag", {
dx: dx, dx: dx,
dy: dy dy: dy
} ); } );
equal( $( handle ).parent().children().index( handle ), index, msg ); assert.equal( $( handle ).parent().children().index( handle ), index, msg );
} }
} ); } );

View File

@ -1,98 +1,99 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"./helper", "./helper",
"ui/widgets/sortable" "ui/widgets/sortable"
], function( $, testHelper ) { ], function( QUnit, $, testHelper ) {
module( "sortable: methods" ); QUnit.module( "sortable: methods" );
test( "init", function() { QUnit.test( "init", function( assert ) {
expect( 5 ); assert.expect( 5 );
$( "<div></div>" ).appendTo( "body" ).sortable().remove(); $( "<div></div>" ).appendTo( "body" ).sortable().remove();
ok( true, ".sortable() called on element" ); assert.ok( true, ".sortable() called on element" );
$( [] ).sortable(); $( [] ).sortable();
ok( true, ".sortable() called on empty collection" ); assert.ok( true, ".sortable() called on empty collection" );
$( "<div></div>" ).sortable(); $( "<div></div>" ).sortable();
ok( true, ".sortable() called on disconnected DOMElement" ); assert.ok( true, ".sortable() called on disconnected DOMElement" );
$( "<div></div>" ).sortable().sortable( "option", "foo" ); $( "<div></div>" ).sortable().sortable( "option", "foo" );
ok( true, "arbitrary option getter after init" ); assert.ok( true, "arbitrary option getter after init" );
$( "<div></div>" ).sortable().sortable( "option", "foo", "bar" ); $( "<div></div>" ).sortable().sortable( "option", "foo", "bar" );
ok( true, "arbitrary option setter after init" ); assert.ok( true, "arbitrary option setter after init" );
} ); } );
test( "destroy", function() { QUnit.test( "destroy", function( assert ) {
expect( 4 ); assert.expect( 4 );
$( "<div></div>" ).appendTo( "body" ).sortable().sortable( "destroy" ).remove(); $( "<div></div>" ).appendTo( "body" ).sortable().sortable( "destroy" ).remove();
ok( true, ".sortable('destroy') called on element" ); assert.ok( true, ".sortable('destroy') called on element" );
$( [] ).sortable().sortable( "destroy" ); $( [] ).sortable().sortable( "destroy" );
ok( true, ".sortable('destroy') called on empty collection" ); assert.ok( true, ".sortable('destroy') called on empty collection" );
$( "<div></div>" ).sortable().sortable( "destroy" ); $( "<div></div>" ).sortable().sortable( "destroy" );
ok( true, ".sortable('destroy') called on disconnected DOMElement" ); assert.ok( true, ".sortable('destroy') called on disconnected DOMElement" );
var expected = $( "<div></div>" ).sortable(), var expected = $( "<div></div>" ).sortable(),
actual = expected.sortable( "destroy" ); actual = expected.sortable( "destroy" );
equal( actual, expected, "destroy is chainable" ); assert.equal( actual, expected, "destroy is chainable" );
} ); } );
test( "enable", function() { QUnit.test( "enable", function( assert ) {
expect( 5 ); assert.expect( 5 );
var el, actual, expected; var el, actual, expected;
el = $( "#sortable" ).sortable( { disabled: true } ); el = $( "#sortable" ).sortable( { disabled: true } );
testHelper.sort( $( "li", el )[ 0 ], 0, 44, 0, ".sortable({ disabled: true })" ); testHelper.sort( assert, $( "li", el )[ 0 ], 0, 44, 0, ".sortable({ disabled: true })" );
el.sortable( "enable" ); el.sortable( "enable" );
equal( el.sortable( "option", "disabled" ), false, "disabled option getter" ); assert.equal( el.sortable( "option", "disabled" ), false, "disabled option getter" );
el.sortable( "destroy" ); el.sortable( "destroy" );
el.sortable( { disabled: true } ); el.sortable( { disabled: true } );
el.sortable( "option", "disabled", false ); el.sortable( "option", "disabled", false );
equal( el.sortable( "option", "disabled" ), false, "disabled option setter" ); assert.equal( el.sortable( "option", "disabled" ), false, "disabled option setter" );
testHelper.sort( $( "li", el )[ 0 ], 0, 44, 2, ".sortable('option', 'disabled', false)" ); testHelper.sort( assert, $( "li", el )[ 0 ], 0, 44, 2, ".sortable('option', 'disabled', false)" );
expected = $( "<div></div>" ).sortable(), expected = $( "<div></div>" ).sortable(),
actual = expected.sortable( "enable" ); actual = expected.sortable( "enable" );
equal( actual, expected, "enable is chainable" ); assert.equal( actual, expected, "enable is chainable" );
} ); } );
test( "disable", function( assert ) { QUnit.test( "disable", function( assert ) {
expect( 9 ); assert.expect( 9 );
var chainable, var chainable,
element = $( "#sortable" ).sortable( { disabled: false } ); element = $( "#sortable" ).sortable( { disabled: false } );
testHelper.sort( $( "li", element )[ 0 ], 0, 44, 2, ".sortable({ disabled: false })" ); testHelper.sort( assert, $( "li", element )[ 0 ], 0, 44, 2, ".sortable({ disabled: false })" );
chainable = element.sortable( "disable" ); chainable = element.sortable( "disable" );
testHelper.sort( $( "li", element )[ 0 ], 0, 44, 0, "disabled.sortable getter" ); testHelper.sort( assert, $( "li", element )[ 0 ], 0, 44, 0, "disabled.sortable getter" );
element.sortable( "destroy" ); element.sortable( "destroy" );
element.sortable( { disabled: false } ); element.sortable( { disabled: false } );
testHelper.sort( $( "li", element )[ 0 ], 0, 44, 2, ".sortable({ disabled: false })" ); testHelper.sort( assert, $( "li", element )[ 0 ], 0, 44, 2, ".sortable({ disabled: false })" );
element.sortable( "option", "disabled", true ); element.sortable( "option", "disabled", true );
equal( element.sortable( "option", "disabled" ), true, "disabled option setter" ); assert.equal( element.sortable( "option", "disabled" ), true, "disabled option setter" );
assert.lacksClasses( element.sortable( "widget" ), "ui-state-disabled" ); assert.lacksClasses( element.sortable( "widget" ), "ui-state-disabled" );
ok( !element.sortable( "widget" ).attr( "aria-disabled" ), "element does not get aria-disabled" ); assert.ok( !element.sortable( "widget" ).attr( "aria-disabled" ), "element does not get aria-disabled" );
assert.hasClasses( element.sortable( "widget" ), "ui-sortable-disabled" ); assert.hasClasses( element.sortable( "widget" ), "ui-sortable-disabled" );
testHelper.sort( $( "li", element )[ 0 ], 0, 44, 0, ".sortable('option', 'disabled', true)" ); testHelper.sort( assert, $( "li", element )[ 0 ], 0, 44, 0, ".sortable('option', 'disabled', true)" );
equal( chainable, element, "disable is chainable" ); assert.equal( chainable, element, "disable is chainable" );
} ); } );
test( "refresh() should update the positions of initially empty lists (see #7498)", function() { QUnit.test( "refresh() should update the positions of initially empty lists (see #7498)", function( assert ) {
expect( 1 ); assert.expect( 1 );
var changeCount = 0, var changeCount = 0,
element = $( "#qunit-fixture" ).html( "<ul></ul>" ).find( "ul" ); element = $( "#qunit-fixture" ).html( "<ul></ul>" ).find( "ul" );
@ -123,7 +124,7 @@ test( "refresh() should update the positions of initially empty lists (see #7498
moves: 15 moves: 15
} ); } );
equal( changeCount, 1 ); assert.equal( changeCount, 1 );
} ); } );
} ); } );

View File

@ -1,12 +1,13 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"ui/widgets/sortable" "ui/widgets/sortable"
], function( $ ) { ], function( QUnit, $ ) {
module( "sortable: options" ); QUnit.module( "sortable: options" );
/* /*
test("{ appendTo: 'parent' }, default", function() { Test("{ appendTo: 'parent' }, default", function() {
ok(false, "missing test - untested code is broken code."); ok(false, "missing test - untested code is broken code.");
}); });
@ -15,16 +16,16 @@ test("{ appendTo: Selector }", function() {
}); });
*/ */
test( "{ axis: false }, default", function() { QUnit.test( "{ axis: false }, default", function( assert ) {
expect( 2 ); assert.expect( 2 );
var offsetAfter, var offsetAfter,
element = $( "#sortable" ).sortable( { element = $( "#sortable" ).sortable( {
axis: false, axis: false,
change: function() { change: function() {
offsetAfter = item.offset(); offsetAfter = item.offset();
notEqual( offsetAfter.left, offsetBefore.left, "x axis not constrained when axis: false" ); assert.notEqual( offsetAfter.left, offsetBefore.left, "x axis not constrained when axis: false" );
notEqual( offsetAfter.top, offsetBefore.top, "y axis not constrained when axis: false" ); assert.notEqual( offsetAfter.top, offsetBefore.top, "y axis not constrained when axis: false" );
} }
} ), } ),
item = element.find( "li" ).eq( 0 ), item = element.find( "li" ).eq( 0 ),
@ -37,16 +38,16 @@ test( "{ axis: false }, default", function() {
} ); } );
} ); } );
test( "{ axis: 'x' }", function() { QUnit.test( "{ axis: 'x' }", function( assert ) {
expect( 2 ); assert.expect( 2 );
var offsetAfter, var offsetAfter,
element = $( "#sortable" ).sortable( { element = $( "#sortable" ).sortable( {
axis: "x", axis: "x",
change: function() { change: function() {
offsetAfter = item.offset(); offsetAfter = item.offset();
notEqual( offsetAfter.left, offsetBefore.left, "x axis not constrained when axis: x" ); assert.notEqual( offsetAfter.left, offsetBefore.left, "x axis not constrained when axis: x" );
equal( offsetAfter.top, offsetBefore.top, "y axis constrained when axis: x" ); assert.equal( offsetAfter.top, offsetBefore.top, "y axis constrained when axis: x" );
} }
} ), } ),
item = element.find( "li" ).eq( 0 ), item = element.find( "li" ).eq( 0 ),
@ -59,16 +60,16 @@ test( "{ axis: 'x' }", function() {
} ); } );
} ); } );
test( "{ axis: 'y' }", function() { QUnit.test( "{ axis: 'y' }", function( assert ) {
expect( 2 ); assert.expect( 2 );
var offsetAfter, var offsetAfter,
element = $( "#sortable" ).sortable( { element = $( "#sortable" ).sortable( {
axis: "y", axis: "y",
change: function() { change: function() {
offsetAfter = item.offset(); offsetAfter = item.offset();
equal( offsetAfter.left, offsetBefore.left, "x axis constrained when axis: y" ); assert.equal( offsetAfter.left, offsetBefore.left, "x axis constrained when axis: y" );
notEqual( offsetAfter.top, offsetBefore.top, "y axis not constrained when axis: y" ); assert.notEqual( offsetAfter.top, offsetBefore.top, "y axis not constrained when axis: y" );
} }
} ), } ),
item = element.find( "li" ).eq( 0 ), item = element.find( "li" ).eq( 0 ),
@ -81,8 +82,9 @@ test( "{ axis: 'y' }", function() {
} ); } );
} ); } );
asyncTest( "#7415: Incorrect revert animation with axis: 'y'", function() { QUnit.test( "#7415: Incorrect revert animation with axis: 'y'", function( assert ) {
expect( 2 ); var ready = assert.async();
assert.expect( 2 );
var expectedLeft, var expectedLeft,
element = $( "#sortable" ).sortable( { element = $( "#sortable" ).sortable( {
axis: "y", axis: "y",
@ -100,14 +102,14 @@ asyncTest( "#7415: Incorrect revert animation with axis: 'y'", function() {
setTimeout( function() { setTimeout( function() {
var top = parseFloat( item.css( "top" ) ); var top = parseFloat( item.css( "top" ) );
equal( item.css( "left" ), expectedLeft, "left not animated" ); assert.equal( item.css( "left" ), expectedLeft, "left not animated" );
ok( top > 0 && top < 300, "top is animated" ); assert.ok( top > 0 && top < 300, "top is animated" );
start(); ready();
}, 100 ); }, 100 );
} ); } );
/* /*
test("{ cancel: 'input,textarea,button,select,option' }, default", function() { Test("{ cancel: 'input,textarea,button,select,option' }, default", function() {
ok(false, "missing test - untested code is broken code."); ok(false, "missing test - untested code is broken code.");
}); });
@ -116,8 +118,8 @@ test("{ cancel: Selector }", function() {
}); });
*/ */
test( "#8792: issues with floated items in connected lists", function() { QUnit.test( "#8792: issues with floated items in connected lists", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element, var element,
changeCount = 0; changeCount = 0;
@ -142,7 +144,7 @@ test( "#8792: issues with floated items in connected lists", function() {
moves: 15 moves: 15
} ); } );
equal( changeCount, 1, "change fired only once (no jitters) when dragging a floated sortable in it's own container" ); assert.equal( changeCount, 1, "change fired only once (no jitters) when dragging a floated sortable in it's own container" );
// Move the first li ( which is now in the second spot ) // Move the first li ( which is now in the second spot )
// through the first spot in the second ul to the second spot in the second ul // through the first spot in the second ul to the second spot in the second ul
@ -151,11 +153,11 @@ test( "#8792: issues with floated items in connected lists", function() {
moves: 15 moves: 15
} ); } );
equal( changeCount, 3, "change fired once for each expected change when dragging a floated sortable to a connected container" ); assert.equal( changeCount, 3, "change fired once for each expected change when dragging a floated sortable to a connected container" );
} ); } );
test( "#8301: single axis with connected list", function() { QUnit.test( "#8301: single axis with connected list", function( assert ) {
expect( 1 ); assert.expect( 1 );
var element = $( "#sortable" ).sortable( { var element = $( "#sortable" ).sortable( {
axis: "y", axis: "y",
@ -169,7 +171,7 @@ test( "#8301: single axis with connected list", function() {
tolerance: "pointer", tolerance: "pointer",
connectWith: "#sortable", connectWith: "#sortable",
receive: function() { receive: function() {
ok( true, "connected list received item" ); assert.ok( true, "connected list received item" );
} }
} ) } )
.insertAfter( element ); .insertAfter( element );
@ -182,7 +184,7 @@ test( "#8301: single axis with connected list", function() {
} ); } );
/* /*
test("{ connectWith: false }, default", function() { Test("{ connectWith: false }, default", function() {
ok(false, "missing test - untested code is broken code."); ok(false, "missing test - untested code is broken code.");
}); });
@ -327,14 +329,14 @@ test("{ placeholder: false }, default", function() {
}); });
*/ */
test( "{ placeholder: false } img", function() { QUnit.test( "{ placeholder: false } img", function( assert ) {
expect( 3 ); assert.expect( 3 );
var element = $( "#sortable-images" ).sortable( { var element = $( "#sortable-images" ).sortable( {
start: function( event, ui ) { start: function( event, ui ) {
ok( ui.placeholder.attr( "src" ).indexOf( "images/jqueryui_32x32.png" ) > 0, "placeholder img has correct src" ); assert.ok( ui.placeholder.attr( "src" ).indexOf( "images/jqueryui_32x32.png" ) > 0, "placeholder img has correct src" );
equal( ui.placeholder.height(), 32, "placeholder has correct height" ); assert.equal( ui.placeholder.height(), 32, "placeholder has correct height" );
equal( ui.placeholder.width(), 32, "placeholder has correct width" ); assert.equal( ui.placeholder.width(), 32, "placeholder has correct width" );
} }
} ); } );
@ -343,8 +345,8 @@ test( "{ placeholder: false } img", function() {
} ); } );
} ); } );
test( "{ placeholder: String }", function( assert ) { QUnit.test( "{ placeholder: String }", function( assert ) {
expect( 1 ); assert.expect( 1 );
var element = $( "#sortable" ).sortable( { var element = $( "#sortable" ).sortable( {
placeholder: "test", placeholder: "test",
@ -358,8 +360,8 @@ test( "{ placeholder: String }", function( assert ) {
} ); } );
} ); } );
test( "{ placholder: String } tr", function( assert ) { QUnit.test( "{ placholder: String } tr", function( assert ) {
expect( 4 ); assert.expect( 4 );
var originalWidths, var originalWidths,
element = $( "#sortable-table tbody" ).sortable( { element = $( "#sortable-table tbody" ).sortable( {
@ -369,10 +371,10 @@ test( "{ placholder: String } tr", function( assert ) {
return $( this ).width(); return $( this ).width();
} ).get(); } ).get();
assert.hasClasses( ui.placeholder, "test" ); assert.hasClasses( ui.placeholder, "test" );
deepEqual( currentWidths, originalWidths, "table cells maintian size" ); assert.deepEqual( currentWidths, originalWidths, "table cells maintian size" );
equal( ui.placeholder.children().length, dragRow.children().length, assert.equal( ui.placeholder.children().length, dragRow.children().length,
"placeholder has correct number of cells" ); "placeholder has correct number of cells" );
equal( ui.placeholder.children().html(), $( "<span>&#160;</span>" ).html(), assert.equal( ui.placeholder.children().html(), $( "<span>&#160;</span>" ).html(),
"placeholder td has content for forced dimensions" ); "placeholder td has content for forced dimensions" );
} }
} ), } ),
@ -388,8 +390,8 @@ test( "{ placholder: String } tr", function( assert ) {
} ); } );
} ); } );
test( "{ placholder: String } tbody", function() { QUnit.test( "{ placholder: String } tbody", function( assert ) {
expect( 6 ); assert.expect( 6 );
var originalWidths, var originalWidths,
element = $( "#sortable-table" ).sortable( { element = $( "#sortable-table" ).sortable( {
@ -398,16 +400,16 @@ test( "{ placholder: String } tbody", function() {
var currentWidths = otherBody.children().map( function() { var currentWidths = otherBody.children().map( function() {
return $( this ).width(); return $( this ).width();
} ).get(); } ).get();
ok( ui.placeholder.hasClass( "test" ), "placeholder has class" ); assert.ok( ui.placeholder.hasClass( "test" ), "placeholder has class" );
deepEqual( currentWidths, originalWidths, "table cells maintain size" ); assert.deepEqual( currentWidths, originalWidths, "table cells maintain size" );
equal( ui.placeholder.children().length, 1, assert.equal( ui.placeholder.children().length, 1,
"placeholder has one child" ); "placeholder has one child" );
equal( ui.placeholder.children( "tr" ).length, 1, assert.equal( ui.placeholder.children( "tr" ).length, 1,
"placeholder's child is tr" ); "placeholder's child is tr" );
equal( ui.placeholder.find( "> tr" ).children().length, assert.equal( ui.placeholder.find( "> tr" ).children().length,
dragBody.find( "> tr:first" ).children().length, dragBody.find( "> tr:first" ).children().length,
"placeholder's tr has correct number of cells" ); "placeholder's tr has correct number of cells" );
equal( ui.placeholder.find( "> tr" ).children().html(), assert.equal( ui.placeholder.find( "> tr" ).children().html(),
$( "<span>&#160;</span>" ).html(), $( "<span>&#160;</span>" ).html(),
"placeholder td has content for forced dimensions" ); "placeholder td has content for forced dimensions" );
} }
@ -425,7 +427,7 @@ test( "{ placholder: String } tbody", function() {
} ); } );
/* /*
test("{ revert: false }, default", function() { Test("{ revert: false }, default", function() {
ok(false, "missing test - untested code is broken code."); ok(false, "missing test - untested code is broken code.");
}); });