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