]> source.dussan.org Git - jquery-ui.git/commitdiff
Sortable Tests: Add tests for axis option and recent axis option bugs.
authorMike Sherov <mike.sherov@gmail.com>
Fri, 15 Mar 2013 02:56:48 +0000 (22:56 -0400)
committerMike Sherov <mike.sherov@gmail.com>
Fri, 15 Mar 2013 02:56:48 +0000 (22:56 -0400)
tests/unit/sortable/sortable_options.js

index 63857316236d2498e5f02cf63ea1d5f0ea3c1c4b..8dcf0e82fa4561382bf5c93471392b75444e29c4 100644 (file)
@@ -13,23 +13,100 @@ test("{ appendTo: 'parent' }, default", function() {
 test("{ appendTo: Selector }", function() {
        ok(false, "missing test - untested code is broken code.");
 });
+*/
 
-test("{ axis: false }, default", function() {
-       ok(false, "missing test - untested code is broken code.");
+test( "{ axis: false }, default", function() {
+       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" );
+                       }
+               }),
+               item = element.find( "li" ).eq( 0 ),
+               offsetBefore = item.offset();
+
+       item.simulate( "drag", {
+               dx: 50,
+               dy: 25,
+               moves: 1
+       });
 });
 
-test("{ axis: 'x' }", function() {
-       ok(false, "missing test - untested code is broken code.");
+test( "{ axis: 'x' }", function() {
+       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" );
+                       }
+               }),
+               item = element.find( "li" ).eq( 0 ),
+               offsetBefore = item.offset();
+
+       item.simulate( "drag", {
+               dx: 50,
+               dy: 25,
+               moves: 1
+       });
 });
 
-test("{ axis: 'y' }", function() {
-       ok(false, "missing test - untested code is broken code.");
+test( "{ axis: 'y' }", function() {
+       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" );
+                       }
+               }),
+               item = element.find( "li" ).eq( 0 ),
+               offsetBefore = item.offset();
+
+       item.simulate( "drag", {
+               dx: 50,
+               dy: 25,
+               moves: 1
+       });
 });
 
-test("{ axis: ? }, unexpected", function() {
-       ok(false, "missing test - untested code is broken code.");
+asyncTest( "#7415: Incorrect revert animation with axis: 'y'", function() {
+  expect( 2 );
+       var expectedLeft,
+               element = $( "#sortable" ).sortable({
+                       axis: "y",
+                       revert: true,
+                       stop: start,
+                       sort: function() {
+                               expectedLeft = item.css( "left" );
+                       }
+               }),
+               item = element.find( "li" ).eq( 0 );
+
+       item.simulate( "drag", {
+               dy: 300,
+               dx: 50
+       });
+
+       setTimeout(function() {
+               var top = parseFloat( item.css( "top" ) );
+               equal( item.css( "left" ), expectedLeft, "left not animated" );
+               ok( top > 0 && top < 300, "top is animated" );
+       }, 100 );
 });
 
+/*
 test("{ cancel: 'input,textarea,button,select,option' }, default", function() {
        ok(false, "missing test - untested code is broken code.");
 });