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 test("animate option (queue === false)", function () {
55 var $foo = jQuery("#foo");
56 $foo.animate({width:'100px'}, 3000, function () {
57 // should finish after unqueued animation so second
59 isSet( order, [ 1, 2 ], "Animations finished in the correct order" );
62 $foo.animate({fontSize:'2em'}, {queue:false, duration:10, complete:function () {
63 // short duration and out of queue so should finish first
68 test("animate duration 0", function() {
73 var $elems = jQuery([{ a:0 },{ a:0 }]),
79 equals( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
81 $elems.eq(0).animate( {a:1}, 0, count );
83 // Failed until [6115]
84 equals( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" );
86 equals( counter, 1, "One synchronic animations" );
88 $elems.animate( { a:2 }, 0, count );
90 equals( counter, 3, "Multiple synchronic animations" );
92 $elems.eq(0).animate( {a:3}, 0, count );
93 $elems.eq(1).animate( {a:3}, 20, function(){
95 // Failed until [6115]
96 equals( counter, 5, "One synchronic and one asynchronic" );
101 test("animate non-element", function(){
105 var obj = { test: 0 };
107 jQuery(obj).animate({test: 200}, 200, function(){
108 equals( obj.test, 200, "The custom property should be modified." );
113 test("stop()", function() {
117 var $foo = jQuery("#nothiddendiv");
119 $foo.hide().width(200).width();
121 $foo.animate({ width:'show' }, 1000);
122 setTimeout(function(){
123 var nw = $foo.width();
124 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
128 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
129 setTimeout(function(){
130 equals( nw, $foo.width(), "The animation didn't continue" );
136 test("stop() - several in queue", function() {
140 var $foo = jQuery("#nothiddendivchild");
142 $foo.hide().width(200).width();
144 $foo.animate({ width:'show' }, 1000);
145 $foo.animate({ width:'hide' }, 1000);
146 $foo.animate({ width:'show' }, 1000);
147 setTimeout(function(){
148 equals( $foo.queue().length, 3, "All 3 still in the queue" );
149 var nw = $foo.width();
150 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
154 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
155 // Disabled, being flaky
156 //equals( $foo.queue().length, 1, "The next animation continued" );
162 test("stop(clearQueue)", function() {
166 var $foo = jQuery("#nothiddendiv");
168 $foo.hide().width(200).width();
170 $foo.animate({ width:'show' }, 1000);
171 $foo.animate({ width:'hide' }, 1000);
172 $foo.animate({ width:'show' }, 1000);
173 setTimeout(function(){
174 var nw = $foo.width();
175 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
179 ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
181 equals( $foo.queue().length, 0, "The animation queue was cleared" );
182 setTimeout(function(){
183 equals( nw, $foo.width(), "The animation didn't continue" );
189 test("stop(clearQueue, gotoEnd)", function() {
193 var $foo = jQuery("#nothiddendivchild");
195 $foo.hide().width(200).width();
197 $foo.animate({ width:'show' }, 1000);
198 $foo.animate({ width:'hide' }, 1000);
199 $foo.animate({ width:'show' }, 1000);
200 $foo.animate({ width:'hide' }, 1000);
201 setTimeout(function(){
202 var nw = $foo.width();
203 ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
204 $foo.stop(false, true);
207 // Disabled, being flaky
208 //equals( nw, 1, "Stop() reset the animation" );
210 setTimeout(function(){
211 // Disabled, being flaky
212 //equals( $foo.queue().length, 2, "The next animation continued" );
219 test("toggle()", function() {
221 var x = jQuery("#nothiddendiv");
222 ok( x.is(":visible"), "is visible" );
224 ok( x.is(":hidden"), "is hidden" );
226 ok( x.is(":visible"), "is visible again" );
229 ok( x.is(":visible"), "is visible" );
231 ok( x.is(":hidden"), "is hidden" );
233 ok( x.is(":visible"), "is visible again" );
236 jQuery.checkOverflowDisplay = function(){
237 var o = jQuery.css( this, "overflow" );
239 equals(o, "visible", "Overflow should be visible: " + o);
240 equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
245 test("JS Overflow and Display", function() {
248 jQuery.makeTest( "JS Overflow and Display" )
249 .addClass("widewidth")
250 .css({ overflow: "visible", display: "inline" })
251 .addClass("widewidth")
252 .text("Some sample text.")
253 .before("text before")
255 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
258 test("CSS Overflow and Display", function() {
261 jQuery.makeTest( "CSS Overflow and Display" )
262 .addClass("overflow inline")
263 .addClass("widewidth")
264 .text("Some sample text.")
265 .before("text before")
267 .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
271 "CSS Auto": function(elem,prop){
272 jQuery(elem).addClass("auto" + prop)
273 .text("This is a long string of text.");
276 "JS Auto": function(elem,prop){
277 jQuery(elem).css(prop,"auto")
278 .text("This is a long string of text.");
281 "CSS 100": function(elem,prop){
282 jQuery(elem).addClass("large" + prop);
285 "JS 100": function(elem,prop){
286 jQuery(elem).css(prop,prop == "opacity" ? 1 : "100px");
287 return prop == "opacity" ? 1 : 100;
289 "CSS 50": function(elem,prop){
290 jQuery(elem).addClass("med" + prop);
293 "JS 50": function(elem,prop){
294 jQuery(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
295 return prop == "opacity" ? 0.5 : 50;
297 "CSS 0": function(elem,prop){
298 jQuery(elem).addClass("no" + prop);
301 "JS 0": function(elem,prop){
302 jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px");
307 "show": function(elem,prop){
308 jQuery(elem).hide().addClass("wide"+prop);
311 "hide": function(elem,prop){
312 jQuery(elem).addClass("wide"+prop);
315 "100": function(elem,prop){
316 jQuery(elem).addClass("wide"+prop);
317 return prop == "opacity" ? 1 : 100;
319 "50": function(elem,prop){
320 return prop == "opacity" ? 0.50 : 50;
322 "0": function(elem,prop){
323 jQuery(elem).addClass("noback");
327 test(fn + " to " + tn, function() {
328 var elem = jQuery.makeTest( fn + " to " + tn );
330 var t_w = t( elem, "width" );
331 var f_w = f( elem, "width" );
332 var t_h = t( elem, "height" );
333 var f_h = f( elem, "height" );
334 var t_o = t( elem, "opacity" );
335 var f_o = f( elem, "opacity" );
339 if ( t_h == "show" ) num++;
340 if ( t_w == "show" ) num++;
341 if ( t_w == "hide"||t_w == "show" ) num++;
342 if ( t_h == "hide"||t_h == "show" ) num++;
343 if ( t_o == "hide"||t_o == "show" ) num++;
344 if ( t_w == "hide" ) num++;
345 if ( t_o.constructor == Number ) num += 2;
346 if ( t_w.constructor == Number ) num += 2;
347 if ( t_h.constructor == Number ) num +=2;
352 var anim = { width: t_w, height: t_h, opacity: t_o };
354 elem.animate(anim, 50, function(){
356 equals( this.style.display, "block", "Showing, display should block: " + this.style.display);
358 if ( t_w == "hide"||t_w == "show" )
359 equals(this.style.width.indexOf(f_w), 0, "Width must be reset to " + f_w + ": " + this.style.width);
361 if ( t_h == "hide"||t_h == "show" )
362 equals(this.style.height.indexOf(f_h), 0, "Height must be reset to " + f_h + ": " + this.style.height);
364 var cur_o = jQuery.style(this, "opacity");
365 if ( cur_o !== "" ) cur_o = parseFloat( cur_o );
367 if ( t_o == "hide"||t_o == "show" )
368 equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
371 equals(this.style.display, "none", "Hiding, display should be none: " + this.style.display);
373 if ( t_o.constructor == Number ) {
374 equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o);
376 ok(jQuery.curCSS(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
379 if ( t_w.constructor == Number ) {
380 equals(this.style.width, t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
382 var cur_w = jQuery.css(this,"width");
384 ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
387 if ( t_h.constructor == Number ) {
388 equals(this.style.height, t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
390 var cur_h = jQuery.css(this,"height");
392 ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
395 if ( t_h == "show" ) {
396 var old_h = jQuery.curCSS(this, "height");
397 jQuery(elem).append("<br/>Some more text<br/>and some more...");
398 ok(old_h != jQuery.css(this, "height" ), "Make sure height is auto.");
407 jQuery.fn.saveState = function(){
408 var check = ['opacity','height','width','display','overflow'];
409 expect(check.length);
412 return this.each(function(){
415 jQuery.each(check, function(i,c){
416 self.save[c] = jQuery.css(self,c);
421 jQuery.checkState = function(){
423 jQuery.each(this.save, function(c,v){
424 var cur = jQuery.css(self,c);
425 equals( v, cur, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
431 test("Chain fadeOut fadeIn", function() {
432 jQuery('#fadein div').saveState().fadeOut('fast').fadeIn('fast',jQuery.checkState);
434 test("Chain fadeIn fadeOut", function() {
435 jQuery('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',jQuery.checkState);
438 test("Chain hide show", function() {
439 jQuery('#show div').saveState().hide('fast').show('fast',jQuery.checkState);
441 test("Chain show hide", function() {
442 jQuery('#hide div').saveState().show('fast').hide('fast',jQuery.checkState);
445 test("Chain toggle in", function() {
446 jQuery('#togglein div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
448 test("Chain toggle out", function() {
449 jQuery('#toggleout div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
452 test("Chain slideDown slideUp", function() {
453 jQuery('#slidedown div').saveState().slideDown('fast').slideUp('fast',jQuery.checkState);
455 test("Chain slideUp slideDown", function() {
456 jQuery('#slideup div').saveState().slideUp('fast').slideDown('fast',jQuery.checkState);
459 test("Chain slideToggle in", function() {
460 jQuery('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
462 test("Chain slideToggle out", function() {
463 jQuery('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
466 jQuery.makeTest = function( text ){
467 var elem = jQuery("<div></div>")
468 .attr("id", "test" + jQuery.makeTest.id++)
473 .appendTo("#fx-tests")
475 jQuery(this).next().toggle();
482 jQuery.makeTest.id = 1;