X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=test%2Funit%2Feffects.js;h=c0a812f45caabcb49debc2f00380c668b2080225;hb=bd4468886d97edfb53342e1a10acb300d081ed27;hp=47266ed4ec78efb4f328154e68edd5d45b0dc403;hpb=5057ff9f43017f673894584358ca95c8753b65d4;p=jquery.git
diff --git a/test/unit/effects.js b/test/unit/effects.js
index 47266ed..c0a812f 100644
--- a/test/unit/effects.js
+++ b/test/unit/effects.js
@@ -1,4 +1,4 @@
-module("effects");
+module("effects", { teardown: moduleTeardown });
test("sanity check", function() {
expect(1);
@@ -6,7 +6,32 @@ test("sanity check", function() {
});
test("show()", function() {
- expect(23);
+ expect(28);
+
+ var hiddendiv = jQuery("div.hidden");
+
+ hiddendiv.hide().show();
+
+ equals( hiddendiv.css("display"), "block", "Make sure a pre-hidden div is visible." );
+
+ var div = jQuery("
").hide().appendTo("#main").show();
+
+ equal( div.css("display"), "block", "Make sure pre-hidden divs show" );
+
+ QUnit.reset();
+
+ hiddendiv = jQuery("div.hidden");
+
+ equal(jQuery.css( hiddendiv[0], "display"), "none", "hiddendiv is display: none");
+
+ hiddendiv.css("display", "block");
+ equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
+
+ hiddendiv.show();
+ equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
+
+ hiddendiv.css("display","");
+
var pass = true, div = jQuery("#main div");
div.show().each(function(){
if ( this.style.display == "none" ) pass = false;
@@ -14,33 +39,33 @@ test("show()", function() {
ok( pass, "Show" );
var speeds = {
- "null speed": null,
- "undefined speed": undefined,
- "empty string speed": "",
- "false speed": false
+ "null speed": null,
+ "undefined speed": undefined,
+ "empty string speed": "",
+ "false speed": false
};
jQuery.each(speeds, function(name, speed) {
- pass = true;
- div.hide().show(speed).each(function() {
- if ( this.style.display == "none" ) pass = false;
- });
- ok( pass, "Show with " + name);
- });
-
+ pass = true;
+ div.hide().show(speed).each(function() {
+ if ( this.style.display == "none" ) pass = false;
+ });
+ ok( pass, "Show with " + name);
+ });
jQuery.each(speeds, function(name, speed) {
- pass = true;
- div.hide().show(speed, function() {
+ pass = true;
+ div.hide().show(speed, function() {
pass = false;
});
ok( pass, "Show with " + name + " does not call animate callback" );
});
// #show-tests * is set display: none in CSS
- jQuery("#main").append('
');
+ jQuery("#main").append('
');
- var old = jQuery("#show-tests table").show().css("display") !== "table";
+ var old = jQuery("#test-table").show().css("display") !== "table";
+ jQuery("#test-table").remove();
var test = {
"div" : "block",
@@ -71,10 +96,11 @@ test("show(Number) - other displays", function() {
stop();
// #show-tests * is set display: none in CSS
- jQuery("#main").append('
');
+ jQuery("#main").append('
');
- 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 +120,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();
@@ -106,6 +129,39 @@ test("show(Number) - other displays", function() {
});
});
+
+
+// Supports #7397
+test("Persist correct display value", function() {
+ expect(3);
+ QUnit.reset();
+ stop();
+
+ // #show-tests * is set display: none in CSS
+ jQuery("#main").append('
foo
');
+
+ var $span = jQuery("#show-tests span"),
+ displayNone = $span.css("display"),
+ display = '', num = 0;
+
+ $span.show();
+
+ display = $span.css("display");
+
+ $span.hide();
+
+ $span.fadeIn(100, function() {
+ equals($span.css("display"), display, "Expecting display: " + display);
+ $span.fadeOut(100, function () {
+ equals($span.css("display"), displayNone, "Expecting display: " + displayNone);
+ $span.fadeIn(100, function() {
+ equals($span.css("display"), display, "Expecting display: " + display);
+ start();
+ });
+ });
+ });
+});
+
test("animate(Hash, Object, Function)", function() {
expect(1);
stop();
@@ -128,27 +184,56 @@ test("animate negative height", function() {
test("animate block as inline width/height", function() {
expect(3);
- stop();
- jQuery("#foo").css({ display: "inline", width: '', height: '' }).animate({ width: 42, height: 42 }, 100, function() {
- equals( jQuery(this).css("display"), jQuery.support.inlineBlockNeedsLayout ? "inline" : "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
- equals( this.offsetWidth, 42, "width was animated" );
- equals( this.offsetHeight, 42, "height was animated" );
- start();
- });
+
+ var span = jQuery("
").css("display", "inline-block").appendTo("body"),
+ expected = span.css("display");
+
+ span.remove();
+
+ if ( jQuery.support.inlineBlockNeedsLayout || expected === "inline-block" ) {
+ stop();
+
+ jQuery("#foo").css({ display: "inline", width: '', height: '' }).animate({ width: 42, height: 42 }, 100, function() {
+ equals( jQuery(this).css("display"), jQuery.support.inlineBlockNeedsLayout ? "inline" : "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
+ equals( this.offsetWidth, 42, "width was animated" );
+ equals( this.offsetHeight, 42, "height was animated" );
+ start();
+ });
+
+ // Browser doesn't support inline-block
+ } else {
+ ok( true, "Browser doesn't support inline-block" );
+ ok( true, "Browser doesn't support inline-block" );
+ ok( true, "Browser doesn't support inline-block" );
+ }
});
test("animate native inline width/height", function() {
expect(3);
- stop();
- jQuery("#foo").css({ display: "", width: '', height: '' })
- .append('text')
- .children('span')
- .animate({ width: 42, height: 42 }, 100, function() {
- equals( jQuery(this).css("display"), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
- equals( this.offsetWidth, 42, "width was animated" );
- equals( this.offsetHeight, 42, "height was animated" );
- start();
- });
+
+ var span = jQuery("").css("display", "inline-block").appendTo("body"),
+ expected = span.css("display");
+
+ span.remove();
+
+ if ( jQuery.support.inlineBlockNeedsLayout || expected === "inline-block" ) {
+ stop();
+ jQuery("#foo").css({ display: "", width: '', height: '' })
+ .append('text')
+ .children('span')
+ .animate({ width: 42, height: 42 }, 100, function() {
+ equals( jQuery(this).css("display"), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
+ equals( this.offsetWidth, 42, "width was animated" );
+ equals( this.offsetHeight, 42, "height was animated" );
+ start();
+ });
+
+ // Browser doesn't support inline-block
+ } else {
+ ok( true, "Browser doesn't support inline-block" );
+ ok( true, "Browser doesn't support inline-block" );
+ ok( true, "Browser doesn't support inline-block" );
+ }
});
test("animate block width/height", function() {
@@ -311,13 +396,16 @@ test("animate duration 0", function() {
$elem.hide(0, function(){
ok(true, "Hide callback with no duration");
});
+
+ // manually clean up detached elements
+ $elem.remove();
});
test("animate hyphenated properties", function(){
expect(1);
stop();
- jQuery("#nothiddendiv")
+ jQuery("#foo")
.css("font-size", 10)
.animate({"font-size": 20}, 200, function(){
equals( this.style.fontSize, "20px", "The font-size property was animated." );
@@ -341,7 +429,7 @@ test("stop()", function() {
expect(3);
stop();
- var $foo = jQuery("#nothiddendiv");
+ var $foo = jQuery("#foo");
var w = 0;
$foo.hide().width(200).width();
@@ -354,6 +442,8 @@ test("stop()", function() {
nw = $foo.width();
notEqual( nw, w, "Stop didn't reset the animation " + nw + "px " + w + "px");
setTimeout(function(){
+ $foo.removeData();
+ $foo.removeData(undefined, true);
equals( nw, $foo.width(), "The animation didn't continue" );
start();
}, 100);
@@ -364,7 +454,7 @@ test("stop() - several in queue", function() {
expect(3);
stop();
- var $foo = jQuery("#nothiddendivchild");
+ var $foo = jQuery("#foo");
var w = 0;
$foo.hide().width(200).width();
@@ -389,7 +479,7 @@ test("stop(clearQueue)", function() {
expect(4);
stop();
- var $foo = jQuery("#nothiddendiv");
+ var $foo = jQuery("#foo");
var w = 0;
$foo.hide().width(200).width();
@@ -416,7 +506,7 @@ test("stop(clearQueue, gotoEnd)", function() {
expect(1);
stop();
- var $foo = jQuery("#nothiddendivchild");
+ var $foo = jQuery("#foo");
var w = 0;
$foo.hide().width(200).width();
@@ -444,7 +534,7 @@ test("stop(clearQueue, gotoEnd)", function() {
test("toggle()", function() {
expect(6);
- var x = jQuery("#nothiddendiv");
+ var x = jQuery("#foo");
ok( x.is(":visible"), "is visible" );
x.toggle();
ok( x.is(":hidden"), "is hidden" );
@@ -460,15 +550,64 @@ 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();
}
+test( "jQuery.fx.prototype.cur()", 6, function() {
+ var div = jQuery( "" ).appendTo( "#main" ).css({
+ color: "#ABC",
+ border: "5px solid black",
+ left: "auto",
+ marginBottom: "-11000px"
+ })[0];
+
+ equals(
+ ( new jQuery.fx( div, {}, "color" ) ).cur(),
+ jQuery.css( div, "color" ),
+ "Return the same value as jQuery.css for complex properties (bug #7912)"
+ );
+
+ strictEqual(
+ ( new jQuery.fx( div, {}, "borderLeftWidth" ) ).cur(),
+ 5,
+ "Return simple values parsed as Float"
+ );
+
+ // backgroundPosition actually returns 0% 0% in most browser
+ // this fakes a "" return
+ jQuery.cssHooks.backgroundPosition = {
+ get: function() {
+ ok( true, "hook used" );
+ return "";
+ }
+ };
+
+ strictEqual(
+ ( new jQuery.fx( div, {}, "backgroundPosition" ) ).cur(),
+ 0,
+ "Return 0 when jQuery.css returns an empty string"
+ );
+
+ delete jQuery.cssHooks.backgroundPosition;
+
+ strictEqual(
+ ( new jQuery.fx( div, {}, "left" ) ).cur(),
+ 0,
+ "Return 0 when jQuery.css returns 'auto'"
+ );
+
+ equals(
+ ( new jQuery.fx( div, {}, "marginBottom" ) ).cur(),
+ -11000,
+ "support negative values < -10000 (bug #7193)"
+ );
+});
+
test("JS Overflow and Display", function() {
expect(2);
stop();
@@ -629,13 +768,16 @@ jQuery.each( {
}
}
+ // manually remove generated element
+ jQuery(this).remove();
+
start();
});
});
});
});
-jQuery.fn.saveState = function(){
+jQuery.fn.saveState = function(hiddenOverflow){
var check = ['opacity','height','width','display','overflow'];
expect(check.length);
@@ -644,7 +786,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,11 +795,12 @@ 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 + ")");
});
+
+ // manually clean data on modified element
+ jQuery.removeData(this, 'olddisplay', true);
+
start();
}
@@ -670,39 +813,46 @@ 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 fadeToggle in", function() {
+ jQuery('#fadetogglein div').saveState().fadeToggle('fast').fadeToggle('fast',jQuery.checkState);
+});
+test("Chain fadeToggle out", function() {
+ jQuery('#fadetoggleout div').saveState().fadeToggle('fast').fadeToggle('fast',jQuery.checkState);
});
test("Chain fadeTo 0.5 1.0 with easing and callback)", function() {
@@ -717,9 +867,6 @@ jQuery.makeTest = function( text ){
jQuery("")
.text( text )
.appendTo("#fx-tests")
- .click(function(){
- jQuery(this).next().toggle();
- })
.after( elem );
return elem;
@@ -729,16 +876,16 @@ jQuery.makeTest.id = 1;
test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function () {
expect(4);
- stop();
+ stop();
var $checkedtest = jQuery("#checkedtest");
// IE6 was clearing "checked" in jQuery(elem).show("fast");
$checkedtest.hide().show("fast", function() {
- ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
- ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
- ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
- ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
- start();
+ ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
+ ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
+ ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
+ ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
+ start();
});
});
@@ -775,3 +922,43 @@ test("animate with per-property easing", function(){
});
});
+
+test("hide hidden elements (bug #7141)", function() {
+ expect(3);
+ QUnit.reset();
+
+ var div = jQuery("").appendTo("#main");
+ equals( div.css("display"), "none", "Element is hidden by default" );
+ div.hide();
+ ok( !jQuery._data(div, "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("").appendTo("#main");
+ equals( div.css("display"), "none", "Element is hidden by default" );
+ div.hide(1, function () {
+ ok( !jQuery._data(div, "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();
+ });
+ });
+});
+
+test("animate unit-less properties (#4966)", 2, function() {
+ stop();
+ var div = jQuery( "" ).appendTo( "#main" );
+ equal( div.css( "z-index" ), "0", "z-index is 0" );
+ div.animate({ zIndex: 2 }, function() {
+ equal( div.css( "z-index" ), "2", "z-index is 2" );
+ start();
+ });
+});