| 1 |
define( [ |
| 2 |
"qunit", |
| 3 |
"jquery", |
| 4 |
"lib/common", |
| 5 |
"lib/helper", |
| 6 |
"ui/effect", |
| 7 |
"ui/effects/effect-blind", |
| 8 |
"ui/effects/effect-bounce", |
| 9 |
"ui/effects/effect-clip", |
| 10 |
"ui/effects/effect-drop", |
| 11 |
"ui/effects/effect-explode", |
| 12 |
"ui/effects/effect-fade", |
| 13 |
"ui/effects/effect-fold", |
| 14 |
"ui/effects/effect-highlight", |
| 15 |
"ui/effects/effect-puff", |
| 16 |
"ui/effects/effect-pulsate", |
| 17 |
"ui/effects/effect-scale", |
| 18 |
"ui/effects/effect-shake", |
| 19 |
"ui/effects/effect-size", |
| 20 |
"ui/effects/effect-slide", |
| 21 |
"ui/effects/effect-transfer" |
| 22 |
], function( QUnit, $, common, helper ) { |
| 23 |
"use strict"; |
| 24 |
|
| 25 |
QUnit.assert.present = function( value, array, message ) { |
| 26 |
this.pushResult( { |
| 27 |
result: jQuery.inArray( value, array ) !== -1, |
| 28 |
actual: value, |
| 29 |
expected: array, |
| 30 |
message: message |
| 31 |
} ); |
| 32 |
}; |
| 33 |
|
| 34 |
QUnit.assert.notPresent = function( value, array, message ) { |
| 35 |
this.pushResult( { |
| 36 |
result: jQuery.inArray( value, array ) === -1, |
| 37 |
actual: value, |
| 38 |
expected: array, |
| 39 |
message: message |
| 40 |
} ); |
| 41 |
}; |
| 42 |
|
| 43 |
|
| 44 |
var minDuration = 60, |
| 45 |
|
| 46 |
|
| 47 |
duration = 200; |
| 48 |
|
| 49 |
QUnit.module( "effects.core", { afterEach: helper.moduleAfterEach } ); |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
QUnit.test( ".hide() with step", function( assert ) { |
| 54 |
var ready = assert.async(); |
| 55 |
assert.expect( 1 ); |
| 56 |
var element = $( "#elem" ), |
| 57 |
step = function() { |
| 58 |
assert.ok( true, "step callback invoked" ); |
| 59 |
step = $.noop; |
| 60 |
}; |
| 61 |
|
| 62 |
element.hide( { |
| 63 |
step: function() { |
| 64 |
step(); |
| 65 |
}, |
| 66 |
complete: ready |
| 67 |
} ); |
| 68 |
} ); |
| 69 |
|
| 70 |
QUnit.test( "Immediate Return Conditions", function( assert ) { |
| 71 |
var hidden = $( "div.hidden" ), |
| 72 |
count = 0; |
| 73 |
assert.expect( 3 ); |
| 74 |
hidden.hide( "blind", function() { |
| 75 |
assert.equal( ++count, 1, "Hide on hidden returned immediately" ); |
| 76 |
} ).show().show( "blind", function() { |
| 77 |
assert.equal( ++count, 2, "Show on shown returned immediately" ); |
| 78 |
} ); |
| 79 |
assert.equal( ++count, 3, "Both Functions worked properly" ); |
| 80 |
} ); |
| 81 |
|
| 82 |
QUnit.test( ".hide() with hidden parent", function( assert ) { |
| 83 |
assert.expect( 1 ); |
| 84 |
var element = $( "div.hidden" ).children(); |
| 85 |
element.hide( "blind", function() { |
| 86 |
assert.equal( element.css( "display" ), "none", "display: none" ); |
| 87 |
} ); |
| 88 |
} ); |
| 89 |
|
| 90 |
QUnit.test( "Parse of null for options", function( assert ) { |
| 91 |
var ready = assert.async(); |
| 92 |
var hidden = $( "div.hidden" ), |
| 93 |
count = 0; |
| 94 |
assert.expect( 1 ); |
| 95 |
hidden.show( "blind", null, 1, function() { |
| 96 |
assert.equal( ++count, 1, "null for options still works" ); |
| 97 |
ready(); |
| 98 |
} ); |
| 99 |
} ); |
| 100 |
|
| 101 |
QUnit.test( "removeClass", function( assert ) { |
| 102 |
assert.expect( 3 ); |
| 103 |
|
| 104 |
var element = $( "<div>" ); |
| 105 |
assert.equal( "", element[ 0 ].className ); |
| 106 |
element.addClass( "destroyed" ); |
| 107 |
assert.equal( "destroyed", element[ 0 ].className ); |
| 108 |
element.removeClass(); |
| 109 |
assert.equal( "", element[ 0 ].className ); |
| 110 |
} ); |
| 111 |
|
| 112 |
QUnit.module( "effects.core: animateClass", { afterEach: helper.moduleAfterEach } ); |
| 113 |
|
| 114 |
QUnit.test( "animateClass works with borderStyle", function( assert ) { |
| 115 |
var ready = assert.async(); |
| 116 |
var test = $( "div.animateClass" ); |
| 117 |
assert.expect( 3 ); |
| 118 |
test.toggleClass( "testAddBorder", minDuration, function() { |
| 119 |
test.toggleClass( "testAddBorder", minDuration, function() { |
| 120 |
assert.equal( test.css( "borderLeftStyle" ), "none", "None border set" ); |
| 121 |
ready(); |
| 122 |
} ); |
| 123 |
assert.equal( test.css( "borderLeftStyle" ), "solid", "None border not immedately set" ); |
| 124 |
} ); |
| 125 |
assert.equal( test.css( "borderLeftStyle" ), "solid", "Solid border immedately set" ); |
| 126 |
} ); |
| 127 |
|
| 128 |
QUnit.test( "animateClass works with colors", function( assert ) { |
| 129 |
var ready = assert.async(); |
| 130 |
var test = $( "div.animateClass" ), |
| 131 |
oldStep = jQuery.fx.step.backgroundColor; |
| 132 |
|
| 133 |
assert.expect( 2 ); |
| 134 |
|
| 135 |
|
| 136 |
jQuery.fx.step.backgroundColor = function( fx ) { |
| 137 |
oldStep.apply( this, arguments ); |
| 138 |
|
| 139 |
|
| 140 |
if ( fx.pos > 255 / 2000 ) { |
| 141 |
jQuery.fx.step.backgroundColor = oldStep; |
| 142 |
assert.notPresent( test.css( "backgroundColor" ), |
| 143 |
[ "#000000", "#ffffff", "#000", "#fff", "rgb(0, 0, 0)", "rgb(255,255,255)" ], |
| 144 |
"Color is not endpoints in middle." ); |
| 145 |
test.stop( true, true ); |
| 146 |
} |
| 147 |
}; |
| 148 |
|
| 149 |
test.toggleClass( "testChangeBackground", { |
| 150 |
duration: 2000, |
| 151 |
complete: function() { |
| 152 |
assert.present( test.css( "backgroundColor" ), [ "#ffffff", "#fff", "rgb(255, 255, 255)" ], "Color is final" ); |
| 153 |
ready(); |
| 154 |
} |
| 155 |
} ); |
| 156 |
} ); |
| 157 |
|
| 158 |
QUnit.test( "animateClass calls step option", function( assert ) { |
| 159 |
assert.expect( 1 ); |
| 160 |
var test = jQuery( "div.animateClass" ), |
| 161 |
step = function() { |
| 162 |
assert.ok( true, "Step Function Called" ); |
| 163 |
step = $.noop; |
| 164 |
}; |
| 165 |
test.toggleClass( "testChangeBackground", { |
| 166 |
step: function() { |
| 167 |
step(); |
| 168 |
} |
| 169 |
} ); |
| 170 |
|
| 171 |
test.stop( true, true ); |
| 172 |
} ); |
| 173 |
|
| 174 |
QUnit.test( "animateClass works with children", function( assert ) { |
| 175 |
assert.expect( 3 ); |
| 176 |
var ready = assert.async(); |
| 177 |
var animatedChild, |
| 178 |
test = $( "div.animateClass" ), |
| 179 |
h2 = test.find( "h2" ); |
| 180 |
|
| 181 |
test.toggleClass( "testChildren", { |
| 182 |
children: true, |
| 183 |
duration: duration, |
| 184 |
complete: function() { |
| 185 |
assert.equal( h2.css( "fontSize" ), "20px", "Text size is final during complete" ); |
| 186 |
test.toggleClass( "testChildren", { |
| 187 |
duration: duration, |
| 188 |
complete: function() { |
| 189 |
assert.equal( h2.css( "fontSize" ), "10px", "Text size revertted after class removed" ); |
| 190 |
|
| 191 |
ready(); |
| 192 |
}, |
| 193 |
step: function( val, fx ) { |
| 194 |
if ( fx.elem === h2[ 0 ] ) { |
| 195 |
assert.ok( false, "Error - Animating property on h2" ); |
| 196 |
} |
| 197 |
} |
| 198 |
} ); |
| 199 |
}, |
| 200 |
step: function( val, fx ) { |
| 201 |
if ( fx.prop === "fontSize" && fx.elem === h2[ 0 ] && !animatedChild ) { |
| 202 |
assert.equal( fx.end, 20, "animating font size on child" ); |
| 203 |
animatedChild = true; |
| 204 |
} |
| 205 |
} |
| 206 |
} ); |
| 207 |
} ); |
| 208 |
|
| 209 |
QUnit.test( "animateClass clears style properties when stopped", function( assert ) { |
| 210 |
var ready = assert.async(); |
| 211 |
var test = $( "div.animateClass" ), |
| 212 |
style = test[ 0 ].style, |
| 213 |
orig = style.cssText; |
| 214 |
|
| 215 |
assert.expect( 2 ); |
| 216 |
|
| 217 |
test.addClass( "testChangeBackground", duration ); |
| 218 |
assert.notEqual( orig, style.cssText, "cssText is not the same after starting animation" ); |
| 219 |
|
| 220 |
test |
| 221 |
.stop( true, true ) |
| 222 |
.promise() |
| 223 |
.then( function() { |
| 224 |
assert.equal( orig, String.prototype.trim.call( style.cssText ), "cssText is the same after stopping animation midway" ); |
| 225 |
ready(); |
| 226 |
} ); |
| 227 |
} ); |
| 228 |
|
| 229 |
QUnit.test( "animateClass: css and class changes during animation are not lost (#7106)", |
| 230 |
function( assert ) { |
| 231 |
var ready = assert.async(); |
| 232 |
assert.expect( 2 ); |
| 233 |
var test = $( "div.ticket7106" ); |
| 234 |
|
| 235 |
|
| 236 |
function animationComplete() { |
| 237 |
assert.hasClasses( test, "testClass", "class change during animateClass was not lost" ); |
| 238 |
assert.equal( test.height(), 100, "css change during animateClass was not lost" ); |
| 239 |
ready(); |
| 240 |
} |
| 241 |
|
| 242 |
|
| 243 |
test.addClass( "animate", minDuration, animationComplete ) |
| 244 |
.addClass( "testClass" ) |
| 245 |
.height( 100 ); |
| 246 |
} ); |
| 247 |
|
| 248 |
QUnit.test( "createPlaceholder: only created for static or relative elements", function( assert ) { |
| 249 |
assert.expect( 4 ); |
| 250 |
|
| 251 |
assert.ok( $.effects.createPlaceholder( $( ".relative" ) ).length, "placeholder created for relative element" ); |
| 252 |
assert.ok( $.effects.createPlaceholder( $( ".static" ) ).length, "placeholder created for static element" ); |
| 253 |
assert.ok( !$.effects.createPlaceholder( $( ".absolute" ) ), "placeholder not created for absolute element" ); |
| 254 |
assert.ok( !$.effects.createPlaceholder( $( ".fixed" ) ), "placeholder not created for fixed element" ); |
| 255 |
} ); |
| 256 |
|
| 257 |
QUnit.test( "createPlaceholder: preserves layout affecting properties", function( assert ) { |
| 258 |
assert.expect( 7 ); |
| 259 |
|
| 260 |
var position = 5, |
| 261 |
element = $( ".relative" ).css( { |
| 262 |
top: position, |
| 263 |
left: position |
| 264 |
} ), |
| 265 |
before = { |
| 266 |
offset: element.offset(), |
| 267 |
outerWidth: element.outerWidth( true ), |
| 268 |
outerHeight: element.outerHeight( true ), |
| 269 |
"float": element.css( "float" ), |
| 270 |
position: element.position() |
| 271 |
}, |
| 272 |
placeholder = $.effects.createPlaceholder( element ); |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
assert.deepEqual( before.offset.top - position, placeholder.offset().top, "offset top preserved" ); |
| 278 |
assert.deepEqual( before.offset.left - position, placeholder.offset().left, "offset left preserved" ); |
| 279 |
assert.deepEqual( before.position.top - position, placeholder.position().top, "position top preserved" ); |
| 280 |
assert.deepEqual( before.position.left - position, placeholder.position().left, "position left preserved" ); |
| 281 |
|
| 282 |
assert.deepEqual( before.float, placeholder.css( "float" ), "float preserved" ); |
| 283 |
assert.deepEqual( before.outerWidth, placeholder.outerWidth( true ), "width preserved" ); |
| 284 |
assert.deepEqual( before.outerHeight, placeholder.outerHeight( true ), "height preserved" ); |
| 285 |
} ); |
| 286 |
|
| 287 |
QUnit.module( "transfer", { afterEach: helper.moduleAfterEach } ); |
| 288 |
|
| 289 |
QUnit.test( "transfer() without callback", function( assert ) { |
| 290 |
var ready = assert.async(); |
| 291 |
assert.expect( 0 ); |
| 292 |
|
| 293 |
|
| 294 |
$( "#elem" ).transfer( { |
| 295 |
to: ".animateClass", |
| 296 |
duration: 1 |
| 297 |
} ); |
| 298 |
setTimeout( function() { |
| 299 |
ready(); |
| 300 |
}, 25 ); |
| 301 |
} ); |
| 302 |
|
| 303 |
QUnit.test( "transfer() with callback", function( assert ) { |
| 304 |
var ready = assert.async(); |
| 305 |
assert.expect( 1 ); |
| 306 |
$( "#elem" ).transfer( { |
| 307 |
to: ".animateClass", |
| 308 |
duration: 1 |
| 309 |
}, function() { |
| 310 |
assert.ok( true, "callback invoked" ); |
| 311 |
ready(); |
| 312 |
} ); |
| 313 |
} ); |
| 314 |
|
| 315 |
$.each( $.effects.effect, function( effect ) { |
| 316 |
QUnit.module( "effects." + effect ); |
| 317 |
|
| 318 |
if ( effect === "transfer" ) { |
| 319 |
return; |
| 320 |
} |
| 321 |
QUnit.test( "show/hide", function( assert ) { |
| 322 |
var ready = assert.async(); |
| 323 |
assert.expect( 12 ); |
| 324 |
var hidden = $( "div.hidden" ), |
| 325 |
count = 0, |
| 326 |
test = 0; |
| 327 |
|
| 328 |
function queueTest( fn ) { |
| 329 |
count++; |
| 330 |
var point = count; |
| 331 |
return function( next ) { |
| 332 |
test++; |
| 333 |
assert.equal( point, test, "Queue function fired in order" ); |
| 334 |
if ( fn ) { |
| 335 |
fn(); |
| 336 |
} else { |
| 337 |
setTimeout( next, minDuration ); |
| 338 |
} |
| 339 |
}; |
| 340 |
} |
| 341 |
|
| 342 |
function duringTest( fn ) { |
| 343 |
return function( next ) { |
| 344 |
setTimeout( fn, minDuration / 2 ); |
| 345 |
next(); |
| 346 |
}; |
| 347 |
} |
| 348 |
|
| 349 |
hidden |
| 350 |
.queue( queueTest() ) |
| 351 |
.queue( duringTest( function() { |
| 352 |
assert.ok( hidden.is( ":animated" ), |
| 353 |
"Hidden is seen as animated during .show(\"" + effect + "\", time)" ); |
| 354 |
} ) ) |
| 355 |
.show( effect, minDuration, queueTest( function() { |
| 356 |
assert.equal( hidden.css( "display" ), "block", |
| 357 |
"Hidden is shown after .show(\"" + effect + "\", time)" ); |
| 358 |
assert.ok( !$( ".ui-effects-placeholder" ).length, |
| 359 |
"No placeholder remains after .show(\"" + effect + "\", time)" ); |
| 360 |
} ) ) |
| 361 |
.queue( queueTest() ) |
| 362 |
.queue( duringTest( function() { |
| 363 |
assert.ok( hidden.is( ":animated" ), |
| 364 |
"Hidden is seen as animated during .hide(\"" + effect + "\", time)" ); |
| 365 |
} ) ) |
| 366 |
.hide( effect, minDuration, queueTest( function() { |
| 367 |
assert.equal( hidden.css( "display" ), "none", |
| 368 |
"Back to hidden after .hide(\"" + effect + "\", time)" ); |
| 369 |
assert.ok( !$( ".ui-effects-placeholder" ).length, |
| 370 |
"No placeholder remains after .hide(\"" + effect + "\", time)" ); |
| 371 |
} ) ) |
| 372 |
.queue( queueTest( function() { |
| 373 |
assert.deepEqual( hidden.queue(), [ "inprogress" ], "Only the inprogress sentinel remains" ); |
| 374 |
ready(); |
| 375 |
} ) ); |
| 376 |
} ); |
| 377 |
|
| 378 |
QUnit.test( "relative width & height - properties are preserved", function( assert ) { |
| 379 |
var ready = assert.async(); |
| 380 |
var test = $( "div.relWidth.relHeight" ), |
| 381 |
width = test.width(), height = test.height(), |
| 382 |
cssWidth = test[ 0 ].style.width, cssHeight = test[ 0 ].style.height; |
| 383 |
|
| 384 |
assert.expect( 4 ); |
| 385 |
test.toggle( effect, minDuration, function() { |
| 386 |
assert.equal( test[ 0 ].style.width, cssWidth, "Inline CSS Width has been reset after animation ended" ); |
| 387 |
assert.equal( test[ 0 ].style.height, cssHeight, "Inline CSS Height has been rest after animation ended" ); |
| 388 |
ready(); |
| 389 |
} ); |
| 390 |
assert.ok( Math.abs( test.width() - width ) / width < 0.05, |
| 391 |
"Width is close to the value when animation started" ); |
| 392 |
assert.ok( Math.abs( test.height() - height ) / height < 0.05, |
| 393 |
"Height is close to the value when animation started" ); |
| 394 |
} ); |
| 395 |
} ); |
| 396 |
|
| 397 |
} ); |