3 test("show()", function() {
5 var pass = true, div = jQuery("#main div");
6 div.show().each(function(){
7 if ( this.style.display == "none" ) pass = false;
11 jQuery("#main").append('<div id="show-tests"><div><p><a href="#"></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div>');
13 var old = jQuery("#show-tests table").show().css("display") !== "table";
22 "table" : old ? "block" : "table",
23 "thead" : old ? "block" : "table-header-group",
24 "tbody" : old ? "block" : "table-row-group",
25 "tr" : old ? "block" : "table-row",
26 "th" : old ? "block" : "table-cell",
27 "td" : old ? "block" : "table-cell",
29 "li" : old ? "block" : "list-item"
32 jQuery.each(test, function(selector, expected) {
33 var elem = jQuery(selector, "#show-tests").show();
34 equals( elem.css("display"), expected, "Show using correct display type for " + selector );
38 test("animate(Hash, Object, Function)", function() {
41 var hash = {opacity: 'show'};
42 var hashCopy = jQuery.extend({}, hash);
43 jQuery('#foo').animate(hash, 0, function() {
44 equals( hash.opacity, hashCopy.opacity, 'Check if animate changed the hash parameter' );
49 /* // This test ends up being flaky depending upon the CPU load
50 test("animate option (queue === false)", function () {
56 var $foo = jQuery("#foo");
57 $foo.animate({width:'100px'}, 3000, function () {
58 // should finish after unqueued animation so second
60 same( order, [ 1, 2 ], "Animations finished in the correct order" );
63 $foo.animate({fontSize:'2em'}, {queue:false, duration:10, complete:function () {
64 // short duration and out of queue so should finish first
70 test("animate with no properties", function() {
73 var divs = jQuery("div"), count = 0;
75 divs.animate({}, function(){
79 equals( divs.length, count, "Make sure that callback is called for each element in the set." );
82 test("animate duration 0", function() {
87 var $elems = jQuery([{ a:0 },{ a:0 }]),
93 equals( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
95 $elems.eq(0).animate( {a:1}, 0, count );
97 // Failed until [6115]
98 equals( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" );
100 equals( counter, 1, "One synchronic animations" );
102 $elems.animate( { a:2 }, 0, count );
104 equals( counter, 3, "Multiple synchronic animations" );
106 $elems.eq(0).animate( {a:3}, 0, count );
107 $elems.eq(1).animate( {a:3}, 20, function(){
109 // Failed until [6115]
110 equals( counter, 5, "One synchronic and one asynchronic" );
114 var $elem = jQuery("<div />");
115 $elem.show(0, function(){
116 ok(true, "Show's callback with no duration");
118 $elem.hide(0, function(){
119 ok(true, "Show's callback with no duration");
123 test("animate hyphenated properties", function(){
127 jQuery("#nothiddendiv")
128 .css("font-size", 10)
129 .animate({"font-size": 20}, 200, function(){
130 equals( this.style.fontSize, "20px", "The font-size property was animated." );
135 test("animate non-element", function(){
139 var obj = { test: 0 };
141 jQuery(obj).animate({test: 200}, 200, function(){
142 equals( obj.test, 200, "The custom property should be modified." );
147 test("stop()", function() {
151 var $foo = jQuery("#nothiddendiv");
153 $foo.hide().width(200).width();
155 $foo.animate({ width:'show' }, 1000);
156 setTimeout(function(){
157 var nw = $foo.width();
158 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
162 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
163 setTimeout(function(){
164 equals( nw, $foo.width(), "The animation didn't continue" );
170 test("stop() - several in queue", function() {
174 var $foo = jQuery("#nothiddendivchild");
176 $foo.hide().width(200).width();
178 $foo.animate({ width:'show' }, 1000);
179 $foo.animate({ width:'hide' }, 1000);
180 $foo.animate({ width:'show' }, 1000);
181 setTimeout(function(){
182 equals( $foo.queue().length, 3, "All 3 still in the queue" );
183 var nw = $foo.width();
184 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
188 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
189 // Disabled, being flaky
190 //equals( $foo.queue().length, 1, "The next animation continued" );
196 test("stop(clearQueue)", function() {
200 var $foo = jQuery("#nothiddendiv");
202 $foo.hide().width(200).width();
204 $foo.animate({ width:'show' }, 1000);
205 $foo.animate({ width:'hide' }, 1000);
206 $foo.animate({ width:'show' }, 1000);
207 setTimeout(function(){
208 var nw = $foo.width();
209 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
213 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
215 equals( $foo.queue().length, 0, "The animation queue was cleared" );
216 setTimeout(function(){
217 equals( nw, $foo.width(), "The animation didn't continue" );
223 test("stop(clearQueue, gotoEnd)", function() {
227 var $foo = jQuery("#nothiddendivchild");
229 $foo.hide().width(200).width();
231 $foo.animate({ width:'show' }, 1000);
232 $foo.animate({ width:'hide' }, 1000);
233 $foo.animate({ width:'show' }, 1000);
234 $foo.animate({ width:'hide' }, 1000);
235 setTimeout(function(){
236 var nw = $foo.width();
237 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
238 $foo.stop(false, true);
241 // Disabled, being flaky
242 //equals( nw, 1, "Stop() reset the animation" );
244 setTimeout(function(){
245 // Disabled, being flaky
246 //equals( $foo.queue().length, 2, "The next animation continued" );
253 test("toggle()", function() {
255 var x = jQuery("#nothiddendiv");
256 ok( x.is(":visible"), "is visible" );
258 ok( x.is(":hidden"), "is hidden" );
260 ok( x.is(":visible"), "is visible again" );
263 ok( x.is(":visible"), "is visible" );
265 ok( x.is(":hidden"), "is hidden" );
267 ok( x.is(":visible"), "is visible again" );
270 jQuery.checkOverflowDisplay = function(){
271 var o = jQuery.css( this, "overflow" );
273 equals(o, "visible", "Overflow should be visible: " + o);
274 equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
279 test("JS Overflow and Display", function() {
282 jQuery.makeTest( "JS Overflow and Display" )
283 .addClass("widewidth")
284 .css({ overflow: "visible", display: "inline" })
285 .addClass("widewidth")
286 .text("Some sample text.")
287 .before("text before")
289 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
292 test("CSS Overflow and Display", function() {
295 jQuery.makeTest( "CSS Overflow and Display" )
296 .addClass("overflow inline")
297 .addClass("widewidth")
298 .text("Some sample text.")
299 .before("text before")
301 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
305 "CSS Auto": function(elem,prop){
306 jQuery(elem).addClass("auto" + prop)
307 .text("This is a long string of text.");
310 "JS Auto": function(elem,prop){
311 jQuery(elem).css(prop,"auto")
312 .text("This is a long string of text.");
315 "CSS 100": function(elem,prop){
316 jQuery(elem).addClass("large" + prop);
319 "JS 100": function(elem,prop){
320 jQuery(elem).css(prop,prop == "opacity" ? 1 : "100px");
321 return prop == "opacity" ? 1 : 100;
323 "CSS 50": function(elem,prop){
324 jQuery(elem).addClass("med" + prop);
327 "JS 50": function(elem,prop){
328 jQuery(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
329 return prop == "opacity" ? 0.5 : 50;
331 "CSS 0": function(elem,prop){
332 jQuery(elem).addClass("no" + prop);
335 "JS 0": function(elem,prop){
336 jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px");
341 "show": function(elem,prop){
342 jQuery(elem).hide().addClass("wide"+prop);
345 "hide": function(elem,prop){
346 jQuery(elem).addClass("wide"+prop);
349 "100": function(elem,prop){
350 jQuery(elem).addClass("wide"+prop);
351 return prop == "opacity" ? 1 : 100;
353 "50": function(elem,prop){
354 return prop == "opacity" ? 0.50 : 50;
356 "0": function(elem,prop){
357 jQuery(elem).addClass("noback");
361 test(fn + " to " + tn, function() {
362 var elem = jQuery.makeTest( fn + " to " + tn );
364 var t_w = t( elem, "width" );
365 var f_w = f( elem, "width" );
366 var t_h = t( elem, "height" );
367 var f_h = f( elem, "height" );
368 var t_o = t( elem, "opacity" );
369 var f_o = f( elem, "opacity" );
373 if ( t_h == "show" ) num++;
374 if ( t_w == "show" ) num++;
375 if ( t_w == "hide"||t_w == "show" ) num++;
376 if ( t_h == "hide"||t_h == "show" ) num++;
377 if ( t_o == "hide"||t_o == "show" ) num++;
378 if ( t_w == "hide" ) num++;
379 if ( t_o.constructor == Number ) num += 2;
380 if ( t_w.constructor == Number ) num += 2;
381 if ( t_h.constructor == Number ) num +=2;
386 var anim = { width: t_w, height: t_h, opacity: t_o };
388 elem.animate(anim, 50, function(){
390 equals( this.style.display, "block", "Showing, display should block: " + this.style.display);
392 if ( t_w == "hide"||t_w == "show" )
393 equals(this.style.width.indexOf(f_w), 0, "Width must be reset to " + f_w + ": " + this.style.width);
395 if ( t_h == "hide"||t_h == "show" )
396 equals(this.style.height.indexOf(f_h), 0, "Height must be reset to " + f_h + ": " + this.style.height);
398 var cur_o = jQuery.style(this, "opacity");
399 if ( cur_o !== "" ) cur_o = parseFloat( cur_o );
401 if ( t_o == "hide"||t_o == "show" )
402 equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
405 equals(this.style.display, "none", "Hiding, display should be none: " + this.style.display);
407 if ( t_o.constructor == Number ) {
408 equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o);
410 ok(jQuery.curCSS(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
413 if ( t_w.constructor == Number ) {
414 equals(this.style.width, t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
416 var cur_w = jQuery.css(this,"width");
418 ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
421 if ( t_h.constructor == Number ) {
422 equals(this.style.height, t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
424 var cur_h = jQuery.css(this,"height");
426 ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
429 if ( t_h == "show" ) {
430 var old_h = jQuery.curCSS(this, "height");
431 jQuery(elem).append("<br/>Some more text<br/>and some more...");
432 ok(old_h != jQuery.css(this, "height" ), "Make sure height is auto.");
441 jQuery.fn.saveState = function(){
442 var check = ['opacity','height','width','display','overflow'];
443 expect(check.length);
446 return this.each(function(){
449 jQuery.each(check, function(i,c){
450 self.save[c] = jQuery.css(self,c);
455 jQuery.checkState = function(){
457 jQuery.each(this.save, function(c,v){
458 var cur = jQuery.css(self,c);
459 equals( v, cur, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
465 test("Chain fadeOut fadeIn", function() {
466 jQuery('#fadein div').saveState().fadeOut('fast').fadeIn('fast',jQuery.checkState);
468 test("Chain fadeIn fadeOut", function() {
469 jQuery('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',jQuery.checkState);
472 test("Chain hide show", function() {
473 jQuery('#show div').saveState().hide('fast').show('fast',jQuery.checkState);
475 test("Chain show hide", function() {
476 jQuery('#hide div').saveState().show('fast').hide('fast',jQuery.checkState);
479 test("Chain toggle in", function() {
480 jQuery('#togglein div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
482 test("Chain toggle out", function() {
483 jQuery('#toggleout div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
486 test("Chain slideDown slideUp", function() {
487 jQuery('#slidedown div').saveState().slideDown('fast').slideUp('fast',jQuery.checkState);
489 test("Chain slideUp slideDown", function() {
490 jQuery('#slideup div').saveState().slideUp('fast').slideDown('fast',jQuery.checkState);
493 test("Chain slideToggle in", function() {
494 jQuery('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
496 test("Chain slideToggle out", function() {
497 jQuery('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
500 jQuery.makeTest = function( text ){
501 var elem = jQuery("<div></div>")
502 .attr("id", "test" + jQuery.makeTest.id++)
507 .appendTo("#fx-tests")
509 jQuery(this).next().toggle();
516 jQuery.makeTest.id = 1;