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" );
103 test("animate non-element", function(){
107 var obj = { test: 0 };
109 jQuery(obj).animate({test: 200}, 200, function(){
110 equals( obj.test, 200, "The custom property should be modified." );
115 test("stop()", function() {
119 var $foo = jQuery("#nothiddendiv");
121 $foo.hide().width(200).width();
123 $foo.animate({ width:'show' }, 1000);
124 setTimeout(function(){
125 var nw = $foo.width();
126 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
130 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
131 setTimeout(function(){
132 equals( nw, $foo.width(), "The animation didn't continue" );
138 test("stop() - several in queue", function() {
142 var $foo = jQuery("#nothiddendivchild");
144 $foo.hide().width(200).width();
146 $foo.animate({ width:'show' }, 1000);
147 $foo.animate({ width:'hide' }, 1000);
148 $foo.animate({ width:'show' }, 1000);
149 setTimeout(function(){
150 equals( $foo.queue().length, 3, "All 3 still in the queue" );
151 var nw = $foo.width();
152 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
156 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
157 // Disabled, being flaky
158 //equals( $foo.queue().length, 1, "The next animation continued" );
164 test("stop(clearQueue)", function() {
168 var $foo = jQuery("#nothiddendiv");
170 $foo.hide().width(200).width();
172 $foo.animate({ width:'show' }, 1000);
173 $foo.animate({ width:'hide' }, 1000);
174 $foo.animate({ width:'show' }, 1000);
175 setTimeout(function(){
176 var nw = $foo.width();
177 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
181 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
183 equals( $foo.queue().length, 0, "The animation queue was cleared" );
184 setTimeout(function(){
185 equals( nw, $foo.width(), "The animation didn't continue" );
191 test("stop(clearQueue, gotoEnd)", function() {
195 var $foo = jQuery("#nothiddendivchild");
197 $foo.hide().width(200).width();
199 $foo.animate({ width:'show' }, 1000);
200 $foo.animate({ width:'hide' }, 1000);
201 $foo.animate({ width:'show' }, 1000);
202 $foo.animate({ width:'hide' }, 1000);
203 setTimeout(function(){
204 var nw = $foo.width();
205 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
206 $foo.stop(false, true);
209 // Disabled, being flaky
210 //equals( nw, 1, "Stop() reset the animation" );
212 setTimeout(function(){
213 // Disabled, being flaky
214 //equals( $foo.queue().length, 2, "The next animation continued" );
221 test("toggle()", function() {
223 var x = jQuery("#nothiddendiv");
224 ok( x.is(":visible"), "is visible" );
226 ok( x.is(":hidden"), "is hidden" );
228 ok( x.is(":visible"), "is visible again" );
231 ok( x.is(":visible"), "is visible" );
233 ok( x.is(":hidden"), "is hidden" );
235 ok( x.is(":visible"), "is visible again" );
238 jQuery.checkOverflowDisplay = function(){
239 var o = jQuery.css( this, "overflow" );
241 equals(o, "visible", "Overflow should be visible: " + o);
242 equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
247 test("JS Overflow and Display", function() {
250 jQuery.makeTest( "JS Overflow and Display" )
251 .addClass("widewidth")
252 .css({ overflow: "visible", display: "inline" })
253 .addClass("widewidth")
254 .text("Some sample text.")
255 .before("text before")
257 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
260 test("CSS Overflow and Display", function() {
263 jQuery.makeTest( "CSS Overflow and Display" )
264 .addClass("overflow inline")
265 .addClass("widewidth")
266 .text("Some sample text.")
267 .before("text before")
269 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
273 "CSS Auto": function(elem,prop){
274 jQuery(elem).addClass("auto" + prop)
275 .text("This is a long string of text.");
278 "JS Auto": function(elem,prop){
279 jQuery(elem).css(prop,"auto")
280 .text("This is a long string of text.");
283 "CSS 100": function(elem,prop){
284 jQuery(elem).addClass("large" + prop);
287 "JS 100": function(elem,prop){
288 jQuery(elem).css(prop,prop == "opacity" ? 1 : "100px");
289 return prop == "opacity" ? 1 : 100;
291 "CSS 50": function(elem,prop){
292 jQuery(elem).addClass("med" + prop);
295 "JS 50": function(elem,prop){
296 jQuery(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
297 return prop == "opacity" ? 0.5 : 50;
299 "CSS 0": function(elem,prop){
300 jQuery(elem).addClass("no" + prop);
303 "JS 0": function(elem,prop){
304 jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px");
309 "show": function(elem,prop){
310 jQuery(elem).hide().addClass("wide"+prop);
313 "hide": function(elem,prop){
314 jQuery(elem).addClass("wide"+prop);
317 "100": function(elem,prop){
318 jQuery(elem).addClass("wide"+prop);
319 return prop == "opacity" ? 1 : 100;
321 "50": function(elem,prop){
322 return prop == "opacity" ? 0.50 : 50;
324 "0": function(elem,prop){
325 jQuery(elem).addClass("noback");
329 test(fn + " to " + tn, function() {
330 var elem = jQuery.makeTest( fn + " to " + tn );
332 var t_w = t( elem, "width" );
333 var f_w = f( elem, "width" );
334 var t_h = t( elem, "height" );
335 var f_h = f( elem, "height" );
336 var t_o = t( elem, "opacity" );
337 var f_o = f( elem, "opacity" );
341 if ( t_h == "show" ) num++;
342 if ( t_w == "show" ) num++;
343 if ( t_w == "hide"||t_w == "show" ) num++;
344 if ( t_h == "hide"||t_h == "show" ) num++;
345 if ( t_o == "hide"||t_o == "show" ) num++;
346 if ( t_w == "hide" ) num++;
347 if ( t_o.constructor == Number ) num += 2;
348 if ( t_w.constructor == Number ) num += 2;
349 if ( t_h.constructor == Number ) num +=2;
354 var anim = { width: t_w, height: t_h, opacity: t_o };
356 elem.animate(anim, 50, function(){
358 equals( this.style.display, "block", "Showing, display should block: " + this.style.display);
360 if ( t_w == "hide"||t_w == "show" )
361 equals(this.style.width.indexOf(f_w), 0, "Width must be reset to " + f_w + ": " + this.style.width);
363 if ( t_h == "hide"||t_h == "show" )
364 equals(this.style.height.indexOf(f_h), 0, "Height must be reset to " + f_h + ": " + this.style.height);
366 var cur_o = jQuery.style(this, "opacity");
367 if ( cur_o !== "" ) cur_o = parseFloat( cur_o );
369 if ( t_o == "hide"||t_o == "show" )
370 equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
373 equals(this.style.display, "none", "Hiding, display should be none: " + this.style.display);
375 if ( t_o.constructor == Number ) {
376 equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o);
378 ok(jQuery.curCSS(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
381 if ( t_w.constructor == Number ) {
382 equals(this.style.width, t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
384 var cur_w = jQuery.css(this,"width");
386 ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
389 if ( t_h.constructor == Number ) {
390 equals(this.style.height, t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
392 var cur_h = jQuery.css(this,"height");
394 ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
397 if ( t_h == "show" ) {
398 var old_h = jQuery.curCSS(this, "height");
399 jQuery(elem).append("<br/>Some more text<br/>and some more...");
400 ok(old_h != jQuery.css(this, "height" ), "Make sure height is auto.");
409 jQuery.fn.saveState = function(){
410 var check = ['opacity','height','width','display','overflow'];
411 expect(check.length);
414 return this.each(function(){
417 jQuery.each(check, function(i,c){
418 self.save[c] = jQuery.css(self,c);
423 jQuery.checkState = function(){
425 jQuery.each(this.save, function(c,v){
426 var cur = jQuery.css(self,c);
427 equals( v, cur, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
433 test("Chain fadeOut fadeIn", function() {
434 jQuery('#fadein div').saveState().fadeOut('fast').fadeIn('fast',jQuery.checkState);
436 test("Chain fadeIn fadeOut", function() {
437 jQuery('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',jQuery.checkState);
440 test("Chain hide show", function() {
441 jQuery('#show div').saveState().hide('fast').show('fast',jQuery.checkState);
443 test("Chain show hide", function() {
444 jQuery('#hide div').saveState().show('fast').hide('fast',jQuery.checkState);
447 test("Chain toggle in", function() {
448 jQuery('#togglein div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
450 test("Chain toggle out", function() {
451 jQuery('#toggleout div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
454 test("Chain slideDown slideUp", function() {
455 jQuery('#slidedown div').saveState().slideDown('fast').slideUp('fast',jQuery.checkState);
457 test("Chain slideUp slideDown", function() {
458 jQuery('#slideup div').saveState().slideUp('fast').slideDown('fast',jQuery.checkState);
461 test("Chain slideToggle in", function() {
462 jQuery('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
464 test("Chain slideToggle out", function() {
465 jQuery('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
468 jQuery.makeTest = function( text ){
469 var elem = jQuery("<div></div>")
470 .attr("id", "test" + jQuery.makeTest.id++)
475 .appendTo("#fx-tests")
477 jQuery(this).next().toggle();
484 jQuery.makeTest.id = 1;