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 hyphenated properties", function(){
107 jQuery("#nothiddendiv")
108 .css("font-size", 10)
109 .animate({"font-size": 20}, 200, function(){
110 equals( this.style.fontSize, "20px", "The font-size property was animated." );
115 test("animate non-element", function(){
119 var obj = { test: 0 };
121 jQuery(obj).animate({test: 200}, 200, function(){
122 equals( obj.test, 200, "The custom property should be modified." );
127 test("stop()", function() {
131 var $foo = jQuery("#nothiddendiv");
133 $foo.hide().width(200).width();
135 $foo.animate({ width:'show' }, 1000);
136 setTimeout(function(){
137 var nw = $foo.width();
138 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
142 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
143 setTimeout(function(){
144 equals( nw, $foo.width(), "The animation didn't continue" );
150 test("stop() - several in queue", function() {
154 var $foo = jQuery("#nothiddendivchild");
156 $foo.hide().width(200).width();
158 $foo.animate({ width:'show' }, 1000);
159 $foo.animate({ width:'hide' }, 1000);
160 $foo.animate({ width:'show' }, 1000);
161 setTimeout(function(){
162 equals( $foo.queue().length, 3, "All 3 still in the queue" );
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 // Disabled, being flaky
170 //equals( $foo.queue().length, 1, "The next animation continued" );
176 test("stop(clearQueue)", function() {
180 var $foo = jQuery("#nothiddendiv");
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 var nw = $foo.width();
189 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
193 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
195 equals( $foo.queue().length, 0, "The animation queue was cleared" );
196 setTimeout(function(){
197 equals( nw, $foo.width(), "The animation didn't continue" );
203 test("stop(clearQueue, gotoEnd)", function() {
207 var $foo = jQuery("#nothiddendivchild");
209 $foo.hide().width(200).width();
211 $foo.animate({ width:'show' }, 1000);
212 $foo.animate({ width:'hide' }, 1000);
213 $foo.animate({ width:'show' }, 1000);
214 $foo.animate({ width:'hide' }, 1000);
215 setTimeout(function(){
216 var nw = $foo.width();
217 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
218 $foo.stop(false, true);
221 // Disabled, being flaky
222 //equals( nw, 1, "Stop() reset the animation" );
224 setTimeout(function(){
225 // Disabled, being flaky
226 //equals( $foo.queue().length, 2, "The next animation continued" );
233 test("toggle()", function() {
235 var x = jQuery("#nothiddendiv");
236 ok( x.is(":visible"), "is visible" );
238 ok( x.is(":hidden"), "is hidden" );
240 ok( x.is(":visible"), "is visible again" );
243 ok( x.is(":visible"), "is visible" );
245 ok( x.is(":hidden"), "is hidden" );
247 ok( x.is(":visible"), "is visible again" );
250 jQuery.checkOverflowDisplay = function(){
251 var o = jQuery.css( this, "overflow" );
253 equals(o, "visible", "Overflow should be visible: " + o);
254 equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
259 test("JS Overflow and Display", function() {
262 jQuery.makeTest( "JS Overflow and Display" )
263 .addClass("widewidth")
264 .css({ overflow: "visible", display: "inline" })
265 .addClass("widewidth")
266 .text("Some sample text.")
267 .before("text before")
269 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
272 test("CSS Overflow and Display", function() {
275 jQuery.makeTest( "CSS Overflow and Display" )
276 .addClass("overflow inline")
277 .addClass("widewidth")
278 .text("Some sample text.")
279 .before("text before")
281 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
285 "CSS Auto": function(elem,prop){
286 jQuery(elem).addClass("auto" + prop)
287 .text("This is a long string of text.");
290 "JS Auto": function(elem,prop){
291 jQuery(elem).css(prop,"auto")
292 .text("This is a long string of text.");
295 "CSS 100": function(elem,prop){
296 jQuery(elem).addClass("large" + prop);
299 "JS 100": function(elem,prop){
300 jQuery(elem).css(prop,prop == "opacity" ? 1 : "100px");
301 return prop == "opacity" ? 1 : 100;
303 "CSS 50": function(elem,prop){
304 jQuery(elem).addClass("med" + prop);
307 "JS 50": function(elem,prop){
308 jQuery(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
309 return prop == "opacity" ? 0.5 : 50;
311 "CSS 0": function(elem,prop){
312 jQuery(elem).addClass("no" + prop);
315 "JS 0": function(elem,prop){
316 jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px");
321 "show": function(elem,prop){
322 jQuery(elem).hide().addClass("wide"+prop);
325 "hide": function(elem,prop){
326 jQuery(elem).addClass("wide"+prop);
329 "100": function(elem,prop){
330 jQuery(elem).addClass("wide"+prop);
331 return prop == "opacity" ? 1 : 100;
333 "50": function(elem,prop){
334 return prop == "opacity" ? 0.50 : 50;
336 "0": function(elem,prop){
337 jQuery(elem).addClass("noback");
341 test(fn + " to " + tn, function() {
342 var elem = jQuery.makeTest( fn + " to " + tn );
344 var t_w = t( elem, "width" );
345 var f_w = f( elem, "width" );
346 var t_h = t( elem, "height" );
347 var f_h = f( elem, "height" );
348 var t_o = t( elem, "opacity" );
349 var f_o = f( elem, "opacity" );
353 if ( t_h == "show" ) num++;
354 if ( t_w == "show" ) num++;
355 if ( t_w == "hide"||t_w == "show" ) num++;
356 if ( t_h == "hide"||t_h == "show" ) num++;
357 if ( t_o == "hide"||t_o == "show" ) num++;
358 if ( t_w == "hide" ) num++;
359 if ( t_o.constructor == Number ) num += 2;
360 if ( t_w.constructor == Number ) num += 2;
361 if ( t_h.constructor == Number ) num +=2;
366 var anim = { width: t_w, height: t_h, opacity: t_o };
368 elem.animate(anim, 50, function(){
370 equals( this.style.display, "block", "Showing, display should block: " + this.style.display);
372 if ( t_w == "hide"||t_w == "show" )
373 equals(this.style.width.indexOf(f_w), 0, "Width must be reset to " + f_w + ": " + this.style.width);
375 if ( t_h == "hide"||t_h == "show" )
376 equals(this.style.height.indexOf(f_h), 0, "Height must be reset to " + f_h + ": " + this.style.height);
378 var cur_o = jQuery.style(this, "opacity");
379 if ( cur_o !== "" ) cur_o = parseFloat( cur_o );
381 if ( t_o == "hide"||t_o == "show" )
382 equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
385 equals(this.style.display, "none", "Hiding, display should be none: " + this.style.display);
387 if ( t_o.constructor == Number ) {
388 equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o);
390 ok(jQuery.curCSS(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
393 if ( t_w.constructor == Number ) {
394 equals(this.style.width, t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
396 var cur_w = jQuery.css(this,"width");
398 ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
401 if ( t_h.constructor == Number ) {
402 equals(this.style.height, t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
404 var cur_h = jQuery.css(this,"height");
406 ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
409 if ( t_h == "show" ) {
410 var old_h = jQuery.curCSS(this, "height");
411 jQuery(elem).append("<br/>Some more text<br/>and some more...");
412 ok(old_h != jQuery.css(this, "height" ), "Make sure height is auto.");
421 jQuery.fn.saveState = function(){
422 var check = ['opacity','height','width','display','overflow'];
423 expect(check.length);
426 return this.each(function(){
429 jQuery.each(check, function(i,c){
430 self.save[c] = jQuery.css(self,c);
435 jQuery.checkState = function(){
437 jQuery.each(this.save, function(c,v){
438 var cur = jQuery.css(self,c);
439 equals( v, cur, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
445 test("Chain fadeOut fadeIn", function() {
446 jQuery('#fadein div').saveState().fadeOut('fast').fadeIn('fast',jQuery.checkState);
448 test("Chain fadeIn fadeOut", function() {
449 jQuery('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',jQuery.checkState);
452 test("Chain hide show", function() {
453 jQuery('#show div').saveState().hide('fast').show('fast',jQuery.checkState);
455 test("Chain show hide", function() {
456 jQuery('#hide div').saveState().show('fast').hide('fast',jQuery.checkState);
459 test("Chain toggle in", function() {
460 jQuery('#togglein div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
462 test("Chain toggle out", function() {
463 jQuery('#toggleout div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
466 test("Chain slideDown slideUp", function() {
467 jQuery('#slidedown div').saveState().slideDown('fast').slideUp('fast',jQuery.checkState);
469 test("Chain slideUp slideDown", function() {
470 jQuery('#slideup div').saveState().slideUp('fast').slideDown('fast',jQuery.checkState);
473 test("Chain slideToggle in", function() {
474 jQuery('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
476 test("Chain slideToggle out", function() {
477 jQuery('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
480 jQuery.makeTest = function( text ){
481 var elem = jQuery("<div></div>")
482 .attr("id", "test" + jQuery.makeTest.id++)
487 .appendTo("#fx-tests")
489 jQuery(this).next().toggle();
496 jQuery.makeTest.id = 1;