2011-03-29 20:32:48 +00:00
|
|
|
(function($) {
|
|
|
|
|
2011-05-12 15:22:49 +00:00
|
|
|
function present( value, array, message ) {
|
|
|
|
QUnit.push( jQuery.inArray( value, array ) !== -1 , value, array, message );
|
|
|
|
}
|
|
|
|
|
|
|
|
function notPresent( value, array, message ) {
|
|
|
|
QUnit.push( jQuery.inArray( value, array ) === -1 , value, array, message );
|
|
|
|
}
|
|
|
|
|
2011-05-16 22:19:57 +00:00
|
|
|
// minDuration is used for "short" animate tests where we are only concerned about the final
|
|
|
|
var minDuration = 15,
|
|
|
|
|
|
|
|
// duration is used for "long" animates where we plan on testing properties during animation
|
2012-10-23 14:36:42 +00:00
|
|
|
duration = 200;
|
2011-03-29 20:32:48 +00:00
|
|
|
|
2011-05-01 11:23:19 +00:00
|
|
|
module( "effects.core" );
|
|
|
|
|
2013-02-28 18:34:49 +00:00
|
|
|
// TODO: test all signatures of .show(), .hide(), .toggle().
|
|
|
|
// Look at core's signatures and UI's signatures.
|
|
|
|
asyncTest( ".hide() with step", function() {
|
|
|
|
expect( 1 );
|
|
|
|
var element = $( "#elem" ),
|
|
|
|
step = function() {
|
|
|
|
ok( true, "step callback invoked" );
|
|
|
|
step = $.noop;
|
|
|
|
};
|
|
|
|
|
|
|
|
element.hide({
|
|
|
|
step: function() {
|
|
|
|
step();
|
|
|
|
},
|
|
|
|
complete: start
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2011-06-23 12:22:34 +00:00
|
|
|
test( "Immediate Return Conditions", function() {
|
|
|
|
var hidden = $( "div.hidden" ),
|
|
|
|
count = 0;
|
2011-06-23 12:24:48 +00:00
|
|
|
expect( 3 );
|
2011-06-23 12:22:34 +00:00
|
|
|
hidden.hide( "blind", function() {
|
|
|
|
equal( ++count, 1, "Hide on hidden returned immediately" );
|
|
|
|
}).show().show( "blind", function() {
|
|
|
|
equal( ++count, 2, "Show on shown returned immediately" );
|
|
|
|
});
|
|
|
|
equal( ++count, 3, "Both Functions worked properly" );
|
|
|
|
});
|
|
|
|
|
2013-02-26 15:36:03 +00:00
|
|
|
test( ".hide() with hidden parent", function() {
|
|
|
|
expect( 1 );
|
|
|
|
var element = $( "div.hidden" ).children();
|
|
|
|
element.hide( "blind", function() {
|
|
|
|
equal( element.css( "display" ), "none", "display: none" );
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2012-10-21 21:46:38 +00:00
|
|
|
asyncTest( "Parse of null for options", function() {
|
|
|
|
var hidden = $( "div.hidden" ),
|
|
|
|
count = 0;
|
|
|
|
expect( 1 );
|
|
|
|
hidden.show( "blind", null, 1, function() {
|
|
|
|
equal( ++count, 1, "null for options still works" );
|
|
|
|
start();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-01-26 17:59:08 +00:00
|
|
|
test( "removeClass", function() {
|
|
|
|
expect( 3 );
|
|
|
|
|
|
|
|
var element = $( "<div>" );
|
|
|
|
equal( "", element[ 0 ].className );
|
|
|
|
element.addClass( "destroyed" );
|
|
|
|
equal( "destroyed", element[ 0 ].className );
|
|
|
|
element.removeClass();
|
|
|
|
equal( "", element[ 0 ].className );
|
|
|
|
});
|
|
|
|
|
2012-10-21 21:46:38 +00:00
|
|
|
|
2012-04-30 12:42:01 +00:00
|
|
|
/* TODO: Disabled - Can't figure out why this is failing in IE 6/7
|
2011-10-25 22:40:37 +00:00
|
|
|
test( "createWrapper and removeWrapper retain focused elements (#7595)", function() {
|
|
|
|
expect( 2 );
|
|
|
|
var test = $( "div.hidden" ).show(),
|
2011-11-02 17:22:58 +00:00
|
|
|
input = $( "<input type='text'>" ).appendTo( test ).focus();
|
2011-06-10 01:36:48 +00:00
|
|
|
|
2011-10-25 22:40:37 +00:00
|
|
|
$.effects.createWrapper( test );
|
|
|
|
equal( document.activeElement, input[ 0 ], "Active element is still input after createWrapper" );
|
|
|
|
$.effects.removeWrapper( test );
|
|
|
|
equal( document.activeElement, input[ 0 ], "Active element is still input after removeWrapper" );
|
2011-03-29 20:32:48 +00:00
|
|
|
});
|
2012-04-30 06:05:30 +00:00
|
|
|
*/
|
2011-10-25 22:40:37 +00:00
|
|
|
|
|
|
|
module( "effects.core: animateClass" );
|
2011-05-12 15:22:49 +00:00
|
|
|
|
|
|
|
asyncTest( "animateClass works with borderStyle", function() {
|
2012-10-23 14:36:42 +00:00
|
|
|
var test = $("div.animateClass");
|
2011-05-12 15:22:49 +00:00
|
|
|
expect(3);
|
2011-05-16 22:19:57 +00:00
|
|
|
test.toggleClass("testAddBorder", minDuration, function() {
|
|
|
|
test.toggleClass("testAddBorder", minDuration, function() {
|
2011-05-12 15:22:49 +00:00
|
|
|
equal( test.css("borderLeftStyle"), "none", "None border set" );
|
|
|
|
start();
|
|
|
|
});
|
|
|
|
equal( test.css("borderLeftStyle"), "solid", "None border not immedately set" );
|
|
|
|
});
|
|
|
|
equal( test.css("borderLeftStyle"), "solid", "Solid border immedately set" );
|
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest( "animateClass works with colors", function() {
|
|
|
|
var test = $("div.animateClass"),
|
2012-04-30 05:19:52 +00:00
|
|
|
oldStep = jQuery.fx.step.backgroundColor;
|
2012-10-23 14:36:42 +00:00
|
|
|
|
2011-05-12 15:22:49 +00:00
|
|
|
expect(2);
|
2012-04-30 05:19:52 +00:00
|
|
|
|
|
|
|
// we want to catch the first frame of animation
|
|
|
|
jQuery.fx.step.backgroundColor = function( fx ) {
|
|
|
|
oldStep.apply( this, arguments );
|
|
|
|
|
|
|
|
// make sure it has animated somewhere we can detect
|
|
|
|
if ( fx.pos > 255 / 2000 ) {
|
|
|
|
jQuery.fx.step.backgroundColor = oldStep;
|
|
|
|
notPresent( test.css("backgroundColor"),
|
|
|
|
[ "#000000", "#ffffff", "#000", "#fff", "rgb(0, 0, 0)", "rgb(255,255,255)" ],
|
|
|
|
"Color is not endpoints in middle." );
|
|
|
|
test.stop( true, true );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
test.toggleClass("testChangeBackground", {
|
|
|
|
duration: 2000,
|
|
|
|
complete: function() {
|
|
|
|
present( test.css("backgroundColor"), [ "#ffffff", "#fff", "rgb(255, 255, 255)" ], "Color is final" );
|
|
|
|
start();
|
|
|
|
}
|
2011-05-12 15:22:49 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2012-04-30 05:19:52 +00:00
|
|
|
asyncTest( "animateClass calls step option", 1, function() {
|
2012-06-25 17:05:01 +00:00
|
|
|
var test = jQuery( "div.animateClass" ),
|
2012-10-23 14:36:42 +00:00
|
|
|
step = function() {
|
2012-06-25 17:05:01 +00:00
|
|
|
ok( true, "Step Function Called" );
|
2012-04-30 05:19:52 +00:00
|
|
|
test.stop();
|
|
|
|
start();
|
2012-06-25 17:05:01 +00:00
|
|
|
step = $.noop;
|
2012-04-30 05:19:52 +00:00
|
|
|
};
|
|
|
|
test.toggleClass( "testChangeBackground", {
|
2012-06-25 17:05:01 +00:00
|
|
|
step: function() {
|
|
|
|
step();
|
2012-04-30 05:19:52 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2011-05-16 22:19:57 +00:00
|
|
|
|
2012-04-30 05:19:52 +00:00
|
|
|
asyncTest( "animateClass works with children", 3, function() {
|
|
|
|
var animatedChild,
|
|
|
|
test = $("div.animateClass"),
|
|
|
|
h2 = test.find("h2");
|
2011-05-18 23:13:37 +00:00
|
|
|
|
2012-04-30 05:19:52 +00:00
|
|
|
test.toggleClass("testChildren", {
|
|
|
|
children: true,
|
|
|
|
duration: duration,
|
|
|
|
complete: function() {
|
|
|
|
equal( h2.css("fontSize"), "20px", "Text size is final during complete");
|
|
|
|
test.toggleClass("testChildren", {
|
|
|
|
duration: duration,
|
|
|
|
complete: function() {
|
|
|
|
equal( h2.css("fontSize"), "10px", "Text size revertted after class removed");
|
|
|
|
|
|
|
|
start();
|
|
|
|
},
|
|
|
|
step: function( val, fx ) {
|
|
|
|
if ( fx.elem === h2[ 0 ] ) {
|
|
|
|
ok( false, "Error - Animating property on h2" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
step: function( val, fx ) {
|
|
|
|
if ( fx.prop === "fontSize" && fx.elem === h2[ 0 ] && !animatedChild ) {
|
|
|
|
equal( fx.end, 20, "animating font size on child" );
|
|
|
|
animatedChild = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2011-05-12 16:13:25 +00:00
|
|
|
});
|
|
|
|
|
2011-06-23 10:29:09 +00:00
|
|
|
asyncTest( "animateClass clears style properties when stopped", function() {
|
|
|
|
var test = $("div.animateClass"),
|
|
|
|
style = test[0].style,
|
|
|
|
orig = style.cssText;
|
2012-04-19 13:39:21 +00:00
|
|
|
|
2011-06-23 10:29:09 +00:00
|
|
|
expect( 2 );
|
|
|
|
|
|
|
|
test.addClass( "testChangeBackground", duration );
|
2011-09-28 14:00:25 +00:00
|
|
|
notEqual( orig, style.cssText, "cssText is not the same after starting animation" );
|
2011-06-23 10:29:09 +00:00
|
|
|
|
|
|
|
test.stop( true, true );
|
2011-09-28 14:00:25 +00:00
|
|
|
equal( orig, $.trim( style.cssText ), "cssText is the same after stopping animation midway" );
|
2011-06-23 10:29:09 +00:00
|
|
|
start();
|
|
|
|
});
|
|
|
|
|
2011-10-25 22:40:37 +00:00
|
|
|
asyncTest( "animateClass: css and class changes during animation are not lost (#7106)", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 2 );
|
2011-10-25 22:40:37 +00:00
|
|
|
var test = $( "div.ticket7106" );
|
2011-08-02 21:54:24 +00:00
|
|
|
|
2011-10-25 22:40:37 +00:00
|
|
|
// ensure the class stays and that the css property stays
|
|
|
|
function animationComplete() {
|
|
|
|
ok( test.hasClass( "testClass" ), "class change during animateClass was not lost" );
|
|
|
|
equal( test.height(), 100, "css change during animateClass was not lost" );
|
|
|
|
start();
|
|
|
|
}
|
2012-04-19 13:39:21 +00:00
|
|
|
|
|
|
|
// add a class and change a style property after starting an animated class
|
|
|
|
test.addClass( "animate", minDuration, animationComplete )
|
|
|
|
.addClass( "testClass" )
|
|
|
|
.height( 100 );
|
2011-10-25 22:40:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$.each( $.effects.effect, function( effect ) {
|
2012-04-30 00:22:31 +00:00
|
|
|
module( "effects." + effect );
|
|
|
|
|
2013-05-13 18:27:40 +00:00
|
|
|
TestHelpers.testJshint( "effect-" + effect );
|
2012-04-30 00:22:31 +00:00
|
|
|
|
2011-10-25 22:40:37 +00:00
|
|
|
if ( effect === "transfer" ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
asyncTest( "show/hide", function() {
|
|
|
|
expect( 8 );
|
2012-04-19 13:39:21 +00:00
|
|
|
var hidden = $( "div.hidden" ),
|
|
|
|
count = 0,
|
2011-10-25 22:40:37 +00:00
|
|
|
test = 0;
|
|
|
|
|
|
|
|
function queueTest( fn ) {
|
|
|
|
count++;
|
|
|
|
var point = count;
|
|
|
|
return function( next ) {
|
|
|
|
test++;
|
|
|
|
equal( point, test, "Queue function fired in order" );
|
|
|
|
if ( fn ) {
|
|
|
|
fn();
|
|
|
|
} else {
|
|
|
|
setTimeout( next, minDuration );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
hidden.queue( queueTest() ).show( effect, minDuration, queueTest(function() {
|
|
|
|
equal( hidden.css("display"), "block", "Hidden is shown after .show(\"" +effect+ "\", time)" );
|
|
|
|
})).queue( queueTest() ).hide( effect, minDuration, queueTest(function() {
|
|
|
|
equal( hidden.css("display"), "none", "Back to hidden after .hide(\"" +effect+ "\", time)" );
|
2012-10-23 14:36:42 +00:00
|
|
|
})).queue( queueTest(function() {
|
2011-10-25 22:40:37 +00:00
|
|
|
deepEqual( hidden.queue(), ["inprogress"], "Only the inprogress sentinel remains");
|
|
|
|
start();
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
asyncTest( "relative width & height - properties are preserved", function() {
|
|
|
|
var test = $("div.relWidth.relHeight"),
|
|
|
|
width = test.width(), height = test.height(),
|
|
|
|
cssWidth = test[0].style.width, cssHeight = test[0].style.height;
|
|
|
|
|
|
|
|
expect( 4 );
|
|
|
|
test.toggle( effect, minDuration, function() {
|
|
|
|
equal( test[0].style.width, cssWidth, "Inline CSS Width has been reset after animation ended" );
|
|
|
|
equal( test[0].style.height, cssHeight, "Inline CSS Height has been rest after animation ended" );
|
|
|
|
start();
|
|
|
|
});
|
|
|
|
equal( test.width(), width, "Width is the same px after animation started" );
|
|
|
|
equal( test.height(), height, "Height is the same px after animation started" );
|
|
|
|
});
|
|
|
|
});
|
2011-08-02 21:54:24 +00:00
|
|
|
|
2011-03-29 20:32:48 +00:00
|
|
|
})(jQuery);
|