X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Ffx.js;h=481b172225121ffd5dc0bc4da8b4de0319f640ce;hb=91f1299f68a68728467a2566a38845d82e30606f;hp=c20e39ceb83da807019ec58b4a5434b15899ad72;hpb=e2ef3df86d5f54274bf2b779d882c30aa0886bfe;p=jquery.git diff --git a/test/unit/fx.js b/test/unit/fx.js index c20e39c..481b172 100644 --- a/test/unit/fx.js +++ b/test/unit/fx.js @@ -1,12 +1,17 @@ module("fx"); test("animate(Hash, Object, Function)", function() { - expect(1); + expect(3); stop(); var hash = {opacity: 'show'}; var hashCopy = $.extend({}, hash); $('#foo').animate(hash, 0, function() { ok( hash.opacity == hashCopy.opacity, 'Check if animate changed the hash parameter' ); + }); + // using contents will get comments regular, text, and comment nodes + $("#nonnodes").contents().animate({paddingLeft:"5px"}, 100, function () { + equals(this.nodeType, 1, "Check node,textnode,comment animate just does real nodes" ); + equals($(this).css("paddingLeft"), "5px", "Check node,textnode,comment animate just does real nodes" ); start(); }); }); @@ -54,21 +59,101 @@ test("queue() defaults to 'fx' type", function () { 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.animate({ width:'show' }, 1000); + $foo.animate({ width:'hide' }, 1000); + $foo.animate({ width:'show' }, 1000); + setTimeout(function(){ + 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").slideUp(1000); + $foo.animate({ width:'show' }, 1000); + $foo.animate({ width:'hide' }, 1000); + $foo.animate({ width:'show' }, 1000); + $foo.animate({ width:'hide' }, 1000); setTimeout(function(){ - var nh = foo.style.height; - ok( nh != h, "An animation occurred " + nh + " " + h ); - $("#foo").stop(); + 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 +162,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 = {