2015-09-02 23:52:01 +00:00
|
|
|
module( "queue", { teardown: moduleTeardown } );
|
2009-12-06 22:19:33 +00:00
|
|
|
|
2015-07-30 17:48:26 +00:00
|
|
|
test( "queue() with other types", function() {
|
|
|
|
expect( 14 );
|
|
|
|
|
2011-04-11 11:40:14 +00:00
|
|
|
stop();
|
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
var $div = jQuery( {} ),
|
2013-04-09 15:45:09 +00:00
|
|
|
counter = 0;
|
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
$div.promise( "foo" ).done( function() {
|
2011-11-06 20:27:42 +00:00
|
|
|
equal( counter, 0, "Deferred for collection with no queue is automatically resolved" );
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2009-12-06 22:19:33 +00:00
|
|
|
$div
|
2015-09-02 23:52:01 +00:00
|
|
|
.queue( "foo", function() {
|
2011-11-06 20:27:42 +00:00
|
|
|
equal( ++counter, 1, "Dequeuing" );
|
2015-09-02 23:52:01 +00:00
|
|
|
jQuery.dequeue( this, "foo" );
|
|
|
|
} )
|
|
|
|
.queue( "foo", function() {
|
2011-11-06 20:27:42 +00:00
|
|
|
equal( ++counter, 2, "Dequeuing" );
|
2015-09-02 23:52:01 +00:00
|
|
|
jQuery( this ).dequeue( "foo" );
|
|
|
|
} )
|
|
|
|
.queue( "foo", function() {
|
2011-11-06 20:27:42 +00:00
|
|
|
equal( ++counter, 3, "Dequeuing" );
|
2015-09-02 23:52:01 +00:00
|
|
|
} )
|
|
|
|
.queue( "foo", function() {
|
2011-11-06 20:27:42 +00:00
|
|
|
equal( ++counter, 4, "Dequeuing" );
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
$div.promise( "foo" ).done( function() {
|
2012-05-23 03:04:45 +00:00
|
|
|
equal( counter, 4, "Testing previous call to dequeue in deferred" );
|
2011-04-11 11:40:14 +00:00
|
|
|
start();
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2011-04-11 11:40:14 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
equal( $div.queue( "foo" ).length, 4, "Testing queue length" );
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
equal( $div.queue( "foo", undefined ).queue( "foo" ).length, 4, ".queue('name',undefined) does nothing but is chainable (#5571)" );
|
2011-12-06 20:25:38 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
$div.dequeue( "foo" );
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2011-11-06 20:27:42 +00:00
|
|
|
equal( counter, 3, "Testing previous call to dequeue" );
|
2015-09-02 23:52:01 +00:00
|
|
|
equal( $div.queue( "foo" ).length, 1, "Testing queue length" );
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
$div.dequeue( "foo" );
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2011-11-06 20:27:42 +00:00
|
|
|
equal( counter, 4, "Testing previous call to dequeue" );
|
2015-09-02 23:52:01 +00:00
|
|
|
equal( $div.queue( "foo" ).length, 0, "Testing queue length" );
|
2012-08-13 17:43:49 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
$div.dequeue( "foo" );
|
2012-08-13 17:43:49 +00:00
|
|
|
|
|
|
|
equal( counter, 4, "Testing previous call to dequeue" );
|
2015-09-02 23:52:01 +00:00
|
|
|
equal( $div.queue( "foo" ).length, 0, "Testing queue length" );
|
2012-08-13 17:43:49 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2009-12-06 22:19:33 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
test( "queue(name) passes in the next item in the queue as a parameter", function() {
|
|
|
|
expect( 2 );
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
var div = jQuery( {} ),
|
2013-04-09 15:45:09 +00:00
|
|
|
counter = 0;
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
div.queue( "foo", function( next ) {
|
|
|
|
equal( ++counter, 1, "Dequeueing" );
|
2009-12-06 22:19:33 +00:00
|
|
|
next();
|
2015-09-02 23:52:01 +00:00
|
|
|
} ).queue( "foo", function( next ) {
|
|
|
|
equal( ++counter, 2, "Next was called" );
|
2009-12-06 22:19:33 +00:00
|
|
|
next();
|
2015-09-02 23:52:01 +00:00
|
|
|
} ).queue( "bar", function() {
|
|
|
|
equal( ++counter, 3, "Other queues are not triggered by next()" );
|
|
|
|
} );
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
div.dequeue( "foo" );
|
|
|
|
} );
|
2009-12-06 22:19:33 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
test( "queue() passes in the next item in the queue as a parameter to fx queues", function() {
|
|
|
|
expect( 3 );
|
2009-12-06 22:19:33 +00:00
|
|
|
stop();
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
var div = jQuery( {} ),
|
2013-04-09 15:45:09 +00:00
|
|
|
counter = 0;
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
div.queue( function( next ) {
|
|
|
|
equal( ++counter, 1, "Dequeueing" );
|
|
|
|
setTimeout( function() { next(); }, 500 );
|
|
|
|
} ).queue( function( next ) {
|
|
|
|
equal( ++counter, 2, "Next was called" );
|
2009-12-06 22:19:33 +00:00
|
|
|
next();
|
2015-09-02 23:52:01 +00:00
|
|
|
} ).queue( "bar", function() {
|
|
|
|
equal( ++counter, 3, "Other queues are not triggered by next()" );
|
|
|
|
} );
|
2009-12-06 22:19:33 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
jQuery.when( div.promise( "fx" ), div ).done( function() {
|
|
|
|
equal( counter, 2, "Deferreds resolved" );
|
2011-04-11 11:40:14 +00:00
|
|
|
start();
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
|
|
|
} );
|
2011-05-11 18:31:42 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
test( "callbacks keep their place in the queue", function() {
|
|
|
|
expect( 5 );
|
2011-05-11 18:31:42 +00:00
|
|
|
stop();
|
2015-09-02 23:52:01 +00:00
|
|
|
var div = jQuery( "<div>" ),
|
2011-05-11 18:31:42 +00:00
|
|
|
counter = 0;
|
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
div.queue( function( next ) {
|
2011-05-11 18:31:42 +00:00
|
|
|
equal( ++counter, 1, "Queue/callback order: first called" );
|
|
|
|
setTimeout( next, 200 );
|
2015-09-02 23:52:01 +00:00
|
|
|
} ).delay( 100 ).queue( function( next ) {
|
2011-05-11 18:31:42 +00:00
|
|
|
equal( ++counter, 2, "Queue/callback order: second called" );
|
2015-09-02 23:52:01 +00:00
|
|
|
jQuery( this ).delay( 100 ).queue( function( next ) {
|
2011-05-11 18:31:42 +00:00
|
|
|
equal( ++counter, 4, "Queue/callback order: fourth called" );
|
2012-05-29 02:25:04 +00:00
|
|
|
next();
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2012-05-29 02:25:04 +00:00
|
|
|
next();
|
2015-09-02 23:52:01 +00:00
|
|
|
} ).queue( function( next ) {
|
2011-05-11 18:31:42 +00:00
|
|
|
equal( ++counter, 3, "Queue/callback order: third called" );
|
|
|
|
next();
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2011-04-11 11:40:14 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
div.promise( "fx" ).done( function() {
|
|
|
|
equal( counter, 4, "Deferreds resolved" );
|
2011-05-11 18:31:42 +00:00
|
|
|
start();
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
|
|
|
} );
|
2009-12-06 22:19:33 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
test( "delay()", function() {
|
|
|
|
expect( 2 );
|
2009-12-06 22:19:33 +00:00
|
|
|
stop();
|
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
var foo = jQuery( {} ), run = 0;
|
2009-12-06 22:19:33 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
foo.delay( 100 ).queue( function() {
|
2009-12-06 22:19:33 +00:00
|
|
|
run = 1;
|
|
|
|
ok( true, "The function was dequeued." );
|
|
|
|
start();
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2009-12-06 22:19:33 +00:00
|
|
|
|
2011-11-06 20:27:42 +00:00
|
|
|
equal( run, 0, "The delay delayed the next function from running." );
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2009-12-06 22:19:33 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
test( "clearQueue(name) clears the queue", function() {
|
|
|
|
expect( 2 );
|
2011-04-11 11:40:14 +00:00
|
|
|
|
2012-06-21 19:30:24 +00:00
|
|
|
stop();
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
var div = jQuery( {} ),
|
2013-04-09 15:45:09 +00:00
|
|
|
counter = 0;
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
div.queue( "foo", function( next ) {
|
2009-12-06 22:19:33 +00:00
|
|
|
counter++;
|
2015-09-02 23:52:01 +00:00
|
|
|
jQuery( this ).clearQueue( "foo" );
|
2009-12-06 22:19:33 +00:00
|
|
|
next();
|
2015-09-02 23:52:01 +00:00
|
|
|
} ).queue( "foo", function() {
|
2009-12-06 22:19:33 +00:00
|
|
|
counter++;
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
div.promise( "foo" ).done( function() {
|
2011-04-11 11:40:14 +00:00
|
|
|
ok( true, "dequeue resolves the deferred" );
|
|
|
|
start();
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2011-04-11 11:40:14 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
div.dequeue( "foo" );
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
equal( counter, 1, "the queue was cleared" );
|
|
|
|
} );
|
2009-12-06 22:19:33 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
test( "clearQueue() clears the fx queue", function() {
|
|
|
|
expect( 1 );
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
var div = jQuery( {} ),
|
2013-04-09 15:45:09 +00:00
|
|
|
counter = 0;
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
div.queue( function( next ) {
|
2009-12-06 22:19:33 +00:00
|
|
|
counter++;
|
|
|
|
var self = this;
|
2015-09-02 23:52:01 +00:00
|
|
|
setTimeout( function() { jQuery( self ).clearQueue(); next(); }, 50 );
|
|
|
|
} ).queue( function() {
|
2009-12-06 22:19:33 +00:00
|
|
|
counter++;
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
equal( counter, 1, "the queue was cleared" );
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2009-12-06 22:19:33 +00:00
|
|
|
div.removeData();
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2011-04-11 11:40:14 +00:00
|
|
|
|
2012-05-23 03:04:45 +00:00
|
|
|
asyncTest( "fn.promise() - called when fx queue is empty", 3, function() {
|
2013-04-15 17:26:34 +00:00
|
|
|
var foo = jQuery( "#foo" ).clone().addBack(),
|
2012-05-23 03:04:45 +00:00
|
|
|
promised = false;
|
2011-04-11 11:40:14 +00:00
|
|
|
|
2012-05-23 03:04:45 +00:00
|
|
|
foo.queue( function( next ) {
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2012-05-23 03:04:45 +00:00
|
|
|
// called twice!
|
|
|
|
ok( !promised, "Promised hasn't been called" );
|
|
|
|
setTimeout( next, 10 );
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2012-05-23 03:04:45 +00:00
|
|
|
foo.promise().done( function() {
|
|
|
|
ok( promised = true, "Promised" );
|
2011-04-11 11:40:14 +00:00
|
|
|
start();
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
|
|
|
} );
|
2011-04-11 11:40:14 +00:00
|
|
|
|
2012-05-23 03:04:45 +00:00
|
|
|
asyncTest( "fn.promise( \"queue\" ) - called whenever last queue function is dequeued", 5, function() {
|
|
|
|
var foo = jQuery( "#foo" ),
|
|
|
|
test;
|
|
|
|
foo.promise( "queue" ).done( function() {
|
|
|
|
strictEqual( test, undefined, "called immediately when queue was already empty" );
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2012-05-23 03:04:45 +00:00
|
|
|
test = 1;
|
|
|
|
foo.queue( "queue", function( next ) {
|
|
|
|
strictEqual( test++, 1, "step one" );
|
|
|
|
setTimeout( next, 0 );
|
2015-09-02 23:52:01 +00:00
|
|
|
} ).queue( "queue", function( next ) {
|
2012-05-23 03:04:45 +00:00
|
|
|
strictEqual( test++, 2, "step two" );
|
|
|
|
setTimeout( function() {
|
|
|
|
next();
|
2012-08-13 17:43:49 +00:00
|
|
|
strictEqual( test++, 4, "step four" );
|
2012-05-23 03:04:45 +00:00
|
|
|
start();
|
|
|
|
}, 10 );
|
2015-09-02 23:52:01 +00:00
|
|
|
} ).promise( "queue" ).done( function() {
|
2012-05-23 03:04:45 +00:00
|
|
|
strictEqual( test++, 3, "step three" );
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2011-04-11 11:40:14 +00:00
|
|
|
|
2012-05-23 03:04:45 +00:00
|
|
|
foo.dequeue( "queue" );
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2011-12-09 17:41:35 +00:00
|
|
|
|
2012-08-13 17:43:49 +00:00
|
|
|
asyncTest( "fn.promise( \"queue\" ) - waits for animation to complete before resolving", 2, function() {
|
|
|
|
var foo = jQuery( "#foo" ),
|
|
|
|
test = 1;
|
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
foo.animate( {
|
2012-08-13 17:43:49 +00:00
|
|
|
top: 100
|
|
|
|
}, {
|
|
|
|
duration: 1,
|
|
|
|
queue: "queue",
|
|
|
|
complete: function() {
|
|
|
|
strictEqual( test++, 1, "step one" );
|
|
|
|
}
|
2015-09-02 23:52:01 +00:00
|
|
|
} ).dequeue( "queue" );
|
2012-08-13 17:43:49 +00:00
|
|
|
|
|
|
|
foo.promise( "queue" ).done( function() {
|
|
|
|
strictEqual( test++, 2, "step two" );
|
|
|
|
start();
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2012-08-13 17:43:49 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2012-08-13 17:43:49 +00:00
|
|
|
|
2012-05-23 03:04:45 +00:00
|
|
|
test( ".promise(obj)", function() {
|
2015-09-02 23:52:01 +00:00
|
|
|
expect( 2 );
|
2011-12-09 17:41:35 +00:00
|
|
|
|
2013-04-09 15:45:09 +00:00
|
|
|
var obj = {},
|
|
|
|
promise = jQuery( "#foo" ).promise( "promise", obj );
|
2011-12-09 17:41:35 +00:00
|
|
|
|
|
|
|
ok( jQuery.isFunction( promise.promise ), ".promise(type, obj) returns a promise" );
|
|
|
|
strictEqual( promise, obj, ".promise(type, obj) returns obj" );
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2012-05-23 03:04:45 +00:00
|
|
|
|
2012-05-29 02:25:04 +00:00
|
|
|
if ( jQuery.fn.stop ) {
|
2015-09-02 23:52:01 +00:00
|
|
|
test( "delay() can be stopped", function() {
|
2012-05-29 02:25:04 +00:00
|
|
|
expect( 3 );
|
|
|
|
stop();
|
|
|
|
|
2012-11-08 15:05:10 +00:00
|
|
|
var done = {};
|
2015-09-02 23:52:01 +00:00
|
|
|
jQuery( {} )
|
2012-05-29 02:25:04 +00:00
|
|
|
.queue( "alternate", function( next ) {
|
2012-11-08 15:05:10 +00:00
|
|
|
done.alt1 = true;
|
2012-05-29 02:25:04 +00:00
|
|
|
ok( true, "This first function was dequeued" );
|
|
|
|
next();
|
2015-09-02 23:52:01 +00:00
|
|
|
} )
|
2012-05-29 02:25:04 +00:00
|
|
|
.delay( 1000, "alternate" )
|
|
|
|
.queue( "alternate", function() {
|
2012-11-08 15:05:10 +00:00
|
|
|
done.alt2 = true;
|
2012-05-29 02:25:04 +00:00
|
|
|
ok( true, "The function was dequeued immediately, the delay was stopped" );
|
2015-09-02 23:52:01 +00:00
|
|
|
} )
|
2012-05-29 02:25:04 +00:00
|
|
|
.dequeue( "alternate" )
|
|
|
|
|
|
|
|
// stop( "alternate", false ) will NOT clear the queue, so it should automatically dequeue the next
|
|
|
|
.stop( "alternate", false, false )
|
|
|
|
|
|
|
|
// this test
|
2012-11-08 15:05:10 +00:00
|
|
|
.delay( 1 )
|
2015-09-02 23:52:01 +00:00
|
|
|
.queue( function() {
|
2012-11-08 15:05:10 +00:00
|
|
|
done.default1 = true;
|
2012-05-29 02:25:04 +00:00
|
|
|
ok( false, "This queue should never run" );
|
2015-09-02 23:52:01 +00:00
|
|
|
} )
|
2012-05-29 02:25:04 +00:00
|
|
|
|
|
|
|
// stop( clearQueue ) should clear the queue
|
|
|
|
.stop( true, false );
|
|
|
|
|
2012-11-08 15:05:10 +00:00
|
|
|
deepEqual( done, { alt1: true, alt2: true }, "Queue ran the proper functions" );
|
2012-05-29 02:25:04 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
setTimeout( function() {
|
2012-11-08 15:05:10 +00:00
|
|
|
start();
|
|
|
|
}, 1500 );
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2012-05-23 03:04:45 +00:00
|
|
|
|
2012-05-29 02:25:04 +00:00
|
|
|
asyncTest( "queue stop hooks", 2, function() {
|
|
|
|
var foo = jQuery( "#foo" );
|
|
|
|
|
|
|
|
foo.queue( function( next, hooks ) {
|
|
|
|
hooks.stop = function( gotoEnd ) {
|
|
|
|
equal( !!gotoEnd, false, "Stopped without gotoEnd" );
|
|
|
|
};
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2012-05-29 02:25:04 +00:00
|
|
|
foo.stop();
|
|
|
|
|
|
|
|
foo.queue( function( next, hooks ) {
|
|
|
|
hooks.stop = function( gotoEnd ) {
|
|
|
|
equal( gotoEnd, true, "Stopped with gotoEnd" );
|
|
|
|
start();
|
|
|
|
};
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2012-05-29 02:25:04 +00:00
|
|
|
|
|
|
|
foo.stop( false, true );
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2012-05-23 03:04:45 +00:00
|
|
|
|
2012-06-21 19:30:24 +00:00
|
|
|
} // if ( jQuery.fn.stop )
|