2012-05-29 16:40:13 +00:00
|
|
|
module( "queue", { teardown: moduleTeardown });
|
2009-12-06 22:19:33 +00:00
|
|
|
|
2012-08-13 17:43:49 +00:00
|
|
|
test( "queue() with other types", 14, function() {
|
2011-04-11 11:40:14 +00:00
|
|
|
stop();
|
|
|
|
|
2013-04-15 17:26:34 +00:00
|
|
|
var $div = jQuery({}),
|
2013-04-09 15:45:09 +00:00
|
|
|
counter = 0;
|
|
|
|
|
2012-05-23 03:04:45 +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" );
|
2011-04-11 11:40:14 +00:00
|
|
|
});
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2009-12-06 22:19:33 +00:00
|
|
|
$div
|
2011-04-12 08:47:46 +00:00
|
|
|
.queue("foo",function(){
|
2011-11-06 20:27:42 +00:00
|
|
|
equal( ++counter, 1, "Dequeuing" );
|
2011-04-12 08:47:46 +00:00
|
|
|
jQuery.dequeue(this,"foo");
|
2009-12-06 22:19:33 +00:00
|
|
|
})
|
2011-04-12 08:47:46 +00:00
|
|
|
.queue("foo",function(){
|
2011-11-06 20:27:42 +00:00
|
|
|
equal( ++counter, 2, "Dequeuing" );
|
2011-04-12 08:47:46 +00:00
|
|
|
jQuery(this).dequeue("foo");
|
2009-12-06 22:19:33 +00:00
|
|
|
})
|
2011-04-12 08:47:46 +00:00
|
|
|
.queue("foo",function(){
|
2011-11-06 20:27:42 +00:00
|
|
|
equal( ++counter, 3, "Dequeuing" );
|
2009-12-06 22:19:33 +00:00
|
|
|
})
|
2011-04-12 08:47:46 +00:00
|
|
|
.queue("foo",function(){
|
2011-11-06 20:27:42 +00:00
|
|
|
equal( ++counter, 4, "Dequeuing" );
|
2009-12-06 22:19:33 +00:00
|
|
|
});
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2013-04-15 17:26:34 +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();
|
|
|
|
});
|
|
|
|
|
2011-11-06 20:27:42 +00:00
|
|
|
equal( $div.queue("foo").length, 4, "Testing queue length" );
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2011-12-06 20:25:38 +00:00
|
|
|
equal( $div.queue("foo", undefined).queue("foo").length, 4, ".queue('name',undefined) does nothing but is chainable (#5571)");
|
|
|
|
|
2011-04-12 08:47:46 +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" );
|
|
|
|
equal( $div.queue("foo").length, 1, "Testing queue length" );
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2011-04-12 08:47:46 +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" );
|
|
|
|
equal( $div.queue("foo").length, 0, "Testing queue length" );
|
2012-08-13 17:43:49 +00:00
|
|
|
|
|
|
|
$div.dequeue("foo");
|
|
|
|
|
|
|
|
equal( counter, 4, "Testing previous call to dequeue" );
|
|
|
|
equal( $div.queue("foo").length, 0, "Testing queue length" );
|
|
|
|
|
2009-12-06 22:19:33 +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
|
|
|
|
2013-04-09 15:45:09 +00:00
|
|
|
var div = jQuery({}),
|
|
|
|
counter = 0;
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2009-12-06 22:19:33 +00:00
|
|
|
div.queue("foo", function(next) {
|
2011-11-06 20:27:42 +00:00
|
|
|
equal(++counter, 1, "Dequeueing");
|
2009-12-06 22:19:33 +00:00
|
|
|
next();
|
|
|
|
}).queue("foo", function(next) {
|
2011-11-06 20:27:42 +00:00
|
|
|
equal(++counter, 2, "Next was called");
|
2009-12-06 22:19:33 +00:00
|
|
|
next();
|
|
|
|
}).queue("bar", function() {
|
2012-06-21 19:30:24 +00:00
|
|
|
equal(++counter, 3, "Other queues are not triggered by next()");
|
2009-12-06 22:19:33 +00:00
|
|
|
});
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2009-12-06 22:19:33 +00:00
|
|
|
div.dequeue("foo");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("queue() passes in the next item in the queue as a parameter to fx queues", function() {
|
2011-04-11 11:40:14 +00:00
|
|
|
expect(3);
|
2009-12-06 22:19:33 +00:00
|
|
|
stop();
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2013-04-09 15:45:09 +00:00
|
|
|
var div = jQuery({}),
|
|
|
|
counter = 0;
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2013-04-09 15:45:09 +00:00
|
|
|
div.queue(function( next ) {
|
2011-11-06 20:27:42 +00:00
|
|
|
equal(++counter, 1, "Dequeueing");
|
2012-06-21 19:30:24 +00:00
|
|
|
setTimeout(function() { next(); }, 500);
|
2009-12-06 22:19:33 +00:00
|
|
|
}).queue(function(next) {
|
2011-11-06 20:27:42 +00:00
|
|
|
equal(++counter, 2, "Next was called");
|
2009-12-06 22:19:33 +00:00
|
|
|
next();
|
|
|
|
}).queue("bar", function() {
|
2012-06-21 19:30:24 +00:00
|
|
|
equal(++counter, 3, "Other queues are not triggered by next()");
|
2009-12-06 22:19:33 +00:00
|
|
|
});
|
|
|
|
|
2011-04-11 11:40:14 +00:00
|
|
|
jQuery.when( div.promise("fx"), div ).done(function() {
|
2011-11-06 20:27:42 +00:00
|
|
|
equal(counter, 2, "Deferreds resolved");
|
2011-04-11 11:40:14 +00:00
|
|
|
start();
|
|
|
|
});
|
2011-05-11 18:31:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("callbacks keep their place in the queue", function() {
|
|
|
|
expect(5);
|
|
|
|
stop();
|
|
|
|
var div = jQuery("<div>"),
|
|
|
|
counter = 0;
|
|
|
|
|
|
|
|
div.queue(function( next ) {
|
|
|
|
equal( ++counter, 1, "Queue/callback order: first called" );
|
|
|
|
setTimeout( next, 200 );
|
2012-05-29 02:25:04 +00:00
|
|
|
}).delay( 100 ).queue(function( next ) {
|
2011-05-11 18:31:42 +00:00
|
|
|
equal( ++counter, 2, "Queue/callback order: second called" );
|
2012-05-29 02:25:04 +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();
|
2011-05-11 18:31:42 +00:00
|
|
|
});
|
2012-05-29 02:25:04 +00:00
|
|
|
next();
|
2011-05-11 18:31:42 +00:00
|
|
|
}).queue(function( next ) {
|
|
|
|
equal( ++counter, 3, "Queue/callback order: third called" );
|
|
|
|
next();
|
|
|
|
});
|
2011-04-11 11:40:14 +00:00
|
|
|
|
2011-05-11 18:31:42 +00:00
|
|
|
div.promise("fx").done(function() {
|
2011-11-06 20:27:42 +00:00
|
|
|
equal(counter, 4, "Deferreds resolved");
|
2011-05-11 18:31:42 +00:00
|
|
|
start();
|
|
|
|
});
|
2009-12-06 22:19:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("delay()", function() {
|
|
|
|
expect(2);
|
|
|
|
stop();
|
|
|
|
|
|
|
|
var foo = jQuery({}), run = 0;
|
|
|
|
|
|
|
|
foo.delay(100).queue(function(){
|
|
|
|
run = 1;
|
|
|
|
ok( true, "The function was dequeued." );
|
|
|
|
start();
|
|
|
|
});
|
|
|
|
|
2011-11-06 20:27:42 +00:00
|
|
|
equal( run, 0, "The delay delayed the next function from running." );
|
2009-12-06 22:19:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("clearQueue(name) clears the queue", function() {
|
2011-04-11 11:40:14 +00:00
|
|
|
expect(2);
|
|
|
|
|
2012-06-21 19:30:24 +00:00
|
|
|
stop();
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2013-04-09 15:45:09 +00:00
|
|
|
var div = jQuery({}),
|
|
|
|
counter = 0;
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2013-04-09 15:45:09 +00:00
|
|
|
div.queue("foo", function( next ) {
|
2009-12-06 22:19:33 +00:00
|
|
|
counter++;
|
|
|
|
jQuery(this).clearQueue("foo");
|
|
|
|
next();
|
2013-04-09 15:45:09 +00:00
|
|
|
}).queue("foo", function() {
|
2009-12-06 22:19:33 +00:00
|
|
|
counter++;
|
|
|
|
});
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2011-04-11 11:40:14 +00:00
|
|
|
div.promise("foo").done(function() {
|
|
|
|
ok( true, "dequeue resolves the deferred" );
|
|
|
|
start();
|
|
|
|
});
|
|
|
|
|
2009-12-06 22:19:33 +00:00
|
|
|
div.dequeue("foo");
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2011-11-06 20:27:42 +00:00
|
|
|
equal(counter, 1, "the queue was cleared");
|
2009-12-06 22:19:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("clearQueue() clears the fx queue", function() {
|
|
|
|
expect(1);
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2013-04-09 15:45:09 +00:00
|
|
|
var div = jQuery({}),
|
|
|
|
counter = 0;
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2013-04-09 15:45:09 +00:00
|
|
|
div.queue(function( next ) {
|
2009-12-06 22:19:33 +00:00
|
|
|
counter++;
|
|
|
|
var self = this;
|
|
|
|
setTimeout(function() { jQuery(self).clearQueue(); next(); }, 50);
|
2013-04-09 15:45:09 +00:00
|
|
|
}).queue(function() {
|
2009-12-06 22:19:33 +00:00
|
|
|
counter++;
|
|
|
|
});
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2011-11-06 20:27:42 +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();
|
|
|
|
});
|
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 ) {
|
|
|
|
// called twice!
|
|
|
|
ok( !promised, "Promised hasn't been called" );
|
|
|
|
setTimeout( next, 10 );
|
2011-04-11 11:40:14 +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();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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" );
|
2011-04-11 11:40:14 +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 );
|
|
|
|
}).queue( "queue", function( next ) {
|
|
|
|
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 );
|
|
|
|
}).promise( "queue" ).done( function() {
|
|
|
|
strictEqual( test++, 3, "step three" );
|
2011-04-11 11:40:14 +00:00
|
|
|
});
|
|
|
|
|
2012-05-23 03:04:45 +00:00
|
|
|
foo.dequeue( "queue" );
|
2011-12-06 20:25:38 +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;
|
|
|
|
|
|
|
|
foo.animate({
|
|
|
|
top: 100
|
|
|
|
}, {
|
|
|
|
duration: 1,
|
|
|
|
queue: "queue",
|
|
|
|
complete: function() {
|
|
|
|
strictEqual( test++, 1, "step one" );
|
|
|
|
}
|
|
|
|
}).dequeue( "queue" );
|
|
|
|
|
|
|
|
foo.promise( "queue" ).done( function() {
|
|
|
|
strictEqual( test++, 2, "step two" );
|
|
|
|
start();
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2012-05-23 03:04:45 +00:00
|
|
|
test( ".promise(obj)", function() {
|
2011-12-09 17:41:35 +00:00
|
|
|
expect(2);
|
|
|
|
|
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" );
|
|
|
|
});
|
2012-05-23 03:04:45 +00:00
|
|
|
|
|
|
|
|
2012-05-29 02:25:04 +00:00
|
|
|
if ( jQuery.fn.stop ) {
|
|
|
|
test("delay() can be stopped", function() {
|
|
|
|
expect( 3 );
|
|
|
|
stop();
|
|
|
|
|
2012-11-08 15:05:10 +00:00
|
|
|
var done = {};
|
|
|
|
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();
|
|
|
|
})
|
|
|
|
.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" );
|
|
|
|
})
|
|
|
|
.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 )
|
2012-05-29 02:25:04 +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" );
|
|
|
|
})
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2012-11-08 15:05:10 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
start();
|
|
|
|
}, 1500 );
|
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" );
|
|
|
|
};
|
|
|
|
});
|
|
|
|
foo.stop();
|
|
|
|
|
|
|
|
foo.queue( function( next, hooks ) {
|
|
|
|
hooks.stop = function( gotoEnd ) {
|
|
|
|
equal( gotoEnd, true, "Stopped with gotoEnd" );
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
foo.stop( false, true );
|
2012-05-23 03:04:45 +00:00
|
|
|
});
|
|
|
|
|
2012-06-21 19:30:24 +00:00
|
|
|
} // if ( jQuery.fn.stop )
|