jquery-ui/tests/unit/widget/animation.js

264 lines
5.1 KiB
JavaScript
Raw Normal View History

define( [
"jquery",
"ui/widget"
], function( $ ) {
2015-08-24 13:32:13 +00:00
module( "widget animation", ( function() {
var show = $.fn.show,
fadeIn = $.fn.fadeIn,
slideDown = $.fn.slideDown;
return {
setup: function() {
$.widget( "ui.testWidget", {
_create: function() {
this.element.hide();
},
show: function( fn ) {
this._show( this.element, this.options.show, fn );
}
2015-08-24 13:32:13 +00:00
} );
$.effects = { effect: { testEffect: $.noop } };
},
teardown: function() {
delete $.ui.testWidget;
delete $.effects.effect.testEffect;
$.fn.show = show;
$.fn.fadeIn = fadeIn;
$.fn.slideDown = slideDown;
}
};
2015-08-24 13:32:13 +00:00
}() ) );
asyncTest( "show: null", function() {
expect( 4 );
var element = $( "#widget" ).testWidget(),
hasRun = false;
$.fn.show = function() {
ok( true, "show called" );
equal( arguments.length, 0, "no args passed to show" );
};
element
.delay( 50 )
2015-08-24 13:32:13 +00:00
.queue( function( next ) {
ok( !hasRun, "queue before show" );
next();
2015-08-24 13:32:13 +00:00
} )
.testWidget( "show", function() {
hasRun = true;
2015-08-24 13:32:13 +00:00
} )
.queue( function( next ) {
ok( hasRun, "queue after show" );
start();
next();
2015-08-24 13:32:13 +00:00
} );
} );
asyncTest( "show: true", function() {
expect( 4 );
2015-08-24 13:32:13 +00:00
var element = $( "#widget" ).testWidget( {
show: true
2015-08-24 13:32:13 +00:00
} ),
hasRun = false;
$.fn.fadeIn = function( duration, easing, complete ) {
2015-08-24 13:32:13 +00:00
return this.queue( function( next ) {
strictEqual( duration, undefined, "duration" );
strictEqual( easing, undefined, "easing" );
complete();
next();
2015-08-24 13:32:13 +00:00
} );
};
element
.delay( 50 )
2015-08-24 13:32:13 +00:00
.queue( function( next ) {
ok( !hasRun, "queue before show" );
next();
2015-08-24 13:32:13 +00:00
} )
.testWidget( "show", function() {
hasRun = true;
2015-08-24 13:32:13 +00:00
} )
.queue( function( next ) {
ok( hasRun, "queue after show" );
start();
next();
2015-08-24 13:32:13 +00:00
} );
} );
asyncTest( "show: number", function() {
expect( 4 );
2015-08-24 13:32:13 +00:00
var element = $( "#widget" ).testWidget( {
show: 123
2015-08-24 13:32:13 +00:00
} ),
hasRun = false;
$.fn.fadeIn = function( duration, easing, complete ) {
2015-08-24 13:32:13 +00:00
return this.queue( function( next ) {
strictEqual( duration, 123, "duration" );
strictEqual( easing, undefined, "easing" );
complete();
next();
2015-08-24 13:32:13 +00:00
} );
};
element
.delay( 50 )
2015-08-24 13:32:13 +00:00
.queue( function( next ) {
ok( !hasRun, "queue before show" );
next();
2015-08-24 13:32:13 +00:00
} )
.testWidget( "show", function() {
hasRun = true;
2015-08-24 13:32:13 +00:00
} )
.queue( function( next ) {
ok( hasRun, "queue after show" );
start();
next();
2015-08-24 13:32:13 +00:00
} );
} );
asyncTest( "show: core animation", function() {
expect( 4 );
2015-08-24 13:32:13 +00:00
var element = $( "#widget" ).testWidget( {
show: "slideDown"
2015-08-24 13:32:13 +00:00
} ),
hasRun = false;
$.fn.slideDown = function( duration, easing, complete ) {
2015-08-24 13:32:13 +00:00
return this.queue( function( next ) {
strictEqual( duration, undefined, "duration" );
strictEqual( easing, undefined, "easing" );
complete();
next();
2015-08-24 13:32:13 +00:00
} );
};
element
.delay( 50 )
2015-08-24 13:32:13 +00:00
.queue( function( next ) {
ok( !hasRun, "queue before show" );
next();
2015-08-24 13:32:13 +00:00
} )
.testWidget( "show", function() {
hasRun = true;
2015-08-24 13:32:13 +00:00
} )
.queue( function( next ) {
ok( hasRun, "queue after show" );
start();
next();
2015-08-24 13:32:13 +00:00
} );
} );
asyncTest( "show: effect", function() {
expect( 5 );
2015-08-24 13:32:13 +00:00
var element = $( "#widget" ).testWidget( {
show: "testEffect"
2015-08-24 13:32:13 +00:00
} ),
hasRun = false;
$.fn.show = function( options ) {
2015-08-24 13:32:13 +00:00
return this.queue( function( next ) {
equal( options.effect, "testEffect", "effect" );
2015-08-24 13:32:13 +00:00
ok( !( "duration" in options ), "duration" );
ok( !( "easing" in options ), "easing" );
options.complete();
next();
2015-08-24 13:32:13 +00:00
} );
};
element
.delay( 50 )
2015-08-24 13:32:13 +00:00
.queue( function( next ) {
ok( !hasRun, "queue before show" );
next();
2015-08-24 13:32:13 +00:00
} )
.testWidget( "show", function() {
hasRun = true;
2015-08-24 13:32:13 +00:00
} )
.queue( function( next ) {
ok( hasRun, "queue after show" );
start();
next();
2015-08-24 13:32:13 +00:00
} );
} );
asyncTest( "show: object(core animation)", function() {
expect( 4 );
2015-08-24 13:32:13 +00:00
var element = $( "#widget" ).testWidget( {
show: {
effect: "slideDown",
duration: 123,
easing: "testEasing"
}
2015-08-24 13:32:13 +00:00
} ),
hasRun = false;
$.fn.slideDown = function( duration, easing, complete ) {
2015-08-24 13:32:13 +00:00
return this.queue( function( next ) {
equal( duration, 123, "duration" );
equal( easing, "testEasing", "easing" );
complete();
next();
2015-08-24 13:32:13 +00:00
} );
};
element
.delay( 50 )
2015-08-24 13:32:13 +00:00
.queue( function( next ) {
ok( !hasRun, "queue before show" );
next();
2015-08-24 13:32:13 +00:00
} )
.testWidget( "show", function() {
hasRun = true;
2015-08-24 13:32:13 +00:00
} )
.queue( function( next ) {
ok( hasRun, "queue after show" );
start();
next();
2015-08-24 13:32:13 +00:00
} );
} );
asyncTest( "show: object(effect)", function() {
expect( 3 );
2015-08-24 13:32:13 +00:00
var element = $( "#widget" ).testWidget( {
show: {
effect: "testEffect",
duration: 123,
easing: "testEasing"
}
2015-08-24 13:32:13 +00:00
} ),
hasRun = false;
$.fn.show = function( options ) {
2015-08-24 13:32:13 +00:00
return this.queue( function( next ) {
deepEqual( options, {
effect: "testEffect",
duration: 123,
easing: "testEasing",
complete: options.complete
2015-08-24 13:32:13 +00:00
} );
options.complete();
next();
2015-08-24 13:32:13 +00:00
} );
};
element
.delay( 50 )
2015-08-24 13:32:13 +00:00
.queue( function( next ) {
ok( !hasRun, "queue before show" );
next();
2015-08-24 13:32:13 +00:00
} )
.testWidget( "show", function() {
hasRun = true;
2015-08-24 13:32:13 +00:00
} )
.queue( function( next ) {
ok( hasRun, "queue after show" );
start();
next();
2015-08-24 13:32:13 +00:00
} );
} );
} );