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;
11 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>');
13 var old = jQuery("#show-tests table").show().css("display") !== "table";
22 "table" : old ? "block" : "table",
23 "thead" : old ? "block" : "table-header-group",
24 "tbody" : old ? "block" : "table-row-group",
25 "tr" : old ? "block" : "table-row",
26 "th" : old ? "block" : "table-cell",
27 "td" : old ? "block" : "table-cell",
29 "li" : old ? "block" : "list-item"
32 jQuery.each(test, function(selector, expected) {
33 var elem = jQuery(selector, "#show-tests").show();
34 equals( elem.css("display"), expected, "Show using correct display type for " + selector );
38 test("animate(Hash, Object, Function)", function() {
41 var hash = {opacity: 'show'};
42 var hashCopy = jQuery.extend({}, hash);
43 jQuery('#foo').animate(hash, 0, function() {
44 equals( hash.opacity, hashCopy.opacity, 'Check if animate changed the hash parameter' );
49 /* // This test ends up being flaky depending upon the CPU load
50 test("animate option (queue === false)", function () {
56 var $foo = jQuery("#foo");
57 $foo.animate({width:'100px'}, 3000, function () {
58 // should finish after unqueued animation so second
60 isSet( order, [ 1, 2 ], "Animations finished in the correct order" );
63 $foo.animate({fontSize:'2em'}, {queue:false, duration:10, complete:function () {
64 // short duration and out of queue so should finish first
70 test("animate duration 0", function() {
75 var $elems = jQuery([{ a:0 },{ a:0 }]),
81 equals( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
83 $elems.eq(0).animate( {a:1}, 0, count );
85 // Failed until [6115]
86 equals( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" );
88 equals( counter, 1, "One synchronic animations" );
90 $elems.animate( { a:2 }, 0, count );
92 equals( counter, 3, "Multiple synchronic animations" );
94 $elems.eq(0).animate( {a:3}, 0, count );
95 $elems.eq(1).animate( {a:3}, 20, function(){
97 // Failed until [6115]
98 equals( counter, 5, "One synchronic and one asynchronic" );
102 var $elem = jQuery("<div />");
103 $elem.show(0, function(){
104 ok(true, "Show's callback with no duration");
106 $elem.hide(0, function(){
107 ok(true, "Show's callback with no duration");
111 test("animate hyphenated properties", function(){
115 jQuery("#nothiddendiv")
116 .css("font-size", 10)
117 .animate({"font-size": 20}, 200, function(){
118 equals( this.style.fontSize, "20px", "The font-size property was animated." );
123 test("animate non-element", function(){
127 var obj = { test: 0 };
129 jQuery(obj).animate({test: 200}, 200, function(){
130 equals( obj.test, 200, "The custom property should be modified." );
135 test("stop()", function() {
139 var $foo = jQuery("#nothiddendiv");
141 $foo.hide().width(200).width();
143 $foo.animate({ width:'show' }, 1000);
144 setTimeout(function(){
145 var nw = $foo.width();
146 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
150 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
151 setTimeout(function(){
152 equals( nw, $foo.width(), "The animation didn't continue" );
158 test("stop() - several in queue", function() {
162 var $foo = jQuery("#nothiddendivchild");
164 $foo.hide().width(200).width();
166 $foo.animate({ width:'show' }, 1000);
167 $foo.animate({ width:'hide' }, 1000);
168 $foo.animate({ width:'show' }, 1000);
169 setTimeout(function(){
170 equals( $foo.queue().length, 3, "All 3 still in the queue" );
171 var nw = $foo.width();
172 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
176 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
177 // Disabled, being flaky
178 //equals( $foo.queue().length, 1, "The next animation continued" );
184 test("stop(clearQueue)", function() {
188 var $foo = jQuery("#nothiddendiv");
190 $foo.hide().width(200).width();
192 $foo.animate({ width:'show' }, 1000);
193 $foo.animate({ width:'hide' }, 1000);
194 $foo.animate({ width:'show' }, 1000);
195 setTimeout(function(){
196 var nw = $foo.width();
197 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
201 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
203 equals( $foo.queue().length, 0, "The animation queue was cleared" );
204 setTimeout(function(){
205 equals( nw, $foo.width(), "The animation didn't continue" );
211 test("stop(clearQueue, gotoEnd)", function() {
215 var $foo = jQuery("#nothiddendivchild");
217 $foo.hide().width(200).width();
219 $foo.animate({ width:'show' }, 1000);
220 $foo.animate({ width:'hide' }, 1000);
221 $foo.animate({ width:'show' }, 1000);
222 $foo.animate({ width:'hide' }, 1000);
223 setTimeout(function(){
224 var nw = $foo.width();
225 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
226 $foo.stop(false, true);
229 // Disabled, being flaky
230 //equals( nw, 1, "Stop() reset the animation" );
232 setTimeout(function(){
233 // Disabled, being flaky
234 //equals( $foo.queue().length, 2, "The next animation continued" );
241 test("toggle()", function() {
243 var x = jQuery("#nothiddendiv");
244 ok( x.is(":visible"), "is visible" );
246 ok( x.is(":hidden"), "is hidden" );
248 ok( x.is(":visible"), "is visible again" );
251 ok( x.is(":visible"), "is visible" );
253 ok( x.is(":hidden"), "is hidden" );
255 ok( x.is(":visible"), "is visible again" );
258 jQuery.checkOverflowDisplay = function(){
259 var o = jQuery.css( this, "overflow" );
261 equals(o, "visible", "Overflow should be visible: " + o);
262 equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
267 test("JS Overflow and Display", function() {
270 jQuery.makeTest( "JS Overflow and Display" )
271 .addClass("widewidth")
272 .css({ overflow: "visible", display: "inline" })
273 .addClass("widewidth")
274 .text("Some sample text.")
275 .before("text before")
277 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
280 test("CSS Overflow and Display", function() {
283 jQuery.makeTest( "CSS Overflow and Display" )
284 .addClass("overflow inline")
285 .addClass("widewidth")
286 .text("Some sample text.")
287 .before("text before")
289 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
293 "CSS Auto": function(elem,prop){
294 jQuery(elem).addClass("auto" + prop)
295 .text("This is a long string of text.");
298 "JS Auto": function(elem,prop){
299 jQuery(elem).css(prop,"auto")
300 .text("This is a long string of text.");
303 "CSS 100": function(elem,prop){
304 jQuery(elem).addClass("large" + prop);
307 "JS 100": function(elem,prop){
308 jQuery(elem).css(prop,prop == "opacity" ? 1 : "100px");
309 return prop == "opacity" ? 1 : 100;
311 "CSS 50": function(elem,prop){
312 jQuery(elem).addClass("med" + prop);
315 "JS 50": function(elem,prop){
316 jQuery(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
317 return prop == "opacity" ? 0.5 : 50;
319 "CSS 0": function(elem,prop){
320 jQuery(elem).addClass("no" + prop);
323 "JS 0": function(elem,prop){
324 jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px");
329 "show": function(elem,prop){
330 jQuery(elem).hide().addClass("wide"+prop);
333 "hide": function(elem,prop){
334 jQuery(elem).addClass("wide"+prop);
337 "100": function(elem,prop){
338 jQuery(elem).addClass("wide"+prop);
339 return prop == "opacity" ? 1 : 100;
341 "50": function(elem,prop){
342 return prop == "opacity" ? 0.50 : 50;
344 "0": function(elem,prop){
345 jQuery(elem).addClass("noback");
349 test(fn + " to " + tn, function() {
350 var elem = jQuery.makeTest( fn + " to " + tn );
352 var t_w = t( elem, "width" );
353 var f_w = f( elem, "width" );
354 var t_h = t( elem, "height" );
355 var f_h = f( elem, "height" );
356 var t_o = t( elem, "opacity" );
357 var f_o = f( elem, "opacity" );
361 if ( t_h == "show" ) num++;
362 if ( t_w == "show" ) num++;
363 if ( t_w == "hide"||t_w == "show" ) num++;
364 if ( t_h == "hide"||t_h == "show" ) num++;
365 if ( t_o == "hide"||t_o == "show" ) num++;
366 if ( t_w == "hide" ) num++;
367 if ( t_o.constructor == Number ) num += 2;
368 if ( t_w.constructor == Number ) num += 2;
369 if ( t_h.constructor == Number ) num +=2;
374 var anim = { width: t_w, height: t_h, opacity: t_o };
376 elem.animate(anim, 50, function(){
378 equals( this.style.display, "block", "Showing, display should block: " + this.style.display);
380 if ( t_w == "hide"||t_w == "show" )
381 equals(this.style.width.indexOf(f_w), 0, "Width must be reset to " + f_w + ": " + this.style.width);
383 if ( t_h == "hide"||t_h == "show" )
384 equals(this.style.height.indexOf(f_h), 0, "Height must be reset to " + f_h + ": " + this.style.height);
386 var cur_o = jQuery.style(this, "opacity");
387 if ( cur_o !== "" ) cur_o = parseFloat( cur_o );
389 if ( t_o == "hide"||t_o == "show" )
390 equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
393 equals(this.style.display, "none", "Hiding, display should be none: " + this.style.display);
395 if ( t_o.constructor == Number ) {
396 equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o);
398 ok(jQuery.curCSS(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
401 if ( t_w.constructor == Number ) {
402 equals(this.style.width, t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
404 var cur_w = jQuery.css(this,"width");
406 ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
409 if ( t_h.constructor == Number ) {
410 equals(this.style.height, t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
412 var cur_h = jQuery.css(this,"height");
414 ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
417 if ( t_h == "show" ) {
418 var old_h = jQuery.curCSS(this, "height");
419 jQuery(elem).append("<br/>Some more text<br/>and some more...");
420 ok(old_h != jQuery.css(this, "height" ), "Make sure height is auto.");
429 jQuery.fn.saveState = function(){
430 var check = ['opacity','height','width','display','overflow'];
431 expect(check.length);
434 return this.each(function(){
437 jQuery.each(check, function(i,c){
438 self.save[c] = jQuery.css(self,c);
443 jQuery.checkState = function(){
445 jQuery.each(this.save, function(c,v){
446 var cur = jQuery.css(self,c);
447 equals( v, cur, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
453 test("Chain fadeOut fadeIn", function() {
454 jQuery('#fadein div').saveState().fadeOut('fast').fadeIn('fast',jQuery.checkState);
456 test("Chain fadeIn fadeOut", function() {
457 jQuery('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',jQuery.checkState);
460 test("Chain hide show", function() {
461 jQuery('#show div').saveState().hide('fast').show('fast',jQuery.checkState);
463 test("Chain show hide", function() {
464 jQuery('#hide div').saveState().show('fast').hide('fast',jQuery.checkState);
467 test("Chain toggle in", function() {
468 jQuery('#togglein div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
470 test("Chain toggle out", function() {
471 jQuery('#toggleout div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
474 test("Chain slideDown slideUp", function() {
475 jQuery('#slidedown div').saveState().slideDown('fast').slideUp('fast',jQuery.checkState);
477 test("Chain slideUp slideDown", function() {
478 jQuery('#slideup div').saveState().slideUp('fast').slideDown('fast',jQuery.checkState);
481 test("Chain slideToggle in", function() {
482 jQuery('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
484 test("Chain slideToggle out", function() {
485 jQuery('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
488 jQuery.makeTest = function( text ){
489 var elem = jQuery("<div></div>")
490 .attr("id", "test" + jQuery.makeTest.id++)
495 .appendTo("#fx-tests")
497 jQuery(this).next().toggle();
504 jQuery.makeTest.id = 1;