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