diff options
author | Amanpreet Singh <apsdehal@gmail.com> | 2016-04-06 18:52:59 +0530 |
---|---|---|
committer | Amanpreet Singh <apsdehal@gmail.com> | 2016-04-14 00:14:57 +0530 |
commit | 749f95ee0ab25b7ee03b3def88ec5bc604ab9929 (patch) | |
tree | 584597827513f6ce1930d4b85ab1371a3513749d /tests | |
parent | 38d473708b6af4166ca01c938325f8910e66cf22 (diff) | |
download | jquery-ui-749f95ee0ab25b7ee03b3def88ec5bc604ab9929.tar.gz jquery-ui-749f95ee0ab25b7ee03b3def88ec5bc604ab9929.zip |
Sortable: Shift to use no globals
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/sortable/core.js | 17 | ||||
-rw-r--r-- | tests/unit/sortable/events.js | 211 | ||||
-rw-r--r-- | tests/unit/sortable/helper.js | 4 | ||||
-rw-r--r-- | tests/unit/sortable/methods.js | 69 | ||||
-rw-r--r-- | tests/unit/sortable/options.js | 102 |
5 files changed, 204 insertions, 199 deletions
diff --git a/tests/unit/sortable/core.js b/tests/unit/sortable/core.js index d12416f09..2bb11edbe 100644 --- a/tests/unit/sortable/core.js +++ b/tests/unit/sortable/core.js @@ -1,23 +1,24 @@ define( [ + "qunit", "jquery", "./helper", "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() { - expect( 1 ); +QUnit.test( "#9314: Sortable: Items cannot be dragged directly into bottom position", function( assert ) { + assert.expect( 1 ); var el = $( ".connectWith" ).sortable( { 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 ) { - expect( 8 ); +QUnit.test( "ui-sortable-handle applied to appropriate element", function( assert ) { + assert.expect( 8 ); var item = "<li><p></p></li>", el = $( "<ul>" + item + item + "</ul>" ) .sortable() @@ -36,7 +37,7 @@ test( "ui-sortable-handle applied to appropriate element", function( assert ) { assert.hasClasses( el.find( "p:last" ), "ui-sortable-handle" ); 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" ); } ); } ); diff --git a/tests/unit/sortable/events.js b/tests/unit/sortable/events.js index d2416fbc4..4973abef0 100644 --- a/tests/unit/sortable/events.js +++ b/tests/unit/sortable/events.js @@ -1,14 +1,15 @@ define( [ + "qunit", "jquery", "./helper", "ui/widgets/sortable", "ui/widgets/draggable" -], function( $, testHelper ) { +], function( QUnit, $, testHelper ) { -module( "sortable: events" ); +QUnit.module( "sortable: events" ); -test( "start", function() { - expect( 7 ); +QUnit.test( "start", function( assert ) { + assert.expect( 7 ); var hash; $( "#sortable" ).sortable( { @@ -19,19 +20,19 @@ test( "start", function() { dy: 10 } ); - ok( hash, "start event triggered" ); - ok( hash.helper, "UI hash includes: helper" ); - ok( hash.placeholder, "UI hash includes: placeholder" ); - ok( hash.item, "UI hash includes: item" ); - ok( !hash.sender, "UI hash does not include: sender" ); + assert.ok( hash, "start event triggered" ); + assert.ok( hash.helper, "UI hash includes: helper" ); + assert.ok( hash.placeholder, "UI hash includes: placeholder" ); + assert.ok( hash.item, "UI hash includes: item" ); + assert.ok( !hash.sender, "UI hash does not include: sender" ); // Todo: see if these events should actually have sane values in them - ok( "position" in hash, "UI hash includes: position" ); - ok( "offset" in hash, "UI hash includes: offset" ); + assert.ok( "position" in hash, "UI hash includes: position" ); + assert.ok( "offset" in hash, "UI hash includes: offset" ); } ); -test( "sort", function() { - expect( 7 ); +QUnit.test( "sort", function( assert ) { + assert.expect( 7 ); var hash; $( "#sortable" ).sortable( { @@ -42,18 +43,18 @@ test( "sort", function() { dy: 10 } ); - ok( hash, "sort event triggered" ); - ok( hash.helper, "UI hash includes: helper" ); - ok( hash.placeholder, "UI hash includes: placeholder" ); - 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" ); - ok( hash.item, "UI hash includes: item" ); - ok( !hash.sender, "UI hash does not include: sender" ); + assert.ok( hash, "sort event triggered" ); + assert.ok( hash.helper, "UI hash includes: helper" ); + assert.ok( hash.placeholder, "UI hash includes: placeholder" ); + assert.ok( hash.position && ( "top" in hash.position && "left" in hash.position ), "UI hash includes: position" ); + assert.ok( hash.offset && ( hash.offset.top && hash.offset.left ), "UI hash includes: offset" ); + assert.ok( hash.item, "UI hash includes: item" ); + assert.ok( !hash.sender, "UI hash does not include: sender" ); } ); -test( "change", function() { - expect( 8 ); +QUnit.test( "change", function( assert ) { + assert.expect( 8 ); var hash; $( "#sortable" ).sortable( { @@ -65,7 +66,7 @@ test( "change", function() { 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( { change: function( e, ui ) { @@ -75,18 +76,18 @@ test( "change", function() { dy: 22 } ); - ok( hash, "change event triggered" ); - ok( hash.helper, "UI hash includes: helper" ); - ok( hash.placeholder, "UI hash includes: placeholder" ); - 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" ); - ok( hash.item, "UI hash includes: item" ); - ok( !hash.sender, "UI hash does not include: sender" ); + assert.ok( hash, "change event triggered" ); + assert.ok( hash.helper, "UI hash includes: helper" ); + assert.ok( hash.placeholder, "UI hash includes: placeholder" ); + assert.ok( hash.position && ( "top" in hash.position && "left" in hash.position ), "UI hash includes: position" ); + assert.ok( hash.offset && ( hash.offset.top && hash.offset.left ), "UI hash includes: offset" ); + assert.ok( hash.item, "UI hash includes: item" ); + assert.ok( !hash.sender, "UI hash does not include: sender" ); } ); -test( "beforeStop", function() { - expect( 7 ); +QUnit.test( "beforeStop", function( assert ) { + assert.expect( 7 ); var hash; $( "#sortable" ).sortable( { @@ -97,18 +98,18 @@ test( "beforeStop", function() { dy: 20 } ); - ok( hash, "beforeStop event triggered" ); - ok( hash.helper, "UI hash includes: helper" ); - ok( hash.placeholder, "UI hash includes: placeholder" ); - 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" ); - ok( hash.item, "UI hash includes: item" ); - ok( !hash.sender, "UI hash does not include: sender" ); + assert.ok( hash, "beforeStop event triggered" ); + assert.ok( hash.helper, "UI hash includes: helper" ); + assert.ok( hash.placeholder, "UI hash includes: placeholder" ); + assert.ok( hash.position && ( "top" in hash.position && "left" in hash.position ), "UI hash includes: position" ); + assert.ok( hash.offset && ( hash.offset.top && hash.offset.left ), "UI hash includes: offset" ); + assert.ok( hash.item, "UI hash includes: item" ); + assert.ok( !hash.sender, "UI hash does not include: sender" ); } ); -test( "stop", function() { - expect( 7 ); +QUnit.test( "stop", function( assert ) { + assert.expect( 7 ); var hash; $( "#sortable" ).sortable( { @@ -119,18 +120,18 @@ test( "stop", function() { dy: 20 } ); - ok( hash, "stop event triggered" ); - ok( !hash.helper, "UI should not include: helper" ); - ok( hash.placeholder, "UI hash includes: placeholder" ); - 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" ); - ok( hash.item, "UI hash includes: item" ); - ok( !hash.sender, "UI hash does not include: sender" ); + assert.ok( hash, "stop event triggered" ); + assert.ok( !hash.helper, "UI should not include: helper" ); + assert.ok( hash.placeholder, "UI hash includes: placeholder" ); + assert.ok( hash.position && ( "top" in hash.position && "left" in hash.position ), "UI hash includes: position" ); + assert.ok( hash.offset && ( hash.offset.top && hash.offset.left ), "UI hash includes: offset" ); + assert.ok( hash.item, "UI hash includes: item" ); + assert.ok( !hash.sender, "UI hash does not include: sender" ); } ); -test( "update", function() { - expect( 8 ); +QUnit.test( "update", function( assert ) { + assert.expect( 8 ); var hash; $( "#sortable" ).sortable( { @@ -142,7 +143,7 @@ test( "update", function() { 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( { update: function( e, ui ) { @@ -152,18 +153,18 @@ test( "update", function() { dy: 22 } ); - ok( hash, "update event triggered" ); - ok( !hash.helper, "UI hash should not include: helper" ); - ok( hash.placeholder, "UI hash includes: placeholder" ); - 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" ); - ok( hash.item, "UI hash includes: item" ); - ok( !hash.sender, "UI hash does not include: sender" ); + assert.ok( hash, "update event triggered" ); + assert.ok( !hash.helper, "UI hash should not include: helper" ); + assert.ok( hash.placeholder, "UI hash includes: placeholder" ); + assert.ok( hash.position && ( "top" in hash.position && "left" in hash.position ), "UI hash includes: position" ); + assert.ok( hash.offset && ( hash.offset.top && hash.offset.left ), "UI hash includes: offset" ); + assert.ok( hash.item, "UI hash includes: item" ); + assert.ok( !hash.sender, "UI hash does not include: sender" ); } ); -test( "#3019: Stop fires too early", function() { - expect( 2 ); +QUnit.test( "#3019: Stop fires too early", function( assert ) { + assert.expect( 2 ); var helper = null, 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" ); - equal( helper, null, "helper should be false" ); + testHelper.sort( assert, $( "li", el )[ 0 ], 0, 44, 2, "Dragging the sortable" ); + assert.equal( helper, null, "helper should be false" ); } ); -test( "#4752: link event firing on sortable with connect list", function() { - expect( 10 ); +QUnit.test( "#4752: link event firing on sortable with connect list", function( assert ) { + assert.expect( 10 ); var fired = {}, 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" ); - ok( !hasFired( "change" ), "Click only, change event should not have fired" ); - ok( hasFired( "click" ), "Click event should have fired" ); + assert.ok( !hasFired( "change" ), "Click only, change event should not have fired" ); + assert.ok( hasFired( "click" ), "Click event should have fired" ); // Drag an item within the first list fired = {}; $( "#sortable li:eq(0)" ).simulate( "drag", { dx: 0, dy: 40 } ); - ok( hasFired( "change" ), "40px drag, change event should have fired" ); - ok( !hasFired( "receive" ), "Receive event should not have fired" ); - ok( !hasFired( "remove" ), "Remove event should not have fired" ); - ok( !hasFired( "click" ), "Click event should not have fired" ); + assert.ok( hasFired( "change" ), "40px drag, change event should have fired" ); + assert.ok( !hasFired( "receive" ), "Receive event should not have fired" ); + assert.ok( !hasFired( "remove" ), "Remove 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 fired = {}; $( "#sortable li:eq(0)" ).simulate( "drag", { dx: 0, dy: 150 } ); - ok( hasFired( "change" ), "150px drag, change event should have fired" ); - ok( hasFired( "receive" ), "Receive event should have fired" ); - ok( hasFired( "remove" ), "Remove event should have fired" ); - ok( !hasFired( "click" ), "Click event should not have fired" ); + assert.ok( hasFired( "change" ), "150px drag, change event should have fired" ); + assert.ok( hasFired( "receive" ), "Receive event should have fired" ); + assert.ok( hasFired( "remove" ), "Remove event should 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."); }); @@ -233,8 +234,8 @@ test("remove", function() { }); */ -test( "over", function() { - expect( 8 ); +QUnit.test( "over", function( assert ) { + assert.expect( 8 ); var hash, overCount = 0; @@ -248,20 +249,20 @@ test( "over", function() { dy: 20 } ); - ok( hash, "over event triggered" ); - ok( hash.helper, "UI includes: helper" ); - ok( hash.placeholder, "UI hash includes: placeholder" ); - 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" ); - ok( hash.item, "UI hash includes: item" ); - ok( hash.sender, "UI hash includes: sender" ); - equal( overCount, 1, "over fires only once" ); + assert.ok( hash, "over event triggered" ); + assert.ok( hash.helper, "UI includes: helper" ); + assert.ok( hash.placeholder, "UI hash includes: placeholder" ); + assert.ok( hash.position && ( "top" in hash.position && "left" in hash.position ), "UI hash includes: position" ); + assert.ok( hash.offset && ( hash.offset.top && hash.offset.left ), "UI hash includes: offset" ); + assert.ok( hash.item, "UI hash includes: item" ); + assert.ok( hash.sender, "UI hash includes: sender" ); + assert.equal( overCount, 1, "over fires only once" ); } ); // http://bugs.jqueryui.com/ticket/9335 // Sortable: over & out events does not consistently fire -test( "over, fires with draggable connected to sortable", function() { - expect( 3 ); +QUnit.test( "over, fires with draggable connected to sortable", function( assert ) { + assert.expect( 3 ); var hash, overCount = 0, @@ -282,13 +283,13 @@ test( "over, fires with draggable connected to sortable", function() { dy: -20 } ); - ok( hash, "over event triggered" ); - ok( !hash.sender, "UI should not include: sender" ); - equal( overCount, 1, "over fires only once" ); + assert.ok( hash, "over event triggered" ); + assert.ok( !hash.sender, "UI should not include: sender" ); + assert.equal( overCount, 1, "over fires only once" ); } ); -test( "over, with connected sortable", function() { - expect( 3 ); +QUnit.test( "over, with connected sortable", function( assert ) { + assert.expect( 3 ); var hash, overCount = 0; @@ -304,19 +305,19 @@ test( "over, with connected sortable", function() { dy: 102 } ); - ok( hash, "over event triggered" ); - equal( hash.sender[ 0 ], $( " #sortable" )[ 0 ], "UI includes: sender" ); - equal( overCount, 1, "over fires only once" ); + assert.ok( hash, "over event triggered" ); + assert.equal( hash.sender[ 0 ], $( " #sortable" )[ 0 ], "UI includes: sender" ); + assert.equal( overCount, 1, "over fires only once" ); } ); /* -test("out", function() { +Test("out", function() { ok(false, "missing test - untested code is broken code."); }); */ -test( "out, with connected sortable", function() { - expect( 2 ); +QUnit.test( "out, with connected sortable", function( assert ) { + assert.expect( 2 ); var hash, outCount = 0; @@ -332,12 +333,12 @@ test( "out, with connected sortable", function() { dy: 40 } ); - ok( hash, "out event triggered" ); - equal( outCount, 1, "out fires only once" ); + assert.ok( hash, "out event triggered" ); + assert.equal( outCount, 1, "out fires only once" ); } ); -test( "repeated out & over between connected sortables", function() { - expect( 2 ); +QUnit.test( "repeated out & over between connected sortables", function( assert ) { + assert.expect( 2 ); var outCount = 0, overCount = 0; @@ -362,12 +363,12 @@ test( "repeated out & over between connected sortables", function() { dy: -40 } ); - equal( outCount, 2, "out fires twice" ); - equal( overCount, 4, "over fires four times" ); + assert.equal( outCount, 2, "out fires twice" ); + assert.equal( overCount, 4, "over fires four times" ); } ); /* -test("activate", function() { +Test("activate", function() { ok(false, "missing test - untested code is broken code."); }); diff --git a/tests/unit/sortable/helper.js b/tests/unit/sortable/helper.js index c1c0b6e74..61de63ae9 100644 --- a/tests/unit/sortable/helper.js +++ b/tests/unit/sortable/helper.js @@ -4,12 +4,12 @@ define( [ ], function( $, helper ) { return $.extend( helper, { - sort: function( handle, dx, dy, index, msg ) { + sort: function( assert, handle, dx, dy, index, msg ) { $( handle ).simulate( "drag", { dx: dx, dy: dy } ); - equal( $( handle ).parent().children().index( handle ), index, msg ); + assert.equal( $( handle ).parent().children().index( handle ), index, msg ); } } ); diff --git a/tests/unit/sortable/methods.js b/tests/unit/sortable/methods.js index 1d2fda8ff..b52d641ed 100644 --- a/tests/unit/sortable/methods.js +++ b/tests/unit/sortable/methods.js @@ -1,98 +1,99 @@ define( [ + "qunit", "jquery", "./helper", "ui/widgets/sortable" -], function( $, testHelper ) { +], function( QUnit, $, testHelper ) { -module( "sortable: methods" ); +QUnit.module( "sortable: methods" ); -test( "init", function() { - expect( 5 ); +QUnit.test( "init", function( assert ) { + assert.expect( 5 ); $( "<div></div>" ).appendTo( "body" ).sortable().remove(); - ok( true, ".sortable() called on element" ); + assert.ok( true, ".sortable() called on element" ); $( [] ).sortable(); - ok( true, ".sortable() called on empty collection" ); + assert.ok( true, ".sortable() called on empty collection" ); $( "<div></div>" ).sortable(); - ok( true, ".sortable() called on disconnected DOMElement" ); + assert.ok( true, ".sortable() called on disconnected DOMElement" ); $( "<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" ); - ok( true, "arbitrary option setter after init" ); + assert.ok( true, "arbitrary option setter after init" ); } ); -test( "destroy", function() { - expect( 4 ); +QUnit.test( "destroy", function( assert ) { + assert.expect( 4 ); $( "<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" ); - ok( true, ".sortable('destroy') called on empty collection" ); + assert.ok( true, ".sortable('destroy') called on empty collection" ); $( "<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(), actual = expected.sortable( "destroy" ); - equal( actual, expected, "destroy is chainable" ); + assert.equal( actual, expected, "destroy is chainable" ); } ); -test( "enable", function() { - expect( 5 ); +QUnit.test( "enable", function( assert ) { + assert.expect( 5 ); var el, actual, expected; 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" ); - equal( el.sortable( "option", "disabled" ), false, "disabled option getter" ); + assert.equal( el.sortable( "option", "disabled" ), false, "disabled option getter" ); el.sortable( "destroy" ); el.sortable( { disabled: true } ); 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(), actual = expected.sortable( "enable" ); - equal( actual, expected, "enable is chainable" ); + assert.equal( actual, expected, "enable is chainable" ); } ); -test( "disable", function( assert ) { - expect( 9 ); +QUnit.test( "disable", function( assert ) { + assert.expect( 9 ); var chainable, 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" ); - 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( { 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 ); - 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" ); - 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" ); - testHelper.sort( $( "li", element )[ 0 ], 0, 44, 0, ".sortable('option', 'disabled', true)" ); - equal( chainable, element, "disable is chainable" ); + testHelper.sort( assert, $( "li", element )[ 0 ], 0, 44, 0, ".sortable('option', 'disabled', true)" ); + assert.equal( chainable, element, "disable is chainable" ); } ); -test( "refresh() should update the positions of initially empty lists (see #7498)", function() { - expect( 1 ); +QUnit.test( "refresh() should update the positions of initially empty lists (see #7498)", function( assert ) { + assert.expect( 1 ); var changeCount = 0, 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 } ); - equal( changeCount, 1 ); + assert.equal( changeCount, 1 ); } ); } ); diff --git a/tests/unit/sortable/options.js b/tests/unit/sortable/options.js index ba3a70d99..fa0c487b7 100644 --- a/tests/unit/sortable/options.js +++ b/tests/unit/sortable/options.js @@ -1,12 +1,13 @@ define( [ + "qunit", "jquery", "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."); }); @@ -15,16 +16,16 @@ test("{ appendTo: Selector }", function() { }); */ -test( "{ axis: false }, default", function() { - expect( 2 ); +QUnit.test( "{ axis: false }, default", function( assert ) { + assert.expect( 2 ); var offsetAfter, element = $( "#sortable" ).sortable( { axis: false, change: function() { offsetAfter = item.offset(); - 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.left, offsetBefore.left, "x 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 ), @@ -37,16 +38,16 @@ test( "{ axis: false }, default", function() { } ); } ); -test( "{ axis: 'x' }", function() { - expect( 2 ); +QUnit.test( "{ axis: 'x' }", function( assert ) { + assert.expect( 2 ); var offsetAfter, element = $( "#sortable" ).sortable( { axis: "x", change: function() { offsetAfter = item.offset(); - notEqual( offsetAfter.left, offsetBefore.left, "x axis not constrained when axis: x" ); - equal( offsetAfter.top, offsetBefore.top, "y axis constrained when axis: x" ); + assert.notEqual( offsetAfter.left, offsetBefore.left, "x axis not constrained when axis: x" ); + assert.equal( offsetAfter.top, offsetBefore.top, "y axis constrained when axis: x" ); } } ), item = element.find( "li" ).eq( 0 ), @@ -59,16 +60,16 @@ test( "{ axis: 'x' }", function() { } ); } ); -test( "{ axis: 'y' }", function() { - expect( 2 ); +QUnit.test( "{ axis: 'y' }", function( assert ) { + assert.expect( 2 ); var offsetAfter, element = $( "#sortable" ).sortable( { axis: "y", change: function() { offsetAfter = item.offset(); - equal( offsetAfter.left, offsetBefore.left, "x axis constrained when axis: y" ); - notEqual( offsetAfter.top, offsetBefore.top, "y axis not constrained when axis: y" ); + assert.equal( offsetAfter.left, offsetBefore.left, "x axis constrained when axis: y" ); + assert.notEqual( offsetAfter.top, offsetBefore.top, "y axis not constrained when axis: y" ); } } ), item = element.find( "li" ).eq( 0 ), @@ -81,8 +82,9 @@ test( "{ axis: 'y' }", function() { } ); } ); -asyncTest( "#7415: Incorrect revert animation with axis: 'y'", function() { - expect( 2 ); +QUnit.test( "#7415: Incorrect revert animation with axis: 'y'", function( assert ) { + var ready = assert.async(); + assert.expect( 2 ); var expectedLeft, element = $( "#sortable" ).sortable( { axis: "y", @@ -100,14 +102,14 @@ asyncTest( "#7415: Incorrect revert animation with axis: 'y'", function() { setTimeout( function() { var top = parseFloat( item.css( "top" ) ); - equal( item.css( "left" ), expectedLeft, "left not animated" ); - ok( top > 0 && top < 300, "top is animated" ); - start(); + assert.equal( item.css( "left" ), expectedLeft, "left not animated" ); + assert.ok( top > 0 && top < 300, "top is animated" ); + ready(); }, 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."); }); @@ -116,8 +118,8 @@ test("{ cancel: Selector }", function() { }); */ -test( "#8792: issues with floated items in connected lists", function() { - expect( 2 ); +QUnit.test( "#8792: issues with floated items in connected lists", function( assert ) { + assert.expect( 2 ); var element, changeCount = 0; @@ -142,7 +144,7 @@ test( "#8792: issues with floated items in connected lists", function() { 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 ) // 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 } ); - 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() { - expect( 1 ); +QUnit.test( "#8301: single axis with connected list", function( assert ) { + assert.expect( 1 ); var element = $( "#sortable" ).sortable( { axis: "y", @@ -169,7 +171,7 @@ test( "#8301: single axis with connected list", function() { tolerance: "pointer", connectWith: "#sortable", receive: function() { - ok( true, "connected list received item" ); + assert.ok( true, "connected list received item" ); } } ) .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."); }); @@ -327,14 +329,14 @@ test("{ placeholder: false }, default", function() { }); */ -test( "{ placeholder: false } img", function() { - expect( 3 ); +QUnit.test( "{ placeholder: false } img", function( assert ) { + assert.expect( 3 ); var element = $( "#sortable-images" ).sortable( { start: function( event, ui ) { - 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" ); - equal( ui.placeholder.width(), 32, "placeholder has correct width" ); + assert.ok( ui.placeholder.attr( "src" ).indexOf( "images/jqueryui_32x32.png" ) > 0, "placeholder img has correct src" ); + assert.equal( ui.placeholder.height(), 32, "placeholder has correct height" ); + assert.equal( ui.placeholder.width(), 32, "placeholder has correct width" ); } } ); @@ -343,8 +345,8 @@ test( "{ placeholder: false } img", function() { } ); } ); -test( "{ placeholder: String }", function( assert ) { - expect( 1 ); +QUnit.test( "{ placeholder: String }", function( assert ) { + assert.expect( 1 ); var element = $( "#sortable" ).sortable( { placeholder: "test", @@ -358,8 +360,8 @@ test( "{ placeholder: String }", function( assert ) { } ); } ); -test( "{ placholder: String } tr", function( assert ) { - expect( 4 ); +QUnit.test( "{ placholder: String } tr", function( assert ) { + assert.expect( 4 ); var originalWidths, element = $( "#sortable-table tbody" ).sortable( { @@ -369,10 +371,10 @@ test( "{ placholder: String } tr", function( assert ) { return $( this ).width(); } ).get(); assert.hasClasses( ui.placeholder, "test" ); - deepEqual( currentWidths, originalWidths, "table cells maintian size" ); - equal( ui.placeholder.children().length, dragRow.children().length, + assert.deepEqual( currentWidths, originalWidths, "table cells maintian size" ); + assert.equal( ui.placeholder.children().length, dragRow.children().length, "placeholder has correct number of cells" ); - equal( ui.placeholder.children().html(), $( "<span> </span>" ).html(), + assert.equal( ui.placeholder.children().html(), $( "<span> </span>" ).html(), "placeholder td has content for forced dimensions" ); } } ), @@ -388,8 +390,8 @@ test( "{ placholder: String } tr", function( assert ) { } ); } ); -test( "{ placholder: String } tbody", function() { - expect( 6 ); +QUnit.test( "{ placholder: String } tbody", function( assert ) { + assert.expect( 6 ); var originalWidths, element = $( "#sortable-table" ).sortable( { @@ -398,16 +400,16 @@ test( "{ placholder: String } tbody", function() { var currentWidths = otherBody.children().map( function() { return $( this ).width(); } ).get(); - ok( ui.placeholder.hasClass( "test" ), "placeholder has class" ); - deepEqual( currentWidths, originalWidths, "table cells maintain size" ); - equal( ui.placeholder.children().length, 1, + assert.ok( ui.placeholder.hasClass( "test" ), "placeholder has class" ); + assert.deepEqual( currentWidths, originalWidths, "table cells maintain size" ); + assert.equal( ui.placeholder.children().length, 1, "placeholder has one child" ); - equal( ui.placeholder.children( "tr" ).length, 1, + assert.equal( ui.placeholder.children( "tr" ).length, 1, "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, "placeholder's tr has correct number of cells" ); - equal( ui.placeholder.find( "> tr" ).children().html(), + assert.equal( ui.placeholder.find( "> tr" ).children().html(), $( "<span> </span>" ).html(), "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."); }); |