X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Ffx.js;h=1204e261cfe432d60839d4e5d8acbaf602384f7f;hb=5039a4bc5b951b9d28659f6f42f73c59e2e560fc;hp=d6de83f921a1c113d56611ac1df3bfed8b11cda1;hpb=0a0990485e5c1fd4b4fdcce7f7723d9e0a9dd16d;p=jquery.git diff --git a/test/unit/fx.js b/test/unit/fx.js index d6de83f..1204e26 100644 --- a/test/unit/fx.js +++ b/test/unit/fx.js @@ -12,63 +12,143 @@ test("animate(Hash, Object, Function)", function() { }); test("animate option (queue === false)", function () { - expect(1); - stop(); - - var order = []; - - var $foo = $("#foo"); - $foo.animate({width:'100px'}, 200, function () { - // should finish after unqueued animation so second - order.push(2); - }); - $foo.animate({fontSize:'2em'}, {queue:false, duration:10, complete:function () { - // short duration and out of queue so should finish first - order.push(1); - }}); - $foo.animate({height:'100px'}, 10, function() { - // queued behind the first animation so should finish third - order.push(3); - isSet( order, [ 1, 2, 3], "Animations finished in the correct order" ); - start(); - }); + expect(1); + stop(); + + var order = []; + + var $foo = $("#foo"); + $foo.animate({width:'100px'}, 200, function () { + // should finish after unqueued animation so second + order.push(2); + }); + $foo.animate({fontSize:'2em'}, {queue:false, duration:10, complete:function () { + // short duration and out of queue so should finish first + order.push(1); + }}); + $foo.animate({height:'100px'}, 10, function() { + // queued behind the first animation so should finish third + order.push(3); + isSet( order, [ 1, 2, 3], "Animations finished in the correct order" ); + start(); + }); }); test("queue() defaults to 'fx' type", function () { - expect(2); - stop(); - - var $foo = $("#foo"); - $foo.queue("fx", [ "sample", "array" ]); - var arr = $foo.queue(); - isSet(arr, [ "sample", "array" ], "queue() got an array set with type 'fx'"); - $foo.queue([ "another", "one" ]); - var arr = $foo.queue("fx"); - isSet(arr, [ "another", "one" ], "queue('fx') got an array set with no type"); - // clean up after test - $foo.queue([]); - - start(); + expect(2); + stop(); + + var $foo = $("#foo"); + $foo.queue("fx", [ "sample", "array" ]); + var arr = $foo.queue(); + isSet(arr, [ "sample", "array" ], "queue() got an array set with type 'fx'"); + $foo.queue([ "another", "one" ]); + var arr = $foo.queue("fx"); + isSet(arr, [ "another", "one" ], "queue('fx') got an array set with no type"); + // clean up after test + $foo.queue([]); + + start(); }); test("stop()", function() { expect(3); stop(); - reset(); - var foo = $("#foo")[0]; - var h = foo.style.height; + var $foo = $("#nothiddendiv"); + var w = 0; + $foo.hide().width(200).width(); + + $foo.animate({ width:'show' }, 1000); + setTimeout(function(){ + var nw = $foo.width(); + ok( nw != w, "An animation occurred " + nw + "px " + w + "px"); + $foo.stop(); + + nw = $foo.width(); + ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px"); + setTimeout(function(){ + equals( nw, $foo.width(), "The animation didn't continue" ); + start(); + }, 100); + }, 100); +}); + +test("stop() - several in queue", function() { + expect(4); + stop(); + + var $foo = $("#nothiddendiv"); + var w = 0; + $foo.hide().width(200).width(); - $("#foo").slideUp(1000); + $foo.animate({ width:'show' }, 1000); + $foo.animate({ width:'hide' }, 1000); + $foo.animate({ width:'show' }, 1000); setTimeout(function(){ - var nh = foo.style.height; - ok( nh != h, "An animation occurred " + nh + " " + h ); - $("#foo").stop(); + equals( $foo.queue().length, 3, "All 3 still in the queue" ); + var nw = $foo.width(); + ok( nw != w, "An animation occurred " + nw + "px " + w + "px"); + $foo.stop(); + + nw = $foo.width(); + ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px"); + equals( $foo.queue().length, 2, "The next animation continued" ); + $foo.stop(true); + start(); + }, 100); +}); + +test("stop(clearQueue)", function() { + expect(4); + stop(); + + var $foo = $("#nothiddendiv"); + var w = 0; + $foo.hide().width(200).width(); + + $foo.animate({ width:'show' }, 1000); + $foo.animate({ width:'hide' }, 1000); + $foo.animate({ width:'show' }, 1000); + setTimeout(function(){ + var nw = $foo.width(); + ok( nw != w, "An animation occurred " + nw + "px " + w + "px"); + $foo.stop(true); + + nw = $foo.width(); + ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px"); + + equals( $foo.queue().length, 0, "The animation queue was cleared" ); + setTimeout(function(){ + equals( nw, $foo.width(), "The animation didn't continue" ); + start(); + }, 100); + }, 100); +}); + +test("stop(clearQueue, gotoEnd)", function() { + expect(3); + stop(); + + var $foo = $("#nothiddendiv"); + var w = 0; + $foo.hide().width(200).width(); + + $foo.animate({ width:'show' }, 1000); + $foo.animate({ width:'hide' }, 1000); + $foo.animate({ width:'show' }, 1000); + $foo.animate({ width:'hide' }, 1000); + setTimeout(function(){ + var nw = $foo.width(); + ok( nw != w, "An animation occurred " + nw + "px " + w + "px"); + $foo.stop(false, true); + + nw = $foo.width(); + equals( nw, 200, "Stop() reset the animation" ); - nh = foo.style.height; - ok( nh != h, "Stop didn't reset the animation " + nh + " " + h ); setTimeout(function(){ - equals( nh, foo.style.height, "The animation didn't continue" ); + equals( $foo.queue().length, 3, "The next animation continued" ); + $foo.stop(true); start(); }, 100); }, 100); @@ -77,11 +157,11 @@ test("stop()", function() { test("toggle()", function() { expect(3); var x = $("#foo"); - ok( x.is(":visible") ); + ok( x.is(":visible"), "is visible" ); x.toggle(); - ok( x.is(":hidden") ); + ok( x.is(":hidden"), "is hidden" ); x.toggle(); - ok( x.is(":visible") ); + ok( x.is(":visible"), "is visible again" ); }); var visible = {