Fix olddisplay was inappropriately set when calling hide on an already hidden element...
[jquery.git] / test / unit / effects.js
index 47266ed..2dfe834 100644 (file)
@@ -38,9 +38,10 @@ test("show()", function() {
        });
 
        // #show-tests * is set display: none in CSS
-       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>');
-
-       var old = jQuery("#show-tests table").show().css("display") !== "table";
+       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><table id="test-table"></table>');
+       
+       var old = jQuery("#test-table").show().css("display") !== "table";
+       jQuery("#test-table").remove();
 
        var test = {
                "div"      : "block",
@@ -71,10 +72,11 @@ test("show(Number) - other displays", function() {
        stop();
 
        // #show-tests * is set display: none in CSS
-       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>');
+       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><table id="test-table"></table>');
 
-       var old = jQuery("#show-tests table").show().css("display") !== "table",
+       var old = jQuery("#test-table").show().css("display") !== "table",
                num = 0;
+       jQuery("#test-table").remove();
 
        var test = {
                "div"      : "block",
@@ -94,10 +96,7 @@ test("show(Number) - other displays", function() {
        };
 
        jQuery.each(test, function(selector, expected) {
-               // IE sometimes has issues with chained functions referencing
-               // assignments from outside the closure
-               var elem = jQuery(selector, "#show-tests");
-               elem.show(1, function() {
+               var elem = jQuery(selector, "#show-tests").show(1, function() {
                        equals( elem.css("display"), expected, "Show using correct display type for " + selector );
                        if ( ++num === 15 ) {
                                start();
@@ -460,10 +459,9 @@ test("toggle()", function() {
 });
 
 jQuery.checkOverflowDisplay = function(){
-       var o = jQuery.css( this, "overflow" ),
-               expected = jQuery.support.shrinkWrapBlocks ? "hidden" : "visible";
+       var o = jQuery.css( this, "overflow" );
 
-       equals(o, expected, "Overflow should be " + expected + ": " + o);
+       equals(o, "visible", "Overflow should be visible: " + o);
        equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
 
        start();
@@ -635,7 +633,7 @@ jQuery.each( {
        });
 });
 
-jQuery.fn.saveState = function(){
+jQuery.fn.saveState = function(hiddenOverflow){
        var check = ['opacity','height','width','display','overflow'];
        expect(check.length);
 
@@ -644,7 +642,7 @@ jQuery.fn.saveState = function(){
                var self = this;
                self.save = {};
                jQuery.each(check, function(i,c){
-                       self.save[c] = self.style[ c ] || jQuery.css(self,c);
+                       self.save[c] = c === "overflow" && hiddenOverflow ? "hidden" : self.style[ c ] || jQuery.css(self,c);
                });
        });
 };
@@ -653,9 +651,6 @@ jQuery.checkState = function(){
        var self = this;
        jQuery.each(this.save, function(c,v){
                var cur = self.style[ c ] || jQuery.css(self, c);
-               if ( c === "overflow" && jQuery.support.shrinkWrapBlocks ) {
-                       v = "hidden";
-               }
                equals( cur, v, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
        });
        start();
@@ -670,39 +665,39 @@ test("Chain fadeIn fadeOut", function() {
 });
 
 test("Chain hide show", function() {
-       jQuery('#show div').saveState().hide('fast').show('fast',jQuery.checkState);
+       jQuery('#show div').saveState(jQuery.support.shrinkWrapBlocks).hide('fast').show('fast',jQuery.checkState);
 });
 test("Chain show hide", function() {
-       jQuery('#hide div').saveState().show('fast').hide('fast',jQuery.checkState);
+       jQuery('#hide div').saveState(jQuery.support.shrinkWrapBlocks).show('fast').hide('fast',jQuery.checkState);
 });
 test("Chain show hide with easing and callback", function() {
        jQuery('#hide div').saveState().show('fast').hide('fast','linear',jQuery.checkState);
 });
 
 test("Chain toggle in", function() {
-       jQuery('#togglein div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
+       jQuery('#togglein div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast',jQuery.checkState);
 });
 test("Chain toggle out", function() {
-       jQuery('#toggleout div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
+       jQuery('#toggleout div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast',jQuery.checkState);
 });
 test("Chain toggle out with easing and callback", function() {
- jQuery('#toggleout div').saveState().toggle('fast').toggle('fast','linear',jQuery.checkState);
+ jQuery('#toggleout div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast','linear',jQuery.checkState);
 });
 test("Chain slideDown slideUp", function() {
-       jQuery('#slidedown div').saveState().slideDown('fast').slideUp('fast',jQuery.checkState);
+       jQuery('#slidedown div').saveState(jQuery.support.shrinkWrapBlocks).slideDown('fast').slideUp('fast',jQuery.checkState);
 });
 test("Chain slideUp slideDown", function() {
-       jQuery('#slideup div').saveState().slideUp('fast').slideDown('fast',jQuery.checkState);
+       jQuery('#slideup div').saveState(jQuery.support.shrinkWrapBlocks).slideUp('fast').slideDown('fast',jQuery.checkState);
 });
 test("Chain slideUp slideDown with easing and callback", function() {
-       jQuery('#slideup div').saveState().slideUp('fast').slideDown('fast','linear',jQuery.checkState);
+       jQuery('#slideup div').saveState(jQuery.support.shrinkWrapBlocks).slideUp('fast').slideDown('fast','linear',jQuery.checkState);
 });
 
 test("Chain slideToggle in", function() {
-       jQuery('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
+       jQuery('#slidetogglein div').saveState(jQuery.support.shrinkWrapBlocks).slideToggle('fast').slideToggle('fast',jQuery.checkState);
 });
 test("Chain slideToggle out", function() {
-       jQuery('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
+       jQuery('#slidetoggleout div').saveState(jQuery.support.shrinkWrapBlocks).slideToggle('fast').slideToggle('fast',jQuery.checkState);
 });
 
 test("Chain fadeTo 0.5 1.0 with easing and callback)", function() {
@@ -775,3 +770,33 @@ test("animate with per-property easing", function(){
        });
 
 });
+
+test("hide hidden elements (bug #7141)", function() {
+       expect(3);
+       QUnit.reset();
+
+       var div = jQuery("<div style='display:none'></div>").appendTo("#main");
+       equals( div.css("display"), "none", "Element is hidden by default" );
+       div.hide();
+       ok( !div.data("olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
+       div.show();
+       equals( div.css("display"), "block", "Show a double-hidden element" );
+
+       div.remove();
+});
+
+test("hide hidden elements, with animation (bug #7141)", function() {
+       expect(3);
+       QUnit.reset();
+       stop();
+       
+       var div = jQuery("<div style='display:none'></div>").appendTo("#main");
+       equals( div.css("display"), "none", "Element is hidden by default" );
+       div.hide(1, function () {
+               ok( !div.data("olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
+               div.show(1, function () {
+                       equals( div.css("display"), "block", "Show a double-hidden element" );
+                       start();
+               });
+       });
+});