3 test("show()", function() {
5 var pass = true, div = jQuery("#main div");
6 div.show().each(function(){
7 if ( this.style.display == "none" ) pass = false;
12 div.hide().show(null).each(function() {
13 if ( this.style.display == "none" ) pass = false;
15 ok( pass, "Show will null speed");
17 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>');
19 var old = jQuery("#show-tests table").show().css("display") !== "table";
28 "table" : old ? "block" : "table",
29 "thead" : old ? "block" : "table-header-group",
30 "tbody" : old ? "block" : "table-row-group",
31 "tr" : old ? "block" : "table-row",
32 "th" : old ? "block" : "table-cell",
33 "td" : old ? "block" : "table-cell",
35 "li" : old ? "block" : "list-item"
38 jQuery.each(test, function(selector, expected) {
39 var elem = jQuery(selector, "#show-tests").show();
40 equals( elem.css("display"), expected, "Show using correct display type for " + selector );
44 test("animate(Hash, Object, Function)", function() {
47 var hash = {opacity: 'show'};
48 var hashCopy = jQuery.extend({}, hash);
49 jQuery('#foo').animate(hash, 0, function() {
50 equals( hash.opacity, hashCopy.opacity, 'Check if animate changed the hash parameter' );
55 /* // This test ends up being flaky depending upon the CPU load
56 test("animate option (queue === false)", function () {
62 var $foo = jQuery("#foo");
63 $foo.animate({width:'100px'}, 3000, function () {
64 // should finish after unqueued animation so second
66 same( order, [ 1, 2 ], "Animations finished in the correct order" );
69 $foo.animate({fontSize:'2em'}, {queue:false, duration:10, complete:function () {
70 // short duration and out of queue so should finish first
76 test("animate with no properties", function() {
79 var divs = jQuery("div"), count = 0;
81 divs.animate({}, function(){
85 equals( divs.length, count, "Make sure that callback is called for each element in the set." );
88 test("animate duration 0", function() {
93 var $elems = jQuery([{ a:0 },{ a:0 }]),
99 equals( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
101 $elems.eq(0).animate( {a:1}, 0, count );
103 // Failed until [6115]
104 equals( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" );
106 equals( counter, 1, "One synchronic animations" );
108 $elems.animate( { a:2 }, 0, count );
110 equals( counter, 3, "Multiple synchronic animations" );
112 $elems.eq(0).animate( {a:3}, 0, count );
113 $elems.eq(1).animate( {a:3}, 20, function(){
115 // Failed until [6115]
116 equals( counter, 5, "One synchronic and one asynchronic" );
120 var $elem = jQuery("<div />");
121 $elem.show(0, function(){
122 ok(true, "Show's callback with no duration");
124 $elem.hide(0, function(){
125 ok(true, "Show's callback with no duration");
129 test("animate hyphenated properties", function(){
133 jQuery("#nothiddendiv")
134 .css("font-size", 10)
135 .animate({"font-size": 20}, 200, function(){
136 equals( this.style.fontSize, "20px", "The font-size property was animated." );
141 test("animate non-element", function(){
145 var obj = { test: 0 };
147 jQuery(obj).animate({test: 200}, 200, function(){
148 equals( obj.test, 200, "The custom property should be modified." );
153 test("stop()", function() {
157 var $foo = jQuery("#nothiddendiv");
159 $foo.hide().width(200).width();
161 $foo.animate({ width:'show' }, 1000);
162 setTimeout(function(){
163 var nw = $foo.width();
164 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
168 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
169 setTimeout(function(){
170 equals( nw, $foo.width(), "The animation didn't continue" );
176 test("stop() - several in queue", function() {
180 var $foo = jQuery("#nothiddendivchild");
182 $foo.hide().width(200).width();
184 $foo.animate({ width:'show' }, 1000);
185 $foo.animate({ width:'hide' }, 1000);
186 $foo.animate({ width:'show' }, 1000);
187 setTimeout(function(){
188 equals( $foo.queue().length, 3, "All 3 still in the queue" );
189 var nw = $foo.width();
190 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
194 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
195 // Disabled, being flaky
196 //equals( $foo.queue().length, 1, "The next animation continued" );
202 test("stop(clearQueue)", function() {
206 var $foo = jQuery("#nothiddendiv");
208 $foo.hide().width(200).width();
210 $foo.animate({ width:'show' }, 1000);
211 $foo.animate({ width:'hide' }, 1000);
212 $foo.animate({ width:'show' }, 1000);
213 setTimeout(function(){
214 var nw = $foo.width();
215 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
219 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
221 equals( $foo.queue().length, 0, "The animation queue was cleared" );
222 setTimeout(function(){
223 equals( nw, $foo.width(), "The animation didn't continue" );
229 test("stop(clearQueue, gotoEnd)", function() {
233 var $foo = jQuery("#nothiddendivchild");
235 $foo.hide().width(200).width();
237 $foo.animate({ width:'show' }, 1000);
238 $foo.animate({ width:'hide' }, 1000);
239 $foo.animate({ width:'show' }, 1000);
240 $foo.animate({ width:'hide' }, 1000);
241 setTimeout(function(){
242 var nw = $foo.width();
243 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
244 $foo.stop(false, true);
247 // Disabled, being flaky
248 //equals( nw, 1, "Stop() reset the animation" );
250 setTimeout(function(){
251 // Disabled, being flaky
252 //equals( $foo.queue().length, 2, "The next animation continued" );
259 test("toggle()", function() {
261 var x = jQuery("#nothiddendiv");
262 ok( x.is(":visible"), "is visible" );
264 ok( x.is(":hidden"), "is hidden" );
266 ok( x.is(":visible"), "is visible again" );
269 ok( x.is(":visible"), "is visible" );
271 ok( x.is(":hidden"), "is hidden" );
273 ok( x.is(":visible"), "is visible again" );
276 jQuery.checkOverflowDisplay = function(){
277 var o = jQuery.css( this, "overflow" );
279 equals(o, "visible", "Overflow should be visible: " + o);
280 equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
285 test("JS Overflow and Display", function() {
288 jQuery.makeTest( "JS Overflow and Display" )
289 .addClass("widewidth")
290 .css({ overflow: "visible", display: "inline" })
291 .addClass("widewidth")
292 .text("Some sample text.")
293 .before("text before")
295 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
298 test("CSS Overflow and Display", function() {
301 jQuery.makeTest( "CSS Overflow and Display" )
302 .addClass("overflow inline")
303 .addClass("widewidth")
304 .text("Some sample text.")
305 .before("text before")
307 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
311 "CSS Auto": function(elem,prop){
312 jQuery(elem).addClass("auto" + prop)
313 .text("This is a long string of text.");
316 "JS Auto": function(elem,prop){
317 jQuery(elem).css(prop,"auto")
318 .text("This is a long string of text.");
321 "CSS 100": function(elem,prop){
322 jQuery(elem).addClass("large" + prop);
325 "JS 100": function(elem,prop){
326 jQuery(elem).css(prop,prop == "opacity" ? 1 : "100px");
327 return prop == "opacity" ? 1 : 100;
329 "CSS 50": function(elem,prop){
330 jQuery(elem).addClass("med" + prop);
333 "JS 50": function(elem,prop){
334 jQuery(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
335 return prop == "opacity" ? 0.5 : 50;
337 "CSS 0": function(elem,prop){
338 jQuery(elem).addClass("no" + prop);
341 "JS 0": function(elem,prop){
342 jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px");
347 "show": function(elem,prop){
348 jQuery(elem).hide().addClass("wide"+prop);
351 "hide": function(elem,prop){
352 jQuery(elem).addClass("wide"+prop);
355 "100": function(elem,prop){
356 jQuery(elem).addClass("wide"+prop);
357 return prop == "opacity" ? 1 : 100;
359 "50": function(elem,prop){
360 return prop == "opacity" ? 0.50 : 50;
362 "0": function(elem,prop){
363 jQuery(elem).addClass("noback");
367 test(fn + " to " + tn, function() {
368 var elem = jQuery.makeTest( fn + " to " + tn );
370 var t_w = t( elem, "width" );
371 var f_w = f( elem, "width" );
372 var t_h = t( elem, "height" );
373 var f_h = f( elem, "height" );
374 var t_o = t( elem, "opacity" );
375 var f_o = f( elem, "opacity" );
379 if ( t_h == "show" ) num++;
380 if ( t_w == "show" ) num++;
381 if ( t_w == "hide"||t_w == "show" ) num++;
382 if ( t_h == "hide"||t_h == "show" ) num++;
383 if ( t_o == "hide"||t_o == "show" ) num++;
384 if ( t_w == "hide" ) num++;
385 if ( t_o.constructor == Number ) num += 2;
386 if ( t_w.constructor == Number ) num += 2;
387 if ( t_h.constructor == Number ) num +=2;
392 var anim = { width: t_w, height: t_h, opacity: t_o };
394 elem.animate(anim, 50, function(){
396 equals( this.style.display, "block", "Showing, display should block: " + this.style.display);
398 if ( t_w == "hide"||t_w == "show" )
399 equals(this.style.width.indexOf(f_w), 0, "Width must be reset to " + f_w + ": " + this.style.width);
401 if ( t_h == "hide"||t_h == "show" )
402 equals(this.style.height.indexOf(f_h), 0, "Height must be reset to " + f_h + ": " + this.style.height);
404 var cur_o = jQuery.style(this, "opacity");
405 if ( cur_o !== "" ) cur_o = parseFloat( cur_o );
407 if ( t_o == "hide"||t_o == "show" )
408 equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
411 equals(this.style.display, "none", "Hiding, display should be none: " + this.style.display);
413 if ( t_o.constructor == Number ) {
414 equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o);
416 ok(jQuery.curCSS(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
419 if ( t_w.constructor == Number ) {
420 equals(this.style.width, t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
422 var cur_w = jQuery.css(this,"width");
424 ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
427 if ( t_h.constructor == Number ) {
428 equals(this.style.height, t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
430 var cur_h = jQuery.css(this,"height");
432 ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
435 if ( t_h == "show" ) {
436 var old_h = jQuery.curCSS(this, "height");
437 jQuery(elem).append("<br/>Some more text<br/>and some more...");
438 ok(old_h != jQuery.css(this, "height" ), "Make sure height is auto.");
447 jQuery.fn.saveState = function(){
448 var check = ['opacity','height','width','display','overflow'];
449 expect(check.length);
452 return this.each(function(){
455 jQuery.each(check, function(i,c){
456 self.save[c] = jQuery.css(self,c);
461 jQuery.checkState = function(){
463 jQuery.each(this.save, function(c,v){
464 var cur = jQuery.css(self,c);
465 equals( v, cur, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
471 test("Chain fadeOut fadeIn", function() {
472 jQuery('#fadein div').saveState().fadeOut('fast').fadeIn('fast',jQuery.checkState);
474 test("Chain fadeIn fadeOut", function() {
475 jQuery('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',jQuery.checkState);
478 test("Chain hide show", function() {
479 jQuery('#show div').saveState().hide('fast').show('fast',jQuery.checkState);
481 test("Chain show hide", function() {
482 jQuery('#hide div').saveState().show('fast').hide('fast',jQuery.checkState);
485 test("Chain toggle in", function() {
486 jQuery('#togglein div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
488 test("Chain toggle out", function() {
489 jQuery('#toggleout div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
492 test("Chain slideDown slideUp", function() {
493 jQuery('#slidedown div').saveState().slideDown('fast').slideUp('fast',jQuery.checkState);
495 test("Chain slideUp slideDown", function() {
496 jQuery('#slideup div').saveState().slideUp('fast').slideDown('fast',jQuery.checkState);
499 test("Chain slideToggle in", function() {
500 jQuery('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
502 test("Chain slideToggle out", function() {
503 jQuery('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
506 jQuery.makeTest = function( text ){
507 var elem = jQuery("<div></div>")
508 .attr("id", "test" + jQuery.makeTest.id++)
513 .appendTo("#fx-tests")
515 jQuery(this).next().toggle();
522 jQuery.makeTest.id = 1;