michael@0: module("fx"); michael@0: michael@0: test("animate(Hash, Object, Function)", function() { michael@0: expect(1); michael@0: stop(); michael@0: var hash = {opacity: 'show'}; michael@0: var hashCopy = $.extend({}, hash); michael@0: $('#foo').animate(hash, 0, function() { michael@0: equals( hash.opacity, hashCopy.opacity, 'Check if animate changed the hash parameter' ); michael@0: start(); michael@0: }); michael@0: }); michael@0: michael@0: /* Commented out because of bug 450190 michael@0: test("animate option (queue === false)", function () { michael@0: expect(1); michael@0: stop(); michael@0: michael@0: var order = []; michael@0: michael@0: var $foo = $("#foo"); michael@0: $foo.animate({width:'100px'}, 200, function () { michael@0: // should finish after unqueued animation so second michael@0: order.push(2); michael@0: }); michael@0: $foo.animate({fontSize:'2em'}, {queue:false, duration:10, complete:function () { michael@0: // short duration and out of queue so should finish first michael@0: order.push(1); michael@0: }}); michael@0: $foo.animate({height:'100px'}, 10, function() { michael@0: // queued behind the first animation so should finish third michael@0: order.push(3); michael@0: isSet( order, [ 1, 2, 3], "Animations finished in the correct order" ); michael@0: start(); michael@0: }); michael@0: }); michael@0: */ michael@0: michael@0: test("queue() defaults to 'fx' type", function () { michael@0: expect(2); michael@0: stop(); michael@0: michael@0: var $foo = $("#foo"); michael@0: $foo.queue("fx", [ "sample", "array" ]); michael@0: var arr = $foo.queue(); michael@0: isSet(arr, [ "sample", "array" ], "queue() got an array set with type 'fx'"); michael@0: $foo.queue([ "another", "one" ]); michael@0: var arr = $foo.queue("fx"); michael@0: isSet(arr, [ "another", "one" ], "queue('fx') got an array set with no type"); michael@0: // clean up after test michael@0: $foo.queue([]); michael@0: michael@0: start(); michael@0: }); michael@0: michael@0: test("stop()", function() { michael@0: expect(3); michael@0: stop(); michael@0: michael@0: var $foo = $("#nothiddendiv"); michael@0: var w = 0; michael@0: $foo.hide().width(200).width(); michael@0: michael@0: $foo.animate({ width:'show' }, 1000); michael@0: setTimeout(function(){ michael@0: var nw = $foo.width(); michael@0: ok( nw != w, "An animation occurred " + nw + "px " + w + "px"); michael@0: $foo.stop(); michael@0: michael@0: nw = $foo.width(); michael@0: ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px"); michael@0: setTimeout(function(){ michael@0: equals( nw, $foo.width(), "The animation didn't continue" ); michael@0: start(); michael@0: }, 100); michael@0: }, 100); michael@0: }); michael@0: michael@0: test("stop() - several in queue", function() { michael@0: // Merge from jquery test 1.3.2 michael@0: expect(2); michael@0: stop(); michael@0: michael@0: var $foo = $("#nothiddendiv"); michael@0: var w = 0; michael@0: $foo.hide().width(200).width(); michael@0: michael@0: $foo.animate({ width:'show' }, 1000); michael@0: $foo.animate({ width:'hide' }, 1000); michael@0: $foo.animate({ width:'show' }, 1000); michael@0: setTimeout(function(){ michael@0: // Unreliable. See bug 484994. michael@0: // equals( $foo.queue().length, 3, "All 3 still in the queue" ); michael@0: var nw = $foo.width(); michael@0: ok( nw != w, "An animation occurred " + nw + "px " + w + "px"); michael@0: $foo.stop(); michael@0: michael@0: nw = $foo.width(); michael@0: ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px"); michael@0: // Merged from 1.3.2, commented out for being flaky in 1.3.2 test suite michael@0: //equals( $foo.queue().length, 2, "The next animation continued" ); michael@0: $foo.stop(true); michael@0: start(); michael@0: }, 100); michael@0: }); michael@0: michael@0: test("stop(clearQueue)", function() { michael@0: expect(4); michael@0: stop(); michael@0: michael@0: var $foo = $("#nothiddendiv"); michael@0: var w = 0; michael@0: $foo.hide().width(200).width(); michael@0: michael@0: $foo.animate({ width:'show' }, 1000); michael@0: $foo.animate({ width:'hide' }, 1000); michael@0: $foo.animate({ width:'show' }, 1000); michael@0: setTimeout(function(){ michael@0: var nw = $foo.width(); michael@0: ok( nw != w, "An animation occurred " + nw + "px " + w + "px"); michael@0: $foo.stop(true); michael@0: michael@0: nw = $foo.width(); michael@0: ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px"); michael@0: michael@0: equals( $foo.queue().length, 0, "The animation queue was cleared" ); michael@0: setTimeout(function(){ michael@0: equals( nw, $foo.width(), "The animation didn't continue" ); michael@0: start(); michael@0: }, 100); michael@0: }, 100); michael@0: }); michael@0: michael@0: test("stop(clearQueue, gotoEnd)", function() { michael@0: // Merge from 1.3.2 - this test marked as being flaky michael@0: expect(1); michael@0: stop(); michael@0: michael@0: var $foo = $("#nothiddendiv"); michael@0: var w = 0; michael@0: $foo.hide().width(200).width(); michael@0: michael@0: $foo.animate({ width:'show' }, 1000); michael@0: $foo.animate({ width:'hide' }, 1000); michael@0: $foo.animate({ width:'show' }, 1000); michael@0: $foo.animate({ width:'hide' }, 1000); michael@0: setTimeout(function(){ michael@0: var nw = $foo.width(); michael@0: ok( nw != w, "An animation occurred " + nw + "px " + w + "px"); michael@0: $foo.stop(false, true); michael@0: michael@0: nw = $foo.width(); michael@0: // Merge from 1.3.2 - marked as flaky in that release michael@0: //equals( nw, 200, "Stop() reset the animation" ); michael@0: michael@0: setTimeout(function(){ michael@0: // Merge from 1.3.2 - marked as flaky in that release michael@0: //equals( $foo.queue().length, 3, "The next animation continued" ); michael@0: $foo.stop(true); michael@0: start(); michael@0: }, 100); michael@0: }, 100); michael@0: }); michael@0: michael@0: test("toggle()", function() { michael@0: expect(3); michael@0: var x = $("#foo"); michael@0: ok( x.is(":visible"), "is visible" ); michael@0: x.toggle(); michael@0: ok( x.is(":hidden"), "is hidden" ); michael@0: x.toggle(); michael@0: ok( x.is(":visible"), "is visible again" ); michael@0: }); michael@0: michael@0: var visible = { michael@0: Normal: function(elem){}, michael@0: "CSS Hidden": function(elem){ michael@0: $(this).addClass("hidden"); michael@0: }, michael@0: "JS Hidden": function(elem){ michael@0: $(this).hide(); michael@0: } michael@0: }; michael@0: michael@0: var from = { michael@0: "CSS Auto": function(elem,prop){ michael@0: $(elem).addClass("auto" + prop) michael@0: .text("This is a long string of text."); michael@0: return ""; michael@0: }, michael@0: "JS Auto": function(elem,prop){ michael@0: $(elem).css(prop,"auto") michael@0: .text("This is a long string of text."); michael@0: return ""; michael@0: }, michael@0: "CSS 100": function(elem,prop){ michael@0: $(elem).addClass("large" + prop); michael@0: return ""; michael@0: }, michael@0: "JS 100": function(elem,prop){ michael@0: $(elem).css(prop,prop == "opacity" ? 1 : "100px"); michael@0: return prop == "opacity" ? 1 : 100; michael@0: }, michael@0: "CSS 50": function(elem,prop){ michael@0: $(elem).addClass("med" + prop); michael@0: return ""; michael@0: }, michael@0: "JS 50": function(elem,prop){ michael@0: $(elem).css(prop,prop == "opacity" ? 0.50 : "50px"); michael@0: return prop == "opacity" ? 0.5 : 50; michael@0: }, michael@0: "CSS 0": function(elem,prop){ michael@0: $(elem).addClass("no" + prop); michael@0: return ""; michael@0: }, michael@0: "JS 0": function(elem,prop){ michael@0: $(elem).css(prop,prop == "opacity" ? 0 : "0px"); michael@0: return 0; michael@0: } michael@0: }; michael@0: michael@0: var to = { michael@0: "show": function(elem,prop){ michael@0: $(elem).hide().addClass("wide"+prop); michael@0: return "show"; michael@0: }, michael@0: "hide": function(elem,prop){ michael@0: $(elem).addClass("wide"+prop); michael@0: return "hide"; michael@0: }, michael@0: "100": function(elem,prop){ michael@0: $(elem).addClass("wide"+prop); michael@0: return prop == "opacity" ? 1 : 100; michael@0: }, michael@0: "50": function(elem,prop){ michael@0: return prop == "opacity" ? 0.50 : 50; michael@0: }, michael@0: "0": function(elem,prop){ michael@0: $(elem).addClass("noback"); michael@0: return 0; michael@0: } michael@0: }; michael@0: michael@0: function checkOverflowDisplay(){ michael@0: var o = jQuery.css( this, "overflow" ); michael@0: michael@0: equals(o, "visible", "Overflow should be visible: " + o); michael@0: equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with."); michael@0: michael@0: start(); michael@0: } michael@0: michael@0: test("JS Overflow and Display", function() { michael@0: expect(2); michael@0: stop(); michael@0: makeTest( "JS Overflow and Display" ) michael@0: .addClass("widewidth") michael@0: .css({ overflow: "visible", display: "inline" }) michael@0: .addClass("widewidth") michael@0: .text("Some sample text.") michael@0: .before("text before") michael@0: .after("text after") michael@0: .animate({ opacity: 0.5 }, "slow", checkOverflowDisplay); michael@0: }); michael@0: michael@0: test("CSS Overflow and Display", function() { michael@0: expect(2); michael@0: stop(); michael@0: makeTest( "CSS Overflow and Display" ) michael@0: .addClass("overflow inline") michael@0: .addClass("widewidth") michael@0: .text("Some sample text.") michael@0: .before("text before") michael@0: .after("text after") michael@0: .animate({ opacity: 0.5 }, "slow", checkOverflowDisplay); michael@0: }); michael@0: michael@0: jQuery.each( from, function(fn, f){ michael@0: jQuery.each( to, function(tn, t){ michael@0: test(fn + " to " + tn, function() { michael@0: var elem = makeTest( fn + " to " + tn ); michael@0: michael@0: var t_w = t( elem, "width" ); michael@0: var f_w = f( elem, "width" ); michael@0: var t_h = t( elem, "height" ); michael@0: var f_h = f( elem, "height" ); michael@0: var t_o = t( elem, "opacity" ); michael@0: var f_o = f( elem, "opacity" ); michael@0: michael@0: var num = 0; michael@0: michael@0: if ( t_h == "show" ) num++; michael@0: if ( t_w == "show" ) num++; michael@0: if ( t_w == "hide"||t_w == "show" ) num++; michael@0: if ( t_h == "hide"||t_h == "show" ) num++; michael@0: if ( t_o == "hide"||t_o == "show" ) num++; michael@0: if ( t_w == "hide" ) num++; michael@0: if ( t_o.constructor == Number ) num += 2; michael@0: if ( t_w.constructor == Number ) num += 2; michael@0: if ( t_h.constructor == Number ) num +=2; michael@0: michael@0: expect(num); michael@0: stop(); michael@0: michael@0: var anim = { width: t_w, height: t_h, opacity: t_o }; michael@0: michael@0: elem.animate(anim, 50, function(){ michael@0: if ( t_w == "show" ) michael@0: equals( this.style.display, "block", "Showing, display should block: " + this.style.display); michael@0: michael@0: if ( t_w == "hide"||t_w == "show" ) michael@0: equals(this.style.width.indexOf(f_w), 0, "Width must be reset to " + f_w + ": " + this.style.width); michael@0: michael@0: if ( t_h == "hide"||t_h == "show" ) michael@0: equals(this.style.height.indexOf(f_h), 0, "Height must be reset to " + f_h + ": " + this.style.height); michael@0: michael@0: var cur_o = jQuery.attr(this.style, "opacity"); michael@0: if ( cur_o !== "" ) cur_o = parseFloat( cur_o ); michael@0: michael@0: if ( t_o == "hide"||t_o == "show" ) michael@0: equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o); michael@0: michael@0: if ( t_w == "hide" ) michael@0: equals(this.style.display, "none", "Hiding, display should be none: " + this.style.display); michael@0: michael@0: if ( t_o.constructor == Number ) { michael@0: equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o); michael@0: michael@0: ok(jQuery.curCSS(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o); michael@0: } michael@0: michael@0: if ( t_w.constructor == Number ) { michael@0: equals(this.style.width, t_w + "px", "Final width should be " + t_w + ": " + this.style.width); michael@0: michael@0: var cur_w = jQuery.css(this,"width"); michael@0: michael@0: ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w); michael@0: } michael@0: michael@0: if ( t_h.constructor == Number ) { michael@0: equals(this.style.height, t_h + "px", "Final height should be " + t_h + ": " + this.style.height); michael@0: michael@0: var cur_h = jQuery.css(this,"height"); michael@0: michael@0: ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w); michael@0: } michael@0: michael@0: if ( t_h == "show" ) { michael@0: var old_h = jQuery.curCSS(this, "height"); michael@0: $(elem).append("
Some more text
and some more..."); michael@0: ok(old_h != jQuery.css(this, "height" ), "Make sure height is auto."); michael@0: } michael@0: michael@0: start(); michael@0: }); michael@0: }); michael@0: }); michael@0: }); michael@0: michael@0: var check = ['opacity','height','width','display','overflow']; michael@0: michael@0: jQuery.fn.saveState = function(){ michael@0: expect(check.length); michael@0: stop(); michael@0: return this.each(function(){ michael@0: var self = this; michael@0: self.save = {}; michael@0: jQuery.each(check, function(i,c){ michael@0: self.save[c] = jQuery.css(self,c); michael@0: }); michael@0: }); michael@0: }; michael@0: michael@0: function checkState(){ michael@0: var self = this; michael@0: jQuery.each(this.save, function(c,v){ michael@0: var cur = jQuery.css(self,c); michael@0: equals( v, cur, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")"); michael@0: }); michael@0: start(); michael@0: } michael@0: michael@0: // Chaining Tests michael@0: test("Chain fadeOut fadeIn", function() { michael@0: $('#fadein div').saveState().fadeOut('fast').fadeIn('fast',checkState); michael@0: }); michael@0: test("Chain fadeIn fadeOut", function() { michael@0: $('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',checkState); michael@0: }); michael@0: michael@0: test("Chain hide show", function() { michael@0: $('#show div').saveState().hide('fast').show('fast',checkState); michael@0: }); michael@0: test("Chain show hide", function() { michael@0: $('#hide div').saveState().show('fast').hide('fast',checkState); michael@0: }); michael@0: michael@0: test("Chain toggle in", function() { michael@0: $('#togglein div').saveState().toggle('fast').toggle('fast',checkState); michael@0: }); michael@0: test("Chain toggle out", function() { michael@0: $('#toggleout div').saveState().toggle('fast').toggle('fast',checkState); michael@0: }); michael@0: michael@0: test("Chain slideDown slideUp", function() { michael@0: $('#slidedown div').saveState().slideDown('fast').slideUp('fast',checkState); michael@0: }); michael@0: test("Chain slideUp slideDown", function() { michael@0: $('#slideup div').saveState().slideUp('fast').slideDown('fast',checkState); michael@0: }); michael@0: michael@0: test("Chain slideToggle in", function() { michael@0: $('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',checkState); michael@0: }); michael@0: test("Chain slideToggle out", function() { michael@0: $('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',checkState); michael@0: }); michael@0: michael@0: function makeTest( text ){ michael@0: var elem = $("
") michael@0: .attr("id", "test" + makeTest.id++) michael@0: .addClass("box"); michael@0: michael@0: $("

") michael@0: .text( text ) michael@0: .appendTo("#fx-tests") michael@0: .click(function(){ michael@0: $(this).next().toggle(); michael@0: }) michael@0: .after( elem ); michael@0: michael@0: return elem; michael@0: } michael@0: michael@0: makeTest.id = 1;