Fixes #7397; Adds 4 supporting unit tests.
[jquery.git] / test / unit / effects.js
1 module("effects");
2
3 test("sanity check", function() {
4         expect(1);
5         ok( jQuery("#dl:visible, #main:visible, #foo:visible").length === 3, "QUnit state is correct for testing effects" );
6 });
7
8 test("show()", function() {
9         expect(28);
10
11         var hiddendiv = jQuery("div.hidden");
12
13         hiddendiv.hide().show();
14
15         equals( hiddendiv.css("display"), "block", "Make sure a pre-hidden div is visible." );
16
17         var div = jQuery("<div>").hide().appendTo("body").show();
18
19         equal( div.css("display"), "block", "Make sure pre-hidden divs show" );
20
21         QUnit.reset();
22
23         hiddendiv = jQuery("div.hidden");
24
25         equal(jQuery.css( hiddendiv[0], "display"), "none", "hiddendiv is display: none");
26
27         hiddendiv.css("display", "block");
28         equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
29
30         hiddendiv.show();
31         equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
32
33         hiddendiv.css("display","");
34
35         var pass = true, div = jQuery("#main div");
36         div.show().each(function(){
37                 if ( this.style.display == "none" ) pass = false;
38         });
39         ok( pass, "Show" );
40
41         var speeds = {
42           "null speed": null,
43           "undefined speed": undefined,
44           "empty string speed": "",
45           "false speed": false
46         };
47
48         jQuery.each(speeds, function(name, speed) {
49     pass = true;
50         div.hide().show(speed).each(function() {
51                 if ( this.style.display == "none" ) pass = false;
52         });
53         ok( pass, "Show with " + name);
54   });
55
56
57         jQuery.each(speeds, function(name, speed) {
58     pass = true;
59         div.hide().show(speed, function() {
60                         pass = false;
61                 });
62                 ok( pass, "Show with " + name + " does not call animate callback" );
63         });
64
65         // #show-tests * is set display: none in CSS
66         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><table id="test-table"></table>');
67         
68         var old = jQuery("#test-table").show().css("display") !== "table";
69         jQuery("#test-table").remove();
70
71         var test = {
72                 "div"      : "block",
73                 "p"        : "block",
74                 "a"        : "inline",
75                 "code"     : "inline",
76                 "pre"      : "block",
77                 "span"     : "inline",
78                 "table"    : old ? "block" : "table",
79                 "thead"    : old ? "block" : "table-header-group",
80                 "tbody"    : old ? "block" : "table-row-group",
81                 "tr"       : old ? "block" : "table-row",
82                 "th"       : old ? "block" : "table-cell",
83                 "td"       : old ? "block" : "table-cell",
84                 "ul"       : "block",
85                 "li"       : old ? "block" : "list-item"
86         };
87
88         jQuery.each(test, function(selector, expected) {
89                 var elem = jQuery(selector, "#show-tests").show();
90                 equals( elem.css("display"), expected, "Show using correct display type for " + selector );
91         });
92 });
93
94 test("show(Number) - other displays", function() {
95         expect(15);
96         QUnit.reset();
97         stop();
98
99         // #show-tests * is set display: none in CSS
100         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><table id="test-table"></table>');
101
102         var old = jQuery("#test-table").show().css("display") !== "table",
103                 num = 0;
104         jQuery("#test-table").remove();
105
106         var test = {
107                 "div"      : "block",
108                 "p"        : "block",
109                 "a"        : "inline",
110                 "code"     : "inline",
111                 "pre"      : "block",
112                 "span"     : "inline",
113                 "table"    : old ? "block" : "table",
114                 "thead"    : old ? "block" : "table-header-group",
115                 "tbody"    : old ? "block" : "table-row-group",
116                 "tr"       : old ? "block" : "table-row",
117                 "th"       : old ? "block" : "table-cell",
118                 "td"       : old ? "block" : "table-cell",
119                 "ul"       : "block",
120                 "li"       : old ? "block" : "list-item"
121         };
122
123         jQuery.each(test, function(selector, expected) {
124                 var elem = jQuery(selector, "#show-tests").show(1, function() {
125                         equals( elem.css("display"), expected, "Show using correct display type for " + selector );
126                         if ( ++num === 15 ) {
127                                 start();
128                         }
129                 });
130         });
131 });
132
133
134
135 //  Supports #7397
136 test("Persist correct display value", function() {
137   expect(4);
138         QUnit.reset();
139         stop();
140
141         // #show-tests * is set display: none in CSS
142         jQuery("#main").append('<div id="show-tests"><span style="position:absolute;"></span></div>');
143   
144         var $span = jQuery("#show-tests span"),  
145           orig = $span.css("display"),
146                 num = 0;
147                 
148   equal(orig, "none", "Expecting to start at display: none");
149
150   $span.text('Saving...').fadeIn(100, function() {
151
152     equal($span.css("display"), "block", "Expecting display: block");
153
154     $span.text('Saved!').fadeOut(100, function () {
155   
156       equal($span.css("display"), "none", "Expecting display: none");
157       
158       $span.text('Saving...').fadeIn(100, function() {
159       
160         equal($span.css("display"), "block", "Expecting display: block");
161       
162         start();
163       });
164     });
165   });
166 });
167
168 test("animate(Hash, Object, Function)", function() {
169         expect(1);
170         stop();
171         var hash = {opacity: 'show'};
172         var hashCopy = jQuery.extend({}, hash);
173         jQuery('#foo').animate(hash, 0, function() {
174                 equals( hash.opacity, hashCopy.opacity, 'Check if animate changed the hash parameter' );
175                 start();
176         });
177 });
178
179 test("animate negative height", function() {
180         expect(1);
181         stop();
182         jQuery("#foo").animate({ height: -100 }, 100, function() {
183                 equals( this.offsetHeight, 0, "Verify height." );
184                 start();
185         });
186 });
187
188 test("animate block as inline width/height", function() {
189         expect(3);
190
191         var span = jQuery("<span>").css("display", "inline-block").appendTo("body"),
192                 expected = span.css("display");
193         
194         span.remove();
195
196         if ( jQuery.support.inlineBlockNeedsLayout || expected === "inline-block" ) {
197                 stop();
198
199                 jQuery("#foo").css({ display: "inline", width: '', height: '' }).animate({ width: 42, height: 42 }, 100, function() {
200                         equals( jQuery(this).css("display"), jQuery.support.inlineBlockNeedsLayout ? "inline" : "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
201                         equals( this.offsetWidth, 42, "width was animated" );
202                         equals( this.offsetHeight, 42, "height was animated" );
203                         start();
204                 });
205
206         // Browser doesn't support inline-block
207         } else {
208                 ok( true, "Browser doesn't support inline-block" );
209                 ok( true, "Browser doesn't support inline-block" );
210                 ok( true, "Browser doesn't support inline-block" );
211         }
212 });
213
214 test("animate native inline width/height", function() {
215         expect(3);
216
217         var span = jQuery("<span>").css("display", "inline-block").appendTo("body"),
218                 expected = span.css("display");
219         
220         span.remove();
221
222         if ( jQuery.support.inlineBlockNeedsLayout || expected === "inline-block" ) {
223                 stop();
224                 jQuery("#foo").css({ display: "", width: '', height: '' })
225                         .append('<span>text</span>')
226                         .children('span')
227                                 .animate({ width: 42, height: 42 }, 100, function() {
228                                         equals( jQuery(this).css("display"), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
229                                         equals( this.offsetWidth, 42, "width was animated" );
230                                         equals( this.offsetHeight, 42, "height was animated" );
231                                         start();
232                                 });
233
234         // Browser doesn't support inline-block
235         } else {
236                 ok( true, "Browser doesn't support inline-block" );
237                 ok( true, "Browser doesn't support inline-block" );
238                 ok( true, "Browser doesn't support inline-block" );
239         }
240 });
241
242 test("animate block width/height", function() {
243         expect(3);
244         stop();
245         jQuery("#foo").css({ display: "block", width: 20, height: 20 }).animate({ width: 42, height: 42 }, 100, function() {
246                 equals( jQuery(this).css("display"), "block", "inline-block was not set on block element when animating width/height" );
247                 equals( this.offsetWidth, 42, "width was animated" );
248                 equals( this.offsetHeight, 42, "height was animated" );
249                 start();
250         });
251 });
252
253 test("animate table width/height", function() {
254         expect(1);
255         stop();
256
257         var displayMode = jQuery("#table").css("display") !== "table" ? "block" : "table";
258
259         jQuery("#table").animate({ width: 42, height: 42 }, 100, function() {
260                 equals( jQuery(this).css("display"), displayMode, "display mode is correct" );
261                 start();
262         });
263 });
264
265 test("animate table-row width/height", function() {
266         expect(3);
267         stop();
268         var tr = jQuery("#table")
269                 .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
270                 .html("<tr style='height:42px;'><td style='padding:0;'><div style='width:20px;height:20px;'></div></td></tr>")
271                 .find("tr");
272
273         // IE<8 uses “block” instead of the correct display type
274         var displayMode = tr.css("display") !== "table-row" ? "block" : "table-row";
275
276         tr.animate({ width: 10, height: 10 }, 100, function() {
277                 equals( jQuery(this).css("display"), displayMode, "display mode is correct" );
278                 equals( this.offsetWidth, 20, "width animated to shrink wrap point" );
279                 equals( this.offsetHeight, 20, "height animated to shrink wrap point" );
280                 start();
281         });
282 });
283
284 test("animate table-cell width/height", function() {
285         expect(3);
286         stop();
287         var td = jQuery("#table")
288                 .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
289                 .html("<tr><td style='width:42px;height:42px;padding:0;'><div style='width:20px;height:20px;'></div></td></tr>")
290                 .find("td");
291
292         // IE<8 uses “block” instead of the correct display type
293         var displayMode = td.css("display") !== "table-cell" ? "block" : "table-cell";
294
295         td.animate({ width: 10, height: 10 }, 100, function() {
296                 equals( jQuery(this).css("display"), displayMode, "display mode is correct" );
297                 equals( this.offsetWidth, 20, "width animated to shrink wrap point" );
298                 equals( this.offsetHeight, 20, "height animated to shrink wrap point" );
299                 start();
300         });
301 });
302
303 test("animate resets overflow-x and overflow-y when finished", function() {
304         expect(2);
305         stop();
306         jQuery("#foo")
307                 .css({ display: "block", width: 20, height: 20, overflowX: "visible", overflowY: "auto" })
308                 .animate({ width: 42, height: 42 }, 100, function() {
309                         equals( this.style.overflowX, "visible", "overflow-x is visible" );
310                         equals( this.style.overflowY, "auto", "overflow-y is auto" );
311                         start();
312                 });
313 });
314
315 /* // This test ends up being flaky depending upon the CPU load
316 test("animate option (queue === false)", function () {
317         expect(1);
318         stop();
319
320         var order = [];
321
322         var $foo = jQuery("#foo");
323         $foo.animate({width:'100px'}, 3000, function () {
324                 // should finish after unqueued animation so second
325                 order.push(2);
326                 same( order, [ 1, 2 ], "Animations finished in the correct order" );
327                 start();
328         });
329         $foo.animate({fontSize:'2em'}, {queue:false, duration:10, complete:function () {
330                 // short duration and out of queue so should finish first
331                 order.push(1);
332         }});
333 });
334 */
335
336 test("animate with no properties", function() {
337         expect(2);
338
339         var divs = jQuery("div"), count = 0;
340
341         divs.animate({}, function(){
342                 count++;
343         });
344
345         equals( divs.length, count, "Make sure that callback is called for each element in the set." );
346
347         stop();
348
349         var foo = jQuery("#foo");
350
351         foo.animate({});
352         foo.animate({top: 10}, 100, function(){
353                 ok( true, "Animation was properly dequeued." );
354                 start();
355         });
356 });
357
358 test("animate duration 0", function() {
359         expect(11);
360
361         stop();
362
363         var $elems = jQuery([{ a:0 },{ a:0 }]), counter = 0;
364
365         equals( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
366
367         $elems.eq(0).animate( {a:1}, 0, function(){
368                 ok( true, "Animate a simple property." );
369                 counter++;
370         });
371
372         // Failed until [6115]
373         equals( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" );
374
375         equals( counter, 1, "One synchronic animations" );
376
377         $elems.animate( { a:2 }, 0, function(){
378                 ok( true, "Animate a second simple property." );
379                 counter++;
380         });
381
382         equals( counter, 3, "Multiple synchronic animations" );
383
384         $elems.eq(0).animate( {a:3}, 0, function(){
385                 ok( true, "Animate a third simple property." );
386                 counter++;
387         });
388         $elems.eq(1).animate( {a:3}, 200, function(){
389                 counter++;
390                 // Failed until [6115]
391                 equals( counter, 5, "One synchronic and one asynchronic" );
392                 start();
393         });
394
395         var $elem = jQuery("<div />");
396         $elem.show(0, function(){
397                 ok(true, "Show callback with no duration");
398         });
399         $elem.hide(0, function(){
400                 ok(true, "Hide callback with no duration");
401         });
402 });
403
404 test("animate hyphenated properties", function(){
405         expect(1);
406         stop();
407
408         jQuery("#nothiddendiv")
409                 .css("font-size", 10)
410                 .animate({"font-size": 20}, 200, function(){
411                         equals( this.style.fontSize, "20px", "The font-size property was animated." );
412                         start();
413                 });
414 });
415
416 test("animate non-element", function(){
417         expect(1);
418         stop();
419
420         var obj = { test: 0 };
421
422         jQuery(obj).animate({test: 200}, 200, function(){
423                 equals( obj.test, 200, "The custom property should be modified." );
424                 start();
425         });
426 });
427
428 test("stop()", function() {
429         expect(3);
430         stop();
431
432         var $foo = jQuery("#nothiddendiv");
433         var w = 0;
434         $foo.hide().width(200).width();
435
436         $foo.animate({ width:'show' }, 1000);
437         setTimeout(function(){
438                 var nw = $foo.width();
439                 notEqual( nw, w, "An animation occurred " + nw + "px " + w + "px");
440                 $foo.stop();
441
442                 nw = $foo.width();
443                 notEqual( nw, w, "Stop didn't reset the animation " + nw + "px " + w + "px");
444                 setTimeout(function(){
445                         equals( nw, $foo.width(), "The animation didn't continue" );
446                         start();
447                 }, 100);
448         }, 100);
449 });
450
451 test("stop() - several in queue", function() {
452         expect(3);
453         stop();
454
455         var $foo = jQuery("#nothiddendivchild");
456         var w = 0;
457         $foo.hide().width(200).width();
458
459         $foo.animate({ width:'show' }, 1000);
460         $foo.animate({ width:'hide' }, 1000);
461         $foo.animate({ width:'show' }, 1000);
462         setTimeout(function(){
463                 equals( $foo.queue().length, 3, "All 3 still in the queue" );
464                 var nw = $foo.width();
465                 notEqual( nw, w, "An animation occurred " + nw + "px " + w + "px");
466                 $foo.stop();
467
468                 nw = $foo.width();
469                 notEqual( nw, w, "Stop didn't reset the animation " + nw + "px " + w + "px");
470
471                 $foo.stop(true);
472                 start();
473         }, 100);
474 });
475
476 test("stop(clearQueue)", function() {
477         expect(4);
478         stop();
479
480         var $foo = jQuery("#nothiddendiv");
481         var w = 0;
482         $foo.hide().width(200).width();
483
484         $foo.animate({ width:'show' }, 1000);
485         $foo.animate({ width:'hide' }, 1000);
486         $foo.animate({ width:'show' }, 1000);
487         setTimeout(function(){
488                 var nw = $foo.width();
489                 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
490                 $foo.stop(true);
491
492                 nw = $foo.width();
493                 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
494
495                 equals( $foo.queue().length, 0, "The animation queue was cleared" );
496                 setTimeout(function(){
497                         equals( nw, $foo.width(), "The animation didn't continue" );
498                         start();
499                 }, 100);
500         }, 100);
501 });
502
503 test("stop(clearQueue, gotoEnd)", function() {
504         expect(1);
505         stop();
506
507         var $foo = jQuery("#nothiddendivchild");
508         var w = 0;
509         $foo.hide().width(200).width();
510
511         $foo.animate({ width:'show' }, 1000);
512         $foo.animate({ width:'hide' }, 1000);
513         $foo.animate({ width:'show' }, 1000);
514         $foo.animate({ width:'hide' }, 1000);
515         setTimeout(function(){
516                 var nw = $foo.width();
517                 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
518                 $foo.stop(false, true);
519
520                 nw = $foo.width();
521                 // Disabled, being flaky
522                 //equals( nw, 1, "Stop() reset the animation" );
523
524                 setTimeout(function(){
525                         // Disabled, being flaky
526                         //equals( $foo.queue().length, 2, "The next animation continued" );
527                         $foo.stop(true);
528                         start();
529                 }, 100);
530         }, 100);
531 });
532
533 test("toggle()", function() {
534         expect(6);
535         var x = jQuery("#nothiddendiv");
536         ok( x.is(":visible"), "is visible" );
537         x.toggle();
538         ok( x.is(":hidden"), "is hidden" );
539         x.toggle();
540         ok( x.is(":visible"), "is visible again" );
541
542         x.toggle(true);
543         ok( x.is(":visible"), "is visible" );
544         x.toggle(false);
545         ok( x.is(":hidden"), "is hidden" );
546         x.toggle(true);
547         ok( x.is(":visible"), "is visible again" );
548 });
549
550 jQuery.checkOverflowDisplay = function(){
551         var o = jQuery.css( this, "overflow" );
552
553         equals(o, "visible", "Overflow should be visible: " + o);
554         equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
555
556         start();
557 }
558
559 test("JS Overflow and Display", function() {
560         expect(2);
561         stop();
562         jQuery.makeTest( "JS Overflow and Display" )
563                 .addClass("widewidth")
564                 .css({ overflow: "visible", display: "inline" })
565                 .addClass("widewidth")
566                 .text("Some sample text.")
567                 .before("text before")
568                 .after("text after")
569                 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
570 });
571
572 test("CSS Overflow and Display", function() {
573         expect(2);
574         stop();
575         jQuery.makeTest( "CSS Overflow and Display" )
576                 .addClass("overflow inline")
577                 .addClass("widewidth")
578                 .text("Some sample text.")
579                 .before("text before")
580                 .after("text after")
581                 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
582 });
583
584 jQuery.each( {
585         "CSS Auto": function(elem,prop){
586                 jQuery(elem).addClass("auto" + prop)
587                         .text("This is a long string of text.");
588                 return "";
589         },
590         "JS Auto": function(elem,prop){
591                 jQuery(elem).css(prop,"")
592                         .text("This is a long string of text.");
593                 return "";
594         },
595         "CSS 100": function(elem,prop){
596                 jQuery(elem).addClass("large" + prop);
597                 return "";
598         },
599         "JS 100": function(elem,prop){
600                 jQuery(elem).css(prop,prop == "opacity" ? 1 : "100px");
601                 return prop == "opacity" ? 1 : 100;
602         },
603         "CSS 50": function(elem,prop){
604                 jQuery(elem).addClass("med" + prop);
605                 return "";
606         },
607         "JS 50": function(elem,prop){
608                 jQuery(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
609                 return prop == "opacity" ? 0.5 : 50;
610         },
611         "CSS 0": function(elem,prop){
612                 jQuery(elem).addClass("no" + prop);
613                 return "";
614         },
615         "JS 0": function(elem,prop){
616                 jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px");
617                 return 0;
618         }
619 }, function(fn, f){
620         jQuery.each( {
621                 "show": function(elem,prop){
622                         jQuery(elem).hide().addClass("wide"+prop);
623                         return "show";
624                 },
625                 "hide": function(elem,prop){
626                         jQuery(elem).addClass("wide"+prop);
627                         return "hide";
628                 },
629                 "100": function(elem,prop){
630                         jQuery(elem).addClass("wide"+prop);
631                         return prop == "opacity" ? 1 : 100;
632                 },
633                 "50": function(elem,prop){
634                         return prop == "opacity" ? 0.50 : 50;
635                 },
636                 "0": function(elem,prop){
637                         jQuery(elem).addClass("noback");
638                         return 0;
639                 }
640         }, function(tn, t){
641                 test(fn + " to " + tn, function() {
642                         var elem = jQuery.makeTest( fn + " to " + tn );
643
644                         var t_w = t( elem, "width" );
645                         var f_w = f( elem, "width" );
646                         var t_h = t( elem, "height" );
647                         var f_h = f( elem, "height" );
648                         var t_o = t( elem, "opacity" );
649                         var f_o = f( elem, "opacity" );
650
651                         var num = 0;
652
653                         if ( t_h == "show" ) num++;
654                         if ( t_w == "show" ) num++;
655                         if ( t_w == "hide"||t_w == "show" ) num++;
656                         if ( t_h == "hide"||t_h == "show" ) num++;
657                         if ( t_o == "hide"||t_o == "show" ) num++;
658                         if ( t_w == "hide" ) num++;
659                         if ( t_o.constructor == Number ) num += 2;
660                         if ( t_w.constructor == Number ) num += 2;
661                         if ( t_h.constructor == Number ) num +=2;
662
663                         expect(num);
664                         stop();
665
666                         var anim = { width: t_w, height: t_h, opacity: t_o };
667
668                         elem.animate(anim, 50, function(){
669                                 if ( t_w == "show" )
670                                         equals( this.style.display, "block", "Showing, display should block: " + this.style.display);
671
672                                 if ( t_w == "hide"||t_w == "show" )
673                                         ok(f_w === "" ? this.style.width === f_w : this.style.width.indexOf(f_w) === 0, "Width must be reset to " + f_w + ": " + this.style.width);
674
675                                 if ( t_h == "hide"||t_h == "show" )
676                                         ok(f_h === "" ? this.style.height === f_h : this.style.height.indexOf(f_h) === 0, "Height must be reset to " + f_h + ": " + this.style.height);
677
678                                 var cur_o = jQuery.style(this, "opacity");
679
680                                 if ( t_o == "hide" || t_o == "show" )
681                                         equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
682
683                                 if ( t_w == "hide" )
684                                         equals(this.style.display, "none", "Hiding, display should be none: " + this.style.display);
685
686                                 if ( t_o.constructor == Number ) {
687                                         equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o);
688
689                                         ok(jQuery.css(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
690                                 }
691
692                                 if ( t_w.constructor == Number ) {
693                                         equals(this.style.width, t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
694
695                                         var cur_w = jQuery.css(this,"width");
696
697                                         ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
698                                 }
699
700                                 if ( t_h.constructor == Number ) {
701                                         equals(this.style.height, t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
702
703                                         var cur_h = jQuery.css(this,"height");
704
705                                         ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
706                                 }
707
708                                 if ( t_h == "show" ) {
709                                         var old_h = jQuery.css(this, "height");
710                                         jQuery(this).append("<br/>Some more text<br/>and some more...");
711
712                                         if ( /Auto/.test( fn ) ) {
713                                                 notEqual(jQuery.css(this, "height"), old_h, "Make sure height is auto.");
714                                         } else {
715                                                 equals(jQuery.css(this, "height"), old_h, "Make sure height is not auto.");
716                                         }
717                                 }
718
719                                 start();
720                         });
721                 });
722         });
723 });
724
725 jQuery.fn.saveState = function(hiddenOverflow){
726         var check = ['opacity','height','width','display','overflow'];
727         expect(check.length);
728
729         stop();
730         return this.each(function(){
731                 var self = this;
732                 self.save = {};
733                 jQuery.each(check, function(i,c){
734                         self.save[c] = c === "overflow" && hiddenOverflow ? "hidden" : self.style[ c ] || jQuery.css(self,c);
735                 });
736         });
737 };
738
739 jQuery.checkState = function(){
740         var self = this;
741         jQuery.each(this.save, function(c,v){
742                 var cur = self.style[ c ] || jQuery.css(self, c);
743                 equals( cur, v, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
744         });
745         start();
746 }
747
748 // Chaining Tests
749 test("Chain fadeOut fadeIn", function() {
750         jQuery('#fadein div').saveState().fadeOut('fast').fadeIn('fast',jQuery.checkState);
751 });
752 test("Chain fadeIn fadeOut", function() {
753         jQuery('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',jQuery.checkState);
754 });
755
756 test("Chain hide show", function() {
757         jQuery('#show div').saveState(jQuery.support.shrinkWrapBlocks).hide('fast').show('fast',jQuery.checkState);
758 });
759 test("Chain show hide", function() {
760         jQuery('#hide div').saveState(jQuery.support.shrinkWrapBlocks).show('fast').hide('fast',jQuery.checkState);
761 });
762 test("Chain show hide with easing and callback", function() {
763         jQuery('#hide div').saveState().show('fast').hide('fast','linear',jQuery.checkState);
764 });
765
766 test("Chain toggle in", function() {
767         jQuery('#togglein div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast',jQuery.checkState);
768 });
769 test("Chain toggle out", function() {
770         jQuery('#toggleout div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast',jQuery.checkState);
771 });
772 test("Chain toggle out with easing and callback", function() {
773  jQuery('#toggleout div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast','linear',jQuery.checkState);
774 });
775 test("Chain slideDown slideUp", function() {
776         jQuery('#slidedown div').saveState(jQuery.support.shrinkWrapBlocks).slideDown('fast').slideUp('fast',jQuery.checkState);
777 });
778 test("Chain slideUp slideDown", function() {
779         jQuery('#slideup div').saveState(jQuery.support.shrinkWrapBlocks).slideUp('fast').slideDown('fast',jQuery.checkState);
780 });
781 test("Chain slideUp slideDown with easing and callback", function() {
782         jQuery('#slideup div').saveState(jQuery.support.shrinkWrapBlocks).slideUp('fast').slideDown('fast','linear',jQuery.checkState);
783 });
784
785 test("Chain slideToggle in", function() {
786         jQuery('#slidetogglein div').saveState(jQuery.support.shrinkWrapBlocks).slideToggle('fast').slideToggle('fast',jQuery.checkState);
787 });
788 test("Chain slideToggle out", function() {
789         jQuery('#slidetoggleout div').saveState(jQuery.support.shrinkWrapBlocks).slideToggle('fast').slideToggle('fast',jQuery.checkState);
790 });
791
792 test("Chain fadeToggle in", function() {
793         jQuery('#fadetogglein div').saveState().fadeToggle('fast').fadeToggle('fast',jQuery.checkState);
794 });
795 test("Chain fadeToggle out", function() {
796         jQuery('#fadetoggleout div').saveState().fadeToggle('fast').fadeToggle('fast',jQuery.checkState);
797 });
798
799 test("Chain fadeTo 0.5 1.0 with easing and callback)", function() {
800         jQuery('#fadeto div').saveState().fadeTo('fast',0.5).fadeTo('fast',1.0,'linear',jQuery.checkState);
801 });
802
803 jQuery.makeTest = function( text ){
804         var elem = jQuery("<div></div>")
805                 .attr("id", "test" + jQuery.makeTest.id++)
806                 .addClass("box");
807
808         jQuery("<h4></h4>")
809                 .text( text )
810                 .appendTo("#fx-tests")
811                 .click(function(){
812                         jQuery(this).next().toggle();
813                 })
814                 .after( elem );
815
816         return elem;
817 }
818
819 jQuery.makeTest.id = 1;
820
821 test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function () {
822         expect(4);
823   stop();
824
825         var $checkedtest = jQuery("#checkedtest");
826         // IE6 was clearing "checked" in jQuery(elem).show("fast");
827         $checkedtest.hide().show("fast", function() {
828         ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
829         ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
830         ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
831         ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
832         start();
833         });
834 });
835
836 test("animate with per-property easing", function(){
837
838         expect(3);
839         stop();
840
841         var _test1_called = false;
842         var _test2_called = false;
843         var _default_test_called = false;
844
845         jQuery.easing['_test1'] = function() {
846                 _test1_called = true;
847         };
848
849         jQuery.easing['_test2'] = function() {
850                 _test2_called = true;
851         };
852
853         jQuery.easing['_default_test'] = function() {
854                 _default_test_called = true;
855         };
856
857         jQuery({a:0,b:0,c:0}).animate({
858                 a: [100, '_test1'],
859                 b: [100, '_test2'],
860                 c: 100
861         }, 400, '_default_test', function(){
862                 start();
863                 ok(_test1_called, "Easing function (1) called");
864                 ok(_test2_called, "Easing function (2) called");
865                 ok(_default_test_called, "Easing function (_default) called");
866         });
867
868 });
869
870 test("hide hidden elements (bug #7141)", function() {
871         expect(3);
872         QUnit.reset();
873
874         var div = jQuery("<div style='display:none'></div>").appendTo("#main");
875         equals( div.css("display"), "none", "Element is hidden by default" );
876         div.hide();
877         ok( !div.data("olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
878         div.show();
879         equals( div.css("display"), "block", "Show a double-hidden element" );
880
881         div.remove();
882 });
883
884 test("hide hidden elements, with animation (bug #7141)", function() {
885         expect(3);
886         QUnit.reset();
887         stop();
888         
889         var div = jQuery("<div style='display:none'></div>").appendTo("#main");
890         equals( div.css("display"), "none", "Element is hidden by default" );
891         div.hide(1, function () {
892                 ok( !div.data("olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
893                 div.show(1, function () {
894                         equals( div.css("display"), "block", "Show a double-hidden element" );
895                         start();
896                 });
897         });
898 });