3 function present( value, array, message ) {
4 QUnit.push( jQuery.inArray( value, array ) !== -1 , value, array, message );
7 function notPresent( value, array, message ) {
8 QUnit.push( jQuery.inArray( value, array ) === -1 , value, array, message );
11 // minDuration is used for "short" animate tests where we are only concerned about the final
14 // duration is used for "long" animates where we plan on testing properties during animation
17 module( "effects.core" );
19 // TODO: test all signatures of .show(), .hide(), .toggle().
20 // Look at core's signatures and UI's signatures.
21 asyncTest( ".hide() with step", function() {
23 var element = $( "#elem" ),
25 ok( true, "step callback invoked" );
37 test( "Immediate Return Conditions", function() {
38 var hidden = $( "div.hidden" ),
41 hidden.hide( "blind", function() {
42 equal( ++count, 1, "Hide on hidden returned immediately" );
43 }).show().show( "blind", function() {
44 equal( ++count, 2, "Show on shown returned immediately" );
46 equal( ++count, 3, "Both Functions worked properly" );
49 test( ".hide() with hidden parent", function() {
51 var element = $( "div.hidden" ).children();
52 element.hide( "blind", function() {
53 equal( element.css( "display" ), "none", "display: none" );
57 asyncTest( "Parse of null for options", function() {
58 var hidden = $( "div.hidden" ),
61 hidden.show( "blind", null, 1, function() {
62 equal( ++count, 1, "null for options still works" );
67 test( "removeClass", function() {
70 var element = $( "<div>" );
71 equal( "", element[ 0 ].className );
72 element.addClass( "destroyed" );
73 equal( "destroyed", element[ 0 ].className );
74 element.removeClass();
75 equal( "", element[ 0 ].className );
79 /* TODO: Disabled - Can't figure out why this is failing in IE 6/7
80 test( "createWrapper and removeWrapper retain focused elements (#7595)", function() {
82 var test = $( "div.hidden" ).show(),
83 input = $( "<input type='text'>" ).appendTo( test ).focus();
85 $.effects.createWrapper( test );
86 equal( document.activeElement, input[ 0 ], "Active element is still input after createWrapper" );
87 $.effects.removeWrapper( test );
88 equal( document.activeElement, input[ 0 ], "Active element is still input after removeWrapper" );
92 module( "effects.core: animateClass" );
94 asyncTest( "animateClass works with borderStyle", function() {
95 var test = $("div.animateClass");
97 test.toggleClass("testAddBorder", minDuration, function() {
98 test.toggleClass("testAddBorder", minDuration, function() {
99 equal( test.css("borderLeftStyle"), "none", "None border set" );
102 equal( test.css("borderLeftStyle"), "solid", "None border not immedately set" );
104 equal( test.css("borderLeftStyle"), "solid", "Solid border immedately set" );
107 asyncTest( "animateClass works with colors", function() {
108 var test = $("div.animateClass"),
109 oldStep = jQuery.fx.step.backgroundColor;
113 // we want to catch the first frame of animation
114 jQuery.fx.step.backgroundColor = function( fx ) {
115 oldStep.apply( this, arguments );
117 // make sure it has animated somewhere we can detect
118 if ( fx.pos > 255 / 2000 ) {
119 jQuery.fx.step.backgroundColor = oldStep;
120 notPresent( test.css("backgroundColor"),
121 [ "#000000", "#ffffff", "#000", "#fff", "rgb(0, 0, 0)", "rgb(255,255,255)" ],
122 "Color is not endpoints in middle." );
123 test.stop( true, true );
127 test.toggleClass("testChangeBackground", {
129 complete: function() {
130 present( test.css("backgroundColor"), [ "#ffffff", "#fff", "rgb(255, 255, 255)" ], "Color is final" );
136 asyncTest( "animateClass calls step option", 1, function() {
137 var test = jQuery( "div.animateClass" ),
139 ok( true, "Step Function Called" );
144 test.toggleClass( "testChangeBackground", {
151 asyncTest( "animateClass works with children", 3, function() {
153 test = $("div.animateClass"),
154 h2 = test.find("h2");
156 test.toggleClass("testChildren", {
159 complete: function() {
160 equal( h2.css("fontSize"), "20px", "Text size is final during complete");
161 test.toggleClass("testChildren", {
163 complete: function() {
164 equal( h2.css("fontSize"), "10px", "Text size revertted after class removed");
168 step: function( val, fx ) {
169 if ( fx.elem === h2[ 0 ] ) {
170 ok( false, "Error - Animating property on h2" );
175 step: function( val, fx ) {
176 if ( fx.prop === "fontSize" && fx.elem === h2[ 0 ] && !animatedChild ) {
177 equal( fx.end, 20, "animating font size on child" );
178 animatedChild = true;
184 asyncTest( "animateClass clears style properties when stopped", function() {
185 var test = $("div.animateClass"),
186 style = test[0].style,
187 orig = style.cssText;
191 test.addClass( "testChangeBackground", duration );
192 notEqual( orig, style.cssText, "cssText is not the same after starting animation" );
194 test.stop( true, true );
195 equal( orig, $.trim( style.cssText ), "cssText is the same after stopping animation midway" );
199 asyncTest( "animateClass: css and class changes during animation are not lost (#7106)", function() {
201 var test = $( "div.ticket7106" );
203 // ensure the class stays and that the css property stays
204 function animationComplete() {
205 ok( test.hasClass( "testClass" ), "class change during animateClass was not lost" );
206 equal( test.height(), 100, "css change during animateClass was not lost" );
210 // add a class and change a style property after starting an animated class
211 test.addClass( "animate", minDuration, animationComplete )
212 .addClass( "testClass" )
217 $.each( $.effects.effect, function( effect ) {
218 module( "effects." + effect );
220 // puff and size are defined inside scale
221 if ( effect !== "puff" && effect !== "size" ) {
222 TestHelpers.testJshint( "effect-" + effect );
225 if ( effect === "transfer" ) {
228 asyncTest( "show/hide", function() {
230 var hidden = $( "div.hidden" ),
234 function queueTest( fn ) {
237 return function( next ) {
239 equal( point, test, "Queue function fired in order" );
243 setTimeout( next, minDuration );
248 hidden.queue( queueTest() ).show( effect, minDuration, queueTest(function() {
249 equal( hidden.css("display"), "block", "Hidden is shown after .show(\"" +effect+ "\", time)" );
250 })).queue( queueTest() ).hide( effect, minDuration, queueTest(function() {
251 equal( hidden.css("display"), "none", "Back to hidden after .hide(\"" +effect+ "\", time)" );
252 })).queue( queueTest(function() {
253 deepEqual( hidden.queue(), ["inprogress"], "Only the inprogress sentinel remains");
258 asyncTest( "relative width & height - properties are preserved", function() {
259 var test = $("div.relWidth.relHeight"),
260 width = test.width(), height = test.height(),
261 cssWidth = test[0].style.width, cssHeight = test[0].style.height;
264 test.toggle( effect, minDuration, function() {
265 equal( test[0].style.width, cssWidth, "Inline CSS Width has been reset after animation ended" );
266 equal( test[0].style.height, cssHeight, "Inline CSS Height has been rest after animation ended" );
269 equal( test.width(), width, "Width is the same px after animation started" );
270 equal( test.height(), height, "Height is the same px after animation started" );