3 test("sanity check", function() {
5 ok( jQuery("#dl:visible, #main:visible, #foo:visible").length === 3, "QUnit state is correct for testing effects" );
8 test("show()", function() {
10 var pass = true, div = jQuery("#main div");
11 div.show().each(function(){
12 if ( this.style.display == "none" ) pass = false;
18 "undefined speed": undefined,
19 "empty string speed": "",
23 jQuery.each(speeds, function(name, speed) {
25 div.hide().show(speed).each(function() {
26 if ( this.style.display == "none" ) pass = false;
28 ok( pass, "Show with " + name);
32 jQuery.each(speeds, function(name, speed) {
34 div.hide().show(speed, function() {
37 ok( pass, "Show with " + name + " does not call animate callback" );
40 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>');
42 var old = jQuery("#show-tests table").show().css("display") !== "table";
51 "table" : old ? "block" : "table",
52 "thead" : old ? "block" : "table-header-group",
53 "tbody" : old ? "block" : "table-row-group",
54 "tr" : old ? "block" : "table-row",
55 "th" : old ? "block" : "table-cell",
56 "td" : old ? "block" : "table-cell",
58 "li" : old ? "block" : "list-item"
61 jQuery.each(test, function(selector, expected) {
62 var elem = jQuery(selector, "#show-tests").show();
63 equals( elem.css("display"), expected, "Show using correct display type for " + selector );
67 test("show(Number) - other displays", function() {
72 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>');
74 var old = jQuery("#show-tests table").show().css("display") !== "table",
84 "table" : old ? "block" : "table",
85 "thead" : old ? "block" : "table-header-group",
86 "tbody" : old ? "block" : "table-row-group",
87 "tr" : old ? "block" : "table-row",
88 "th" : old ? "block" : "table-cell",
89 "td" : old ? "block" : "table-cell",
91 "li" : old ? "block" : "list-item"
94 jQuery.each(test, function(selector, expected) {
95 // IE sometimes has issues with chained functions referencing
96 // assignments from outside the closure
97 var elem = jQuery(selector, "#show-tests");
98 elem.show(1, function() {
99 equals( elem.css("display"), expected, "Show using correct display type for " + selector );
100 if ( ++num === 15 ) {
107 test("animate(Hash, Object, Function)", function() {
110 var hash = {opacity: 'show'};
111 var hashCopy = jQuery.extend({}, hash);
112 jQuery('#foo').animate(hash, 0, function() {
113 equals( hash.opacity, hashCopy.opacity, 'Check if animate changed the hash parameter' );
118 test("animate negative height", function() {
121 jQuery("#foo").animate({ height: -100 }, 100, function() {
122 equals( this.offsetHeight, 0, "Verify height." );
127 test("animate inline width/height", function() {
130 jQuery("#foo").css({ display: "inline", width: '', height: '' }).animate({ width: 42, height: 42 }, 100, function() {
131 equals( jQuery(this).css("display"), jQuery.support.inlineBlockNeedsLayout ? "inline" : "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
132 equals( this.offsetWidth, 42, "width was animated" );
133 equals( this.offsetHeight, 42, "height was animated" );
138 test("animate block width/height", function() {
141 jQuery("#foo").css({ display: "block", width: 20, height: 20 }).animate({ width: 42, height: 42 }, 100, function() {
142 equals( jQuery(this).css("display"), "block", "inline-block was not set on block element when animating width/height" );
143 equals( this.offsetWidth, 42, "width was animated" );
144 equals( this.offsetHeight, 42, "height was animated" );
149 test("animate table width/height", function() {
153 var displayMode = jQuery("#table").css("display") !== "table" ? "block" : "table";
155 jQuery("#table").animate({ width: 42, height: 42 }, 100, function() {
156 equals( jQuery(this).css("display"), displayMode, "display mode is correct" );
161 test("animate table-cell width/height", function() {
164 var td = jQuery("#table")
165 .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
166 .append("<tr><td style='width:42px;height:42px;padding:0;'><div style='width:20px;height:20px;'></div></td></tr>")
169 // IE<8 uses “block” instead of the correct display type
170 var displayMode = td.css("display") !== "table-cell" ? "block" : "table-cell";
172 td.animate({ width: 10, height: 10 }, 100, function() {
173 equals( jQuery(this).css("display"), displayMode, "display mode is correct" );
174 equals( this.offsetWidth, 20, "width animated to shrink wrap point" );
175 equals( this.offsetHeight, 20, "height animated to shrink wrap point" );
180 test("animate resets overflow-x and overflow-y when finished", function() {
184 .css({ display: "block", width: 20, height: 20, overflowX: "visible", overflowY: "auto" })
185 .animate({ width: 42, height: 42 }, 100, function() {
186 equals( this.style.overflowX, "visible", "overflow-x is visible" );
187 equals( this.style.overflowY, "auto", "overflow-y is auto" );
192 /* // This test ends up being flaky depending upon the CPU load
193 test("animate option (queue === false)", function () {
199 var $foo = jQuery("#foo");
200 $foo.animate({width:'100px'}, 3000, function () {
201 // should finish after unqueued animation so second
203 same( order, [ 1, 2 ], "Animations finished in the correct order" );
206 $foo.animate({fontSize:'2em'}, {queue:false, duration:10, complete:function () {
207 // short duration and out of queue so should finish first
213 test("animate with no properties", function() {
216 var divs = jQuery("div"), count = 0;
218 divs.animate({}, function(){
222 equals( divs.length, count, "Make sure that callback is called for each element in the set." );
226 var foo = jQuery("#foo");
229 foo.animate({top: 10}, 100, function(){
230 ok( true, "Animation was properly dequeued." );
235 test("animate duration 0", function() {
240 var $elems = jQuery([{ a:0 },{ a:0 }]), counter = 0;
242 equals( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
244 $elems.eq(0).animate( {a:1}, 0, function(){
245 ok( true, "Animate a simple property." );
249 // Failed until [6115]
250 equals( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" );
252 equals( counter, 1, "One synchronic animations" );
254 $elems.animate( { a:2 }, 0, function(){
255 ok( true, "Animate a second simple property." );
259 equals( counter, 3, "Multiple synchronic animations" );
261 $elems.eq(0).animate( {a:3}, 0, function(){
262 ok( true, "Animate a third simple property." );
265 $elems.eq(1).animate( {a:3}, 200, function(){
267 // Failed until [6115]
268 equals( counter, 5, "One synchronic and one asynchronic" );
272 var $elem = jQuery("<div />");
273 $elem.show(0, function(){
274 ok(true, "Show callback with no duration");
276 $elem.hide(0, function(){
277 ok(true, "Hide callback with no duration");
281 test("animate hyphenated properties", function(){
285 jQuery("#nothiddendiv")
286 .css("font-size", 10)
287 .animate({"font-size": 20}, 200, function(){
288 equals( this.style.fontSize, "20px", "The font-size property was animated." );
293 test("animate non-element", function(){
297 var obj = { test: 0 };
299 jQuery(obj).animate({test: 200}, 200, function(){
300 equals( obj.test, 200, "The custom property should be modified." );
305 test("stop()", function() {
309 var $foo = jQuery("#nothiddendiv");
311 $foo.hide().width(200).width();
313 $foo.animate({ width:'show' }, 1000);
314 setTimeout(function(){
315 var nw = $foo.width();
316 notEqual( nw, w, "An animation occurred " + nw + "px " + w + "px");
320 notEqual( nw, w, "Stop didn't reset the animation " + nw + "px " + w + "px");
321 setTimeout(function(){
322 equals( nw, $foo.width(), "The animation didn't continue" );
328 test("stop() - several in queue", function() {
332 var $foo = jQuery("#nothiddendivchild");
334 $foo.hide().width(200).width();
336 $foo.animate({ width:'show' }, 1000);
337 $foo.animate({ width:'hide' }, 1000);
338 $foo.animate({ width:'show' }, 1000);
339 setTimeout(function(){
340 equals( $foo.queue().length, 3, "All 3 still in the queue" );
341 var nw = $foo.width();
342 notEqual( nw, w, "An animation occurred " + nw + "px " + w + "px");
346 notEqual( nw, w, "Stop didn't reset the animation " + nw + "px " + w + "px");
353 test("stop(clearQueue)", function() {
357 var $foo = jQuery("#nothiddendiv");
359 $foo.hide().width(200).width();
361 $foo.animate({ width:'show' }, 1000);
362 $foo.animate({ width:'hide' }, 1000);
363 $foo.animate({ width:'show' }, 1000);
364 setTimeout(function(){
365 var nw = $foo.width();
366 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
370 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
372 equals( $foo.queue().length, 0, "The animation queue was cleared" );
373 setTimeout(function(){
374 equals( nw, $foo.width(), "The animation didn't continue" );
380 test("stop(clearQueue, gotoEnd)", function() {
384 var $foo = jQuery("#nothiddendivchild");
386 $foo.hide().width(200).width();
388 $foo.animate({ width:'show' }, 1000);
389 $foo.animate({ width:'hide' }, 1000);
390 $foo.animate({ width:'show' }, 1000);
391 $foo.animate({ width:'hide' }, 1000);
392 setTimeout(function(){
393 var nw = $foo.width();
394 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
395 $foo.stop(false, true);
398 // Disabled, being flaky
399 //equals( nw, 1, "Stop() reset the animation" );
401 setTimeout(function(){
402 // Disabled, being flaky
403 //equals( $foo.queue().length, 2, "The next animation continued" );
410 test("toggle()", function() {
412 var x = jQuery("#nothiddendiv");
413 ok( x.is(":visible"), "is visible" );
415 ok( x.is(":hidden"), "is hidden" );
417 ok( x.is(":visible"), "is visible again" );
420 ok( x.is(":visible"), "is visible" );
422 ok( x.is(":hidden"), "is hidden" );
424 ok( x.is(":visible"), "is visible again" );
427 jQuery.checkOverflowDisplay = function(){
428 var o = jQuery.css( this, "overflow" );
430 equals(o, "visible", "Overflow should be visible: " + o);
431 equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
436 test("JS Overflow and Display", function() {
439 jQuery.makeTest( "JS Overflow and Display" )
440 .addClass("widewidth")
441 .css({ overflow: "visible", display: "inline" })
442 .addClass("widewidth")
443 .text("Some sample text.")
444 .before("text before")
446 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
449 test("CSS Overflow and Display", function() {
452 jQuery.makeTest( "CSS Overflow and Display" )
453 .addClass("overflow inline")
454 .addClass("widewidth")
455 .text("Some sample text.")
456 .before("text before")
458 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
462 "CSS Auto": function(elem,prop){
463 jQuery(elem).addClass("auto" + prop)
464 .text("This is a long string of text.");
467 "JS Auto": function(elem,prop){
468 jQuery(elem).css(prop,"")
469 .text("This is a long string of text.");
472 "CSS 100": function(elem,prop){
473 jQuery(elem).addClass("large" + prop);
476 "JS 100": function(elem,prop){
477 jQuery(elem).css(prop,prop == "opacity" ? 1 : "100px");
478 return prop == "opacity" ? 1 : 100;
480 "CSS 50": function(elem,prop){
481 jQuery(elem).addClass("med" + prop);
484 "JS 50": function(elem,prop){
485 jQuery(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
486 return prop == "opacity" ? 0.5 : 50;
488 "CSS 0": function(elem,prop){
489 jQuery(elem).addClass("no" + prop);
492 "JS 0": function(elem,prop){
493 jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px");
498 "show": function(elem,prop){
499 jQuery(elem).hide().addClass("wide"+prop);
502 "hide": function(elem,prop){
503 jQuery(elem).addClass("wide"+prop);
506 "100": function(elem,prop){
507 jQuery(elem).addClass("wide"+prop);
508 return prop == "opacity" ? 1 : 100;
510 "50": function(elem,prop){
511 return prop == "opacity" ? 0.50 : 50;
513 "0": function(elem,prop){
514 jQuery(elem).addClass("noback");
518 test(fn + " to " + tn, function() {
519 var elem = jQuery.makeTest( fn + " to " + tn );
521 var t_w = t( elem, "width" );
522 var f_w = f( elem, "width" );
523 var t_h = t( elem, "height" );
524 var f_h = f( elem, "height" );
525 var t_o = t( elem, "opacity" );
526 var f_o = f( elem, "opacity" );
530 if ( t_h == "show" ) num++;
531 if ( t_w == "show" ) num++;
532 if ( t_w == "hide"||t_w == "show" ) num++;
533 if ( t_h == "hide"||t_h == "show" ) num++;
534 if ( t_o == "hide"||t_o == "show" ) num++;
535 if ( t_w == "hide" ) num++;
536 if ( t_o.constructor == Number ) num += 2;
537 if ( t_w.constructor == Number ) num += 2;
538 if ( t_h.constructor == Number ) num +=2;
543 var anim = { width: t_w, height: t_h, opacity: t_o };
545 elem.animate(anim, 50, function(){
547 equals( this.style.display, "block", "Showing, display should block: " + this.style.display);
549 if ( t_w == "hide"||t_w == "show" )
550 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);
552 if ( t_h == "hide"||t_h == "show" )
553 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);
555 var cur_o = jQuery.style(this, "opacity");
557 if ( t_o == "hide" || t_o == "show" )
558 equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
561 equals(this.style.display, "none", "Hiding, display should be none: " + this.style.display);
563 if ( t_o.constructor == Number ) {
564 equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o);
566 ok(jQuery.css(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
569 if ( t_w.constructor == Number ) {
570 equals(this.style.width, t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
572 var cur_w = jQuery.css(this,"width");
574 ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
577 if ( t_h.constructor == Number ) {
578 equals(this.style.height, t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
580 var cur_h = jQuery.css(this,"height");
582 ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
585 if ( t_h == "show" ) {
586 var old_h = jQuery.css(this, "height");
587 jQuery(this).append("<br/>Some more text<br/>and some more...");
589 if ( /Auto/.test( fn ) ) {
590 notEqual(jQuery.css(this, "height"), old_h, "Make sure height is auto.");
592 equals(jQuery.css(this, "height"), old_h, "Make sure height is not auto.");
602 jQuery.fn.saveState = function(){
603 var check = ['opacity','height','width','display','overflow'];
604 expect(check.length);
607 return this.each(function(){
610 jQuery.each(check, function(i,c){
611 self.save[c] = self.style[ c ] || jQuery.css(self,c);
616 jQuery.checkState = function(){
618 jQuery.each(this.save, function(c,v){
619 var cur = self.style[ c ] || jQuery.css(self, c);
620 equals( cur, v, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
626 test("Chain fadeOut fadeIn", function() {
627 jQuery('#fadein div').saveState().fadeOut('fast').fadeIn('fast',jQuery.checkState);
629 test("Chain fadeIn fadeOut", function() {
630 jQuery('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',jQuery.checkState);
633 test("Chain hide show", function() {
634 jQuery('#show div').saveState().hide('fast').show('fast',jQuery.checkState);
636 test("Chain show hide", function() {
637 jQuery('#hide div').saveState().show('fast').hide('fast',jQuery.checkState);
639 test("Chain show hide with easing and callback", function() {
640 jQuery('#hide div').saveState().show('fast').hide('fast','linear',jQuery.checkState);
643 test("Chain toggle in", function() {
644 jQuery('#togglein div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
646 test("Chain toggle out", function() {
647 jQuery('#toggleout div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
649 test("Chain toggle out with easing and callback", function() {
650 jQuery('#toggleout div').saveState().toggle('fast').toggle('fast','linear',jQuery.checkState);
652 test("Chain slideDown slideUp", function() {
653 jQuery('#slidedown div').saveState().slideDown('fast').slideUp('fast',jQuery.checkState);
655 test("Chain slideUp slideDown", function() {
656 jQuery('#slideup div').saveState().slideUp('fast').slideDown('fast',jQuery.checkState);
658 test("Chain slideUp slideDown with easing and callback", function() {
659 jQuery('#slideup div').saveState().slideUp('fast').slideDown('fast','linear',jQuery.checkState);
662 test("Chain slideToggle in", function() {
663 jQuery('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
665 test("Chain slideToggle out", function() {
666 jQuery('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
669 test("Chain fadeTo 0.5 1.0 with easing and callback)", function() {
670 jQuery('#fadeto div').saveState().fadeTo('fast',0.5).fadeTo('fast',1.0,'linear',jQuery.checkState);
673 jQuery.makeTest = function( text ){
674 var elem = jQuery("<div></div>")
675 .attr("id", "test" + jQuery.makeTest.id++)
680 .appendTo("#fx-tests")
682 jQuery(this).next().toggle();
689 jQuery.makeTest.id = 1;
691 test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function () {
695 var $checkedtest = jQuery("#checkedtest");
696 // IE6 was clearing "checked" in jQuery(elem).show("fast");
697 $checkedtest.hide().show("fast", function() {
698 ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
699 ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
700 ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
701 ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
706 test("animate with per-property easing", function(){
711 var _test1_called = false;
712 var _test2_called = false;
713 var _default_test_called = false;
715 jQuery.easing['_test1'] = function() {
716 _test1_called = true;
719 jQuery.easing['_test2'] = function() {
720 _test2_called = true;
723 jQuery.easing['_default_test'] = function() {
724 _default_test_called = true;
727 jQuery({a:0,b:0,c:0}).animate({
731 }, 400, '_default_test', function(){
733 ok(_test1_called, "Easing function (1) called");
734 ok(_test2_called, "Easing function (2) called");
735 ok(_default_test_called, "Easing function (_default) called");