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