diff options
Diffstat (limited to 'tests/unit/sortable')
-rw-r--r-- | tests/unit/sortable/all.html | 4 | ||||
-rw-r--r-- | tests/unit/sortable/common.js (renamed from tests/unit/sortable/sortable_common.js) | 12 | ||||
-rw-r--r-- | tests/unit/sortable/core.js | 42 | ||||
-rw-r--r-- | tests/unit/sortable/events.js (renamed from tests/unit/sortable/sortable_events.js) | 16 | ||||
-rw-r--r-- | tests/unit/sortable/helper.js (renamed from tests/unit/sortable/sortable_test_helpers.js) | 11 | ||||
-rw-r--r-- | tests/unit/sortable/methods.js (renamed from tests/unit/sortable/sortable_methods.js) | 29 | ||||
-rw-r--r-- | tests/unit/sortable/options.js (renamed from tests/unit/sortable/sortable_options.js) | 54 | ||||
-rw-r--r-- | tests/unit/sortable/sortable.html | 81 | ||||
-rw-r--r-- | tests/unit/sortable/sortable_core.js | 40 |
9 files changed, 179 insertions, 110 deletions
diff --git a/tests/unit/sortable/all.html b/tests/unit/sortable/all.html index cabaea469..cb08860bc 100644 --- a/tests/unit/sortable/all.html +++ b/tests/unit/sortable/all.html @@ -7,9 +7,9 @@ <script src="../../../external/jquery/jquery.js"></script> <link rel="stylesheet" href="../../../external/qunit/qunit.css"> - <link rel="stylesheet" href="../qunit-composite.css"> + <link rel="stylesheet" href="../../../external/qunit-composite/qunit-composite.css"> <script src="../../../external/qunit/qunit.js"></script> - <script src="../qunit-composite.js"></script> + <script src="../../../external/qunit-composite/qunit-composite.js"></script> <script src="../subsuite.js"></script> <script> diff --git a/tests/unit/sortable/sortable_common.js b/tests/unit/sortable/common.js index 86850a658..ab43251ab 100644 --- a/tests/unit/sortable/sortable_common.js +++ b/tests/unit/sortable/common.js @@ -1,8 +1,14 @@ -TestHelpers.commonWidgetTests( "sortable", { +define( [ + "lib/common", + "ui/sortable" +], function( common ) { + +common.testWidget( "sortable", { defaults: { appendTo: "parent", axis: false, - cancel: "input,textarea,button,select,option", + cancel: "input, textarea, button, select, option", + classes: {}, connectWith: false, containment: false, cursor: "auto", @@ -43,3 +49,5 @@ TestHelpers.commonWidgetTests( "sortable", { update: null } }); + +} ); diff --git a/tests/unit/sortable/core.js b/tests/unit/sortable/core.js new file mode 100644 index 000000000..7e973ec05 --- /dev/null +++ b/tests/unit/sortable/core.js @@ -0,0 +1,42 @@ +define( [ + "jquery", + "./helper", + "ui/sortable" +], function( $, testHelper ) { + +module( "sortable: core" ); + +test( "#9314: Sortable: Items cannot be dragged directly into bottom position", function() { + expect( 1 ); + + var el = $( ".connectWith" ).sortable({ + connectWith: ".connectWith" + }); + + testHelper.sort( $( "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 ); + var item = "<li><p></p></li>", + el = $( "<ul>" + item + item + "</ul>" ) + .sortable() + .appendTo( "#qunit-fixture" ); + + assert.hasClasses( el.find( "li:first" ), "ui-sortable-handle" ); + assert.hasClasses( el.find( "li:last" ), "ui-sortable-handle" ); + + el.sortable( "option", "handle", "p" ); + assert.lacksClasses( el.find( "li" )[ 0 ], "ui-sortable-handle" ); + assert.lacksClasses( el.find( "li" )[ 1 ], "ui-sortable-handle" ); + assert.hasClasses( el.find( "p" )[ 0 ], "ui-sortable-handle" ); + assert.hasClasses( el.find( "p" )[ 1 ], "ui-sortable-handle" ); + + el.append( item ).sortable( "refresh" ); + 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" ); +}); + +} ); diff --git a/tests/unit/sortable/sortable_events.js b/tests/unit/sortable/events.js index 46e86c906..267534b16 100644 --- a/tests/unit/sortable/sortable_events.js +++ b/tests/unit/sortable/events.js @@ -1,7 +1,9 @@ -/* - * sortable_events.js - */ -(function($) { +define( [ + "jquery", + "./helper", + "ui/sortable", + "ui/draggable" +], function( $, testHelper ) { module("sortable: events"); @@ -170,7 +172,7 @@ test("#3019: Stop fires too early", function() { } }); - TestHelpers.sortable.sort($("li", el)[0], 0, 44, 2, "Dragging the sortable"); + testHelper.sort($("li", el)[0], 0, 44, 2, "Dragging the sortable"); equal(helper, null, "helper should be false"); }); @@ -196,7 +198,7 @@ test("#4752: link event firing on sortable with connect list", function () { } }); - $("#qunit-fixture ul").bind("click.ui-sortable-test", function () { + $("#qunit-fixture ul").on("click.ui-sortable-test", function () { fired.click = true; }); @@ -373,4 +375,4 @@ test("deactivate", function() { }); */ -})(jQuery); +} ); diff --git a/tests/unit/sortable/sortable_test_helpers.js b/tests/unit/sortable/helper.js index 3cda43b8f..76545022e 100644 --- a/tests/unit/sortable/sortable_test_helpers.js +++ b/tests/unit/sortable/helper.js @@ -1,4 +1,9 @@ -TestHelpers.sortable = { +define( [ + "jquery", + "lib/helper" +], function( $, helper ) { + +return $.extend( helper, { sort: function( handle, dx, dy, index, msg ) { $( handle ).simulate( "drag", { dx: dx, @@ -6,4 +11,6 @@ TestHelpers.sortable = { }); equal( $( handle ).parent().children().index( handle ), index, msg ); } -}; +} ); + +} ); diff --git a/tests/unit/sortable/sortable_methods.js b/tests/unit/sortable/methods.js index 9c0a86a35..d88b8089f 100644 --- a/tests/unit/sortable/sortable_methods.js +++ b/tests/unit/sortable/methods.js @@ -1,7 +1,8 @@ -/* - * sortable_methods.js - */ -(function($) { +define( [ + "jquery", + "./helper", + "ui/sortable" +], function( $, testHelper ) { module("sortable: methods"); @@ -47,7 +48,7 @@ test("enable", function() { el = $("#sortable").sortable({ disabled: true }); - TestHelpers.sortable.sort($("li", el)[0], 0, 44, 0, ".sortable({ disabled: true })"); + testHelper.sort($("li", el)[0], 0, 44, 0, ".sortable({ disabled: true })"); el.sortable("enable"); equal(el.sortable("option", "disabled"), false, "disabled option getter"); @@ -57,36 +58,36 @@ test("enable", function() { el.sortable("option", "disabled", false); equal(el.sortable("option", "disabled"), false, "disabled option setter"); - TestHelpers.sortable.sort($("li", el)[0], 0, 44, 2, ".sortable('option', 'disabled', false)"); + testHelper.sort($("li", el)[0], 0, 44, 2, ".sortable('option', 'disabled', false)"); expected = $("<div></div>").sortable(), actual = expected.sortable("enable"); equal(actual, expected, "enable is chainable"); }); -test( "disable", function() { +test( "disable", function( assert ) { expect( 9 ); var chainable, element = $( "#sortable" ).sortable({ disabled: false }); - TestHelpers.sortable.sort( $( "li", element )[ 0 ], 0, 44, 2, ".sortable({ disabled: false })" ); + testHelper.sort( $( "li", element )[ 0 ], 0, 44, 2, ".sortable({ disabled: false })" ); chainable = element.sortable( "disable" ); - TestHelpers.sortable.sort( $( "li", element )[ 0 ], 0, 44, 0, "disabled.sortable getter" ); + testHelper.sort( $( "li", element )[ 0 ], 0, 44, 0, "disabled.sortable getter" ); element.sortable( "destroy" ); element.sortable({ disabled: false }); - TestHelpers.sortable.sort( $( "li", element )[ 0 ], 0, 44, 2, ".sortable({ disabled: false })" ); + testHelper.sort( $( "li", element )[ 0 ], 0, 44, 2, ".sortable({ disabled: false })" ); element.sortable( "option", "disabled", true); equal( element.sortable( "option", "disabled" ), true, "disabled option setter" ); - ok( !element.sortable( "widget" ).hasClass( "ui-state-disabled" ), "element does not get ui-state-disabled" ); + assert.lacksClasses( element.sortable( "widget" ), "ui-state-disabled" ); ok( !element.sortable( "widget" ).attr( "aria-disabled" ), "element does not get aria-disabled" ); - ok( element.sortable( "widget" ).hasClass( "ui-sortable-disabled" ), "element gets ui-sortable-disabled" ); + assert.hasClasses( element.sortable( "widget" ), "ui-sortable-disabled" ); - TestHelpers.sortable.sort($( "li", element )[ 0 ], 0, 44, 0, ".sortable('option', 'disabled', true)" ); + testHelper.sort($( "li", element )[ 0 ], 0, 44, 0, ".sortable('option', 'disabled', true)" ); equal( chainable, element, "disable is chainable" ); }); @@ -125,4 +126,4 @@ test( "refresh() should update the positions of initially empty lists (see #7498 equal( changeCount, 1 ); }); -})(jQuery); +} ); diff --git a/tests/unit/sortable/sortable_options.js b/tests/unit/sortable/options.js index f2beb4dbc..930f339e6 100644 --- a/tests/unit/sortable/sortable_options.js +++ b/tests/unit/sortable/options.js @@ -1,7 +1,7 @@ -/* - * sortable_options.js - */ -(function($) { +define( [ + "jquery", + "ui/sortable" +], function( $ ) { module("sortable: options"); @@ -343,13 +343,13 @@ test( "{ placeholder: false } img", function() { }); }); -test( "{ placeholder: String }", function() { +test( "{ placeholder: String }", function( assert ) { expect( 1 ); var element = $( "#sortable" ).sortable({ placeholder: "test", start: function( event, ui ) { - ok( ui.placeholder.hasClass( "test" ), "placeholder has class" ); + assert.hasClasses( ui.placeholder, "test" ); } }); @@ -358,7 +358,7 @@ test( "{ placeholder: String }", function() { }); }); -test( "{ placholder: String } tr", function() { +test( "{ placholder: String } tr", function( assert ) { expect( 4 ); var originalWidths, @@ -368,7 +368,7 @@ test( "{ placholder: String } tr", function() { var currentWidths = otherRow.children().map(function() { return $( this ).width(); }).get(); - ok( ui.placeholder.hasClass( "test" ), "placeholder has class" ); + assert.hasClasses( ui.placeholder, "test" ); deepEqual( currentWidths, originalWidths, "table cells maintian size" ); equal( ui.placeholder.children().length, dragRow.children().length, "placeholder has correct number of cells" ); @@ -388,6 +388,42 @@ test( "{ placholder: String } tr", function() { }); }); +test( "{ placholder: String } tbody", function() { + expect( 6 ); + + var originalWidths, + element = $( "#sortable-table" ).sortable({ + placeholder: "test", + start: function( event, ui ) { + 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, + "placeholder has one child" ); + equal( ui.placeholder.children( "tr" ).length, 1, + "placeholder's child is tr" ); + 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(), + $( "<span> </span>" ).html(), + "placeholder td has content for forced dimensions" ); + } + }), + bodies = element.children( "tbody" ), + dragBody = bodies.eq( 0 ), + otherBody = bodies.eq( 1 ); + + originalWidths = otherBody.children().map(function() { + return $( this ).width(); + }).get(); + dragBody.simulate( "drag", { + dy: 1 + }); +}); + /* test("{ revert: false }, default", function() { ok(false, "missing test - untested code is broken code."); @@ -457,4 +493,4 @@ test("{ zIndex: false }", function() { ok(false, "missing test - untested code is broken code."); }); */ -})(jQuery); +} ); diff --git a/tests/unit/sortable/sortable.html b/tests/unit/sortable/sortable.html index 3edc999b7..8bfbd3370 100644 --- a/tests/unit/sortable/sortable.html +++ b/tests/unit/sortable/sortable.html @@ -4,32 +4,9 @@ <meta charset="utf-8"> <title>jQuery UI Sortable Test Suite</title> - <script src="../../jquery.js"></script> - <link rel="stylesheet" href="../../../external/qunit/qunit.css"> - <script src="../../../external/qunit/qunit.js"></script> - <script src="../../../external/jquery-simulate/jquery.simulate.js"></script> - <script src="../testsuite.js"></script> - <script> - TestHelpers.loadResources({ - css: [ "core" ], - js: [ - "ui/core.js", - "ui/widget.js", - "ui/mouse.js", - "ui/sortable.js", - "ui/draggable.js" - ] - }); - </script> - - <script src="sortable_common.js"></script> - <script src="sortable_core.js"></script> - <script src="sortable_events.js"></script> - <script src="sortable_methods.js"></script> - <script src="sortable_options.js"></script> - <script src="sortable_test_helpers.js"></script> - - <script src="../swarminject.js"></script> + <script src="../../../external/requirejs/require.js"></script> + <script src="../../lib/css.js" data-modules="core"></script> + <script src="../../lib/bootstrap.js" data-widget="sortable"></script> <style> #sortable, #sortable2 { position:relative; @@ -74,20 +51,56 @@ <table id="sortable-table"> <tbody> <tr> - <td>1</td> - <td>2</td> + <td>1.1</td> + <td>1.2</td> + </tr> + <tr> + <td>1.3</td> + <td>1.4</td> + </tr> + <tr> + <td>1.5</td> + <td>1.6</td> + </tr> + <tr> + <td>1.7</td> + <td>1.8</td> + </tr> + </tbody> + <tbody> + <tr> + <td>2.1</td> + <td>2.2</td> + </tr> + <tr> + <td>2.3</td> + <td>2.4</td> + </tr> + <tr> + <td>2.5</td> + <td>2.6</td> + </tr> + <tr> + <td>2.7</td> + <td>2.8</td> + </tr> + </tbody> + <tbody> + <tr> + <td>3.1</td> + <td>3.2</td> </tr> <tr> - <td>3</td> - <td>4</td> + <td>3.3</td> + <td>3.4</td> </tr> <tr> - <td>5</td> - <td>6</td> + <td>3.5</td> + <td>3.6</td> </tr> <tr> - <td>7</td> - <td>8</td> + <td>3.7</td> + <td>3.8</td> </tr> </tbody> </table> diff --git a/tests/unit/sortable/sortable_core.js b/tests/unit/sortable/sortable_core.js deleted file mode 100644 index 54069a9bf..000000000 --- a/tests/unit/sortable/sortable_core.js +++ /dev/null @@ -1,40 +0,0 @@ -/* - * sortable_core.js - */ - -(function( $ ) { - -module( "sortable: core" ); - -test( "#9314: Sortable: Items cannot be dragged directly into bottom position", function() { - expect( 1 ); - - var el = $( ".connectWith" ).sortable({ - connectWith: ".connectWith" - }); - - TestHelpers.sortable.sort( $( "li", el[ 1 ] )[ 0 ], 0, -12, 5, "Dragging the sortable into connected sortable" ); -}); - -test( "ui-sortable-handle applied to appropriate element", function() { - expect( 6 ); - var item = "<li><p></p></li>", - el = $( "<ul>" + item + item + "</ul>" ) - .sortable() - .appendTo( "#qunit-fixture" ); - - ok( el.find( "li:first" ).hasClass( "ui-sortable-handle" ), "defaults to item" ); - ok( el.find( "li:last" ).hasClass( "ui-sortable-handle" ), "both items received class name" ); - - el.sortable( "option", "handle", "p" ); - ok( !el.find( "li" ).hasClass( "ui-sortable-handle" ), "removed on change" ); - ok( el.find( "p" ).hasClass( "ui-sortable-handle" ), "applied to handle" ); - - el.append( item ).sortable( "refresh" ); - ok( el.find( "p:last" ).hasClass( "ui-sortable-handle" ), "class name applied on refresh" ); - - el.sortable( "destroy" ); - equal( el.find( ".ui-sortable-handle" ).length, 0, "class name removed on destroy" ); -}); - -})( jQuery ); |