Completely disable the flaky fx queue test.
[jquery.git] / test / unit / fx.js
1 module("fx");
2
3 test("show()", function() {
4         expect(15);
5         var pass = true, div = jQuery("#main div");
6         div.show().each(function(){
7                 if ( this.style.display == "none" ) pass = false;
8         });
9         ok( pass, "Show" );
10
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>');
12
13         var old = jQuery("#show-tests table").show().css("display") !== "table";
14
15         var test = {
16                 "div"      : "block",
17                 "p"        : "block",
18                 "a"        : "inline",
19                 "code"     : "inline",
20                 "pre"      : "block",
21                 "span"     : "inline",
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",
28                 "ul"       : "block",
29                 "li"       : old ? "block" : "list-item"
30         };
31
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 );
35         });
36 });
37
38 test("animate(Hash, Object, Function)", function() {
39         expect(1);
40         stop();
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' );
45                 start();
46         });
47 });
48
49 /* // This test ends up being flaky depending upon the CPU load
50 test("animate option (queue === false)", function () {
51         expect(1);
52         stop();
53
54         var order = [];
55
56         var $foo = jQuery("#foo");
57         $foo.animate({width:'100px'}, 3000, function () {
58                 // should finish after unqueued animation so second
59                 order.push(2);
60                 isSet( order, [ 1, 2 ], "Animations finished in the correct order" );
61                 start();
62         });
63         $foo.animate({fontSize:'2em'}, {queue:false, duration:10, complete:function () {
64                 // short duration and out of queue so should finish first
65                 order.push(1);
66         }});
67 });
68 */
69
70 test("animate duration 0", function() {
71         expect(5);
72         
73         stop();
74         
75         var $elems = jQuery([{ a:0 },{ a:0 }]),
76                 counter = 0,
77                 count = function(){
78                         counter++;
79                 };
80         
81         equals( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
82                 
83         $elems.eq(0).animate( {a:1}, 0, count );
84         
85         // Failed until [6115]
86         equals( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" );
87         
88         equals( counter, 1, "One synchronic animations" );
89         
90         $elems.animate( { a:2 }, 0, count );
91         
92         equals( counter, 3, "Multiple synchronic animations" );
93         
94         $elems.eq(0).animate( {a:3}, 0, count );
95         $elems.eq(1).animate( {a:3}, 20, function(){
96                 count();
97                 // Failed until [6115]
98                 equals( counter, 5, "One synchronic and one asynchronic" );
99                 start();
100         });     
101 });
102
103 test("animate non-element", function(){
104         expect(1);
105         stop();
106
107         var obj = { test: 0 };
108
109         jQuery(obj).animate({test: 200}, 200, function(){
110                 equals( obj.test, 200, "The custom property should be modified." );
111                 start();
112         });
113 });
114
115 test("stop()", function() {
116         expect(3);
117         stop();
118
119         var $foo = jQuery("#nothiddendiv");
120         var w = 0;
121         $foo.hide().width(200).width();
122
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");
127                 $foo.stop();
128
129                 nw = $foo.width();
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" );
133                         start();
134                 }, 100);
135         }, 100);
136 });
137
138 test("stop() - several in queue", function() {
139         expect(3);
140         stop();
141
142         var $foo = jQuery("#nothiddendivchild");
143         var w = 0;
144         $foo.hide().width(200).width();
145
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");
153                 $foo.stop();
154
155                 nw = $foo.width();
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" );
159                 $foo.stop(true);
160                 start();
161         }, 100);
162 });
163
164 test("stop(clearQueue)", function() {
165         expect(4);
166         stop();
167
168         var $foo = jQuery("#nothiddendiv");
169         var w = 0;
170         $foo.hide().width(200).width();
171
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");
178                 $foo.stop(true);
179
180                 nw = $foo.width();
181                 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
182
183                 equals( $foo.queue().length, 0, "The animation queue was cleared" );
184                 setTimeout(function(){
185                         equals( nw, $foo.width(), "The animation didn't continue" );
186                         start();
187                 }, 100);
188         }, 100);
189 });
190
191 test("stop(clearQueue, gotoEnd)", function() {
192         expect(1);
193         stop();
194
195         var $foo = jQuery("#nothiddendivchild");
196         var w = 0;
197         $foo.hide().width(200).width();
198
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);
207
208                 nw = $foo.width();
209                 // Disabled, being flaky
210                 //equals( nw, 1, "Stop() reset the animation" );
211
212                 setTimeout(function(){
213                         // Disabled, being flaky
214                         //equals( $foo.queue().length, 2, "The next animation continued" );
215                         $foo.stop(true);
216                         start();
217                 }, 100);
218         }, 100);
219 });
220
221 test("toggle()", function() {
222         expect(6);
223         var x = jQuery("#nothiddendiv");
224         ok( x.is(":visible"), "is visible" );
225         x.toggle();
226         ok( x.is(":hidden"), "is hidden" );
227         x.toggle();
228         ok( x.is(":visible"), "is visible again" );
229         
230         x.toggle(true);
231         ok( x.is(":visible"), "is visible" );
232         x.toggle(false);
233         ok( x.is(":hidden"), "is hidden" );
234         x.toggle(true);
235         ok( x.is(":visible"), "is visible again" );
236 });
237
238 jQuery.checkOverflowDisplay = function(){
239         var o = jQuery.css( this, "overflow" );
240
241         equals(o, "visible", "Overflow should be visible: " + o);
242         equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
243
244         start();
245 }
246
247 test("JS Overflow and Display", function() {
248         expect(2);
249         stop();
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")
256                 .after("text after")
257                 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
258 });
259                 
260 test("CSS Overflow and Display", function() {
261         expect(2);
262         stop();
263         jQuery.makeTest( "CSS Overflow and Display" )
264                 .addClass("overflow inline")
265                 .addClass("widewidth")
266                 .text("Some sample text.")
267                 .before("text before")
268                 .after("text after")
269                 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
270 });
271
272 jQuery.each( {
273         "CSS Auto": function(elem,prop){
274                 jQuery(elem).addClass("auto" + prop)
275                         .text("This is a long string of text.");
276                 return "";
277         },
278         "JS Auto": function(elem,prop){
279                 jQuery(elem).css(prop,"auto")
280                         .text("This is a long string of text.");
281                 return "";
282         },
283         "CSS 100": function(elem,prop){
284                 jQuery(elem).addClass("large" + prop);
285                 return "";
286         },
287         "JS 100": function(elem,prop){
288                 jQuery(elem).css(prop,prop == "opacity" ? 1 : "100px");
289                 return prop == "opacity" ? 1 : 100;
290         },
291         "CSS 50": function(elem,prop){
292                 jQuery(elem).addClass("med" + prop);
293                 return "";
294         },
295         "JS 50": function(elem,prop){
296                 jQuery(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
297                 return prop == "opacity" ? 0.5 : 50;
298         },
299         "CSS 0": function(elem,prop){
300                 jQuery(elem).addClass("no" + prop);
301                 return "";
302         },
303         "JS 0": function(elem,prop){
304                 jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px");
305                 return 0;
306         }
307 }, function(fn, f){
308         jQuery.each( {
309                 "show": function(elem,prop){
310                         jQuery(elem).hide().addClass("wide"+prop);
311                         return "show";
312                 },
313                 "hide": function(elem,prop){
314                         jQuery(elem).addClass("wide"+prop);
315                         return "hide";
316                 },
317                 "100": function(elem,prop){
318                         jQuery(elem).addClass("wide"+prop);
319                         return prop == "opacity" ? 1 : 100;
320                 },
321                 "50": function(elem,prop){
322                         return prop == "opacity" ? 0.50 : 50;
323                 },
324                 "0": function(elem,prop){
325                         jQuery(elem).addClass("noback");
326                         return 0;
327                 }
328         }, function(tn, t){
329                 test(fn + " to " + tn, function() {
330                         var elem = jQuery.makeTest( fn + " to " + tn );
331         
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" );
338                         
339                         var num = 0;
340                         
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;
350                         
351                         expect(num);
352                         stop();
353         
354                         var anim = { width: t_w, height: t_h, opacity: t_o };
355         
356                         elem.animate(anim, 50, function(){
357                                 if ( t_w == "show" )
358                                         equals( this.style.display, "block", "Showing, display should block: " + this.style.display);
359                                         
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);
362                                         
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);
365                                         
366                                 var cur_o = jQuery.style(this, "opacity");
367                                 if ( cur_o !== "" ) cur_o = parseFloat( cur_o );
368         
369                                 if ( t_o == "hide"||t_o == "show" )
370                                         equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
371                                         
372                                 if ( t_w == "hide" )
373                                         equals(this.style.display, "none", "Hiding, display should be none: " + this.style.display);
374                                         
375                                 if ( t_o.constructor == Number ) {
376                                         equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o);
377                                         
378                                         ok(jQuery.curCSS(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
379                                 }
380                                         
381                                 if ( t_w.constructor == Number ) {
382                                         equals(this.style.width, t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
383                                         
384                                         var cur_w = jQuery.css(this,"width");
385
386                                         ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
387                                 }
388                                         
389                                 if ( t_h.constructor == Number ) {
390                                         equals(this.style.height, t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
391                                         
392                                         var cur_h = jQuery.css(this,"height");
393
394                                         ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
395                                 }
396                                 
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.");
401                                 }
402         
403                                 start();
404                         });
405                 });
406         });
407 });
408
409 jQuery.fn.saveState = function(){
410         var check = ['opacity','height','width','display','overflow'];  
411         expect(check.length);
412         
413         stop();
414         return this.each(function(){
415                 var self = this;
416                 self.save = {};
417                 jQuery.each(check, function(i,c){
418                         self.save[c] = jQuery.css(self,c);
419                 });
420         });
421 };
422
423 jQuery.checkState = function(){
424         var self = this;
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 + ")");
428         });
429         start();
430 }
431
432 // Chaining Tests
433 test("Chain fadeOut fadeIn", function() {
434         jQuery('#fadein div').saveState().fadeOut('fast').fadeIn('fast',jQuery.checkState);
435 });
436 test("Chain fadeIn fadeOut", function() {
437         jQuery('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',jQuery.checkState);
438 });
439
440 test("Chain hide show", function() {
441         jQuery('#show div').saveState().hide('fast').show('fast',jQuery.checkState);
442 });
443 test("Chain show hide", function() {
444         jQuery('#hide div').saveState().show('fast').hide('fast',jQuery.checkState);
445 });
446
447 test("Chain toggle in", function() {
448         jQuery('#togglein div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
449 });
450 test("Chain toggle out", function() {
451         jQuery('#toggleout div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
452 });
453
454 test("Chain slideDown slideUp", function() {
455         jQuery('#slidedown div').saveState().slideDown('fast').slideUp('fast',jQuery.checkState);
456 });
457 test("Chain slideUp slideDown", function() {
458         jQuery('#slideup div').saveState().slideUp('fast').slideDown('fast',jQuery.checkState);
459 });
460
461 test("Chain slideToggle in", function() {
462         jQuery('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
463 });
464 test("Chain slideToggle out", function() {
465         jQuery('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
466 });
467
468 jQuery.makeTest = function( text ){
469         var elem = jQuery("<div></div>")
470                 .attr("id", "test" + jQuery.makeTest.id++)
471                 .addClass("box");
472
473         jQuery("<h4></h4>")
474                 .text( text )
475                 .appendTo("#fx-tests")
476                 .click(function(){
477                         jQuery(this).next().toggle();
478                 })
479                 .after( elem );
480
481         return elem;
482 }
483
484 jQuery.makeTest.id = 1;