2011-01-09 21:58:47 +00:00
|
|
|
module("queue", { teardown: moduleTeardown });
|
2009-12-06 22:19:33 +00:00
|
|
|
|
|
|
|
test("queue() with other types",function() {
|
2011-04-11 11:40:14 +00:00
|
|
|
expect(11);
|
2009-12-06 22:19:33 +00:00
|
|
|
var counter = 0;
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2011-04-11 11:40:14 +00:00
|
|
|
stop();
|
|
|
|
|
|
|
|
var $div = jQuery({}),
|
|
|
|
defer;
|
|
|
|
|
2011-04-12 09:29:25 +00:00
|
|
|
$div.promise("foo").done(function() {
|
2011-04-11 11:40:14 +00:00
|
|
|
equals( counter, 0, "Deferred for collection with no queue is automatically resolved" );
|
|
|
|
});
|
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(){
|
2009-12-06 22:19:33 +00:00
|
|
|
equals( ++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(){
|
2009-12-06 22:19:33 +00:00
|
|
|
equals( ++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(){
|
2009-12-06 22:19:33 +00:00
|
|
|
equals( ++counter, 3, "Dequeuing" );
|
|
|
|
})
|
2011-04-12 08:47:46 +00:00
|
|
|
.queue("foo",function(){
|
2009-12-06 22:19:33 +00:00
|
|
|
equals( ++counter, 4, "Dequeuing" );
|
|
|
|
});
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2011-04-12 09:29:25 +00:00
|
|
|
defer = $div.promise("foo").done(function() {
|
2011-04-11 11:40:14 +00:00
|
|
|
equals( counter, 4, "Testing previous call to dequeue in deferred" );
|
|
|
|
start();
|
|
|
|
});
|
|
|
|
|
2011-04-12 08:47:46 +00:00
|
|
|
equals( $div.queue("foo").length, 4, "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
|
|
|
|
2009-12-06 22:19:33 +00:00
|
|
|
equals( counter, 3, "Testing previous call to dequeue" );
|
2011-04-12 08:47:46 +00:00
|
|
|
equals( $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
|
|
|
|
2009-12-06 22:19:33 +00:00
|
|
|
equals( counter, 4, "Testing previous call to dequeue" );
|
2011-04-12 08:47:46 +00:00
|
|
|
equals( $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
|
|
|
|
2009-12-06 22:19:33 +00:00
|
|
|
var div = jQuery({});
|
|
|
|
var counter = 0;
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2009-12-06 22:19:33 +00:00
|
|
|
div.queue("foo", function(next) {
|
|
|
|
equals(++counter, 1, "Dequeueing");
|
|
|
|
next();
|
|
|
|
}).queue("foo", function(next) {
|
|
|
|
equals(++counter, 2, "Next was called");
|
|
|
|
next();
|
|
|
|
}).queue("bar", function() {
|
|
|
|
equals(++counter, 3, "Other queues are not triggered by next()")
|
|
|
|
});
|
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
|
|
|
|
2009-12-06 22:19:33 +00:00
|
|
|
var div = jQuery({});
|
|
|
|
var counter = 0;
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2009-12-06 22:19:33 +00:00
|
|
|
div.queue(function(next) {
|
|
|
|
equals(++counter, 1, "Dequeueing");
|
|
|
|
var self = this;
|
|
|
|
setTimeout(function() { next() }, 500);
|
|
|
|
}).queue(function(next) {
|
|
|
|
equals(++counter, 2, "Next was called");
|
|
|
|
next();
|
|
|
|
}).queue("bar", function() {
|
|
|
|
equals(++counter, 3, "Other queues are not triggered by next()")
|
|
|
|
});
|
|
|
|
|
2011-04-11 11:40:14 +00:00
|
|
|
jQuery.when( div.promise("fx"), div ).done(function() {
|
|
|
|
equals(counter, 2, "Deferreds resolved");
|
|
|
|
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 );
|
|
|
|
}).show(100, function() {
|
|
|
|
equal( ++counter, 2, "Queue/callback order: second called" );
|
|
|
|
jQuery(this).hide(100, function() {
|
|
|
|
equal( ++counter, 4, "Queue/callback order: fourth called" );
|
|
|
|
});
|
|
|
|
}).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() {
|
|
|
|
equals(counter, 4, "Deferreds resolved");
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
|
|
|
equals( run, 0, "The delay delayed the next function from running." );
|
|
|
|
});
|
|
|
|
|
2011-09-28 15:55:29 +00:00
|
|
|
test("delay() can be stopped", function() {
|
|
|
|
expect( 3 );
|
|
|
|
stop();
|
|
|
|
|
|
|
|
var foo = jQuery({}), run = 0;
|
|
|
|
|
|
|
|
foo
|
|
|
|
.queue( "alternate", function( next ) {
|
|
|
|
run++;
|
|
|
|
ok( true, "This first function was dequeued" );
|
|
|
|
next();
|
|
|
|
})
|
|
|
|
.delay( 100, "alternate" )
|
|
|
|
.queue( "alternate", function() {
|
|
|
|
run++;
|
|
|
|
ok( true, "The function was dequeued immediately, the delay was stopped" );
|
|
|
|
})
|
|
|
|
.dequeue( "alternate" )
|
|
|
|
|
|
|
|
// stop( false ) will NOT clear the queue, so it should automatically dequeue the next
|
|
|
|
.stop( false, false, "alternate" )
|
|
|
|
|
|
|
|
// this test
|
|
|
|
.delay( 100 )
|
|
|
|
.queue(function() {
|
|
|
|
run++;
|
|
|
|
ok( false, "This queue should never run" );
|
|
|
|
})
|
|
|
|
|
|
|
|
// stop( clearQueue ) should clear the queue
|
|
|
|
.stop( true, false );
|
|
|
|
|
|
|
|
equal( run, 2, "Queue ran the proper functions" );
|
|
|
|
|
|
|
|
setTimeout( start, 200 );
|
|
|
|
});
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
stop()
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2009-12-06 22:19:33 +00:00
|
|
|
var div = jQuery({});
|
|
|
|
var counter = 0;
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2009-12-06 22:19:33 +00:00
|
|
|
div.queue("foo", function(next) {
|
|
|
|
counter++;
|
|
|
|
jQuery(this).clearQueue("foo");
|
|
|
|
next();
|
|
|
|
}).queue("foo", function(next) {
|
|
|
|
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
|
|
|
|
2009-12-06 22:19:33 +00:00
|
|
|
equals(counter, 1, "the queue was cleared");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("clearQueue() clears the fx queue", function() {
|
|
|
|
expect(1);
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2009-12-06 22:19:33 +00:00
|
|
|
var div = jQuery({});
|
|
|
|
var counter = 0;
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2009-12-06 22:19:33 +00:00
|
|
|
div.queue(function(next) {
|
|
|
|
counter++;
|
|
|
|
var self = this;
|
|
|
|
setTimeout(function() { jQuery(self).clearQueue(); next(); }, 50);
|
|
|
|
}).queue(function(next) {
|
|
|
|
counter++;
|
|
|
|
});
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2009-12-06 22:19:33 +00:00
|
|
|
equals(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
|
|
|
|
|
|
|
test("_mark() and _unmark()", function() {
|
|
|
|
expect(1);
|
|
|
|
|
|
|
|
var div = {},
|
|
|
|
$div = jQuery( div );
|
|
|
|
|
|
|
|
stop();
|
|
|
|
|
|
|
|
jQuery._mark( div, "foo" );
|
|
|
|
jQuery._mark( div, "foo" );
|
|
|
|
jQuery._unmark( div, "foo" );
|
|
|
|
jQuery._unmark( div, "foo" );
|
|
|
|
|
|
|
|
$div.promise( "foo" ).done(function() {
|
|
|
|
ok( true, "No more marks" );
|
|
|
|
start();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("_mark() and _unmark() default to 'fx'", function() {
|
|
|
|
expect(1);
|
|
|
|
|
|
|
|
var div = {},
|
|
|
|
$div = jQuery( div );
|
|
|
|
|
|
|
|
stop();
|
|
|
|
|
|
|
|
jQuery._mark( div );
|
|
|
|
jQuery._mark( div );
|
|
|
|
jQuery._unmark( div, "fx" );
|
|
|
|
jQuery._unmark( div );
|
|
|
|
|
|
|
|
$div.promise().done(function() {
|
|
|
|
ok( true, "No more marks" );
|
|
|
|
start();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("promise()", function() {
|
|
|
|
expect(1);
|
|
|
|
|
|
|
|
stop();
|
|
|
|
|
|
|
|
var objects = [];
|
|
|
|
|
|
|
|
jQuery.each( [{}, {}], function( i, div ) {
|
|
|
|
var $div = jQuery( div );
|
|
|
|
$div.queue(function( next ) {
|
|
|
|
setTimeout( function() {
|
|
|
|
if ( i ) {
|
|
|
|
next();
|
|
|
|
setTimeout( function() {
|
|
|
|
jQuery._unmark( div );
|
|
|
|
}, 20 );
|
|
|
|
} else {
|
|
|
|
jQuery._unmark( div );
|
|
|
|
setTimeout( function() {
|
|
|
|
next();
|
|
|
|
}, 20 );
|
|
|
|
}
|
|
|
|
}, 50 );
|
|
|
|
}).queue(function( next ) {
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
jQuery._mark( div );
|
|
|
|
objects.push( $div );
|
|
|
|
});
|
|
|
|
|
|
|
|
jQuery.when.apply( jQuery, objects ).done(function() {
|
|
|
|
ok( true, "Deferred resolved" );
|
|
|
|
start();
|
|
|
|
});
|
|
|
|
|
|
|
|
jQuery.each( objects, function() {
|
|
|
|
this.dequeue();
|
|
|
|
});
|
2011-04-12 09:29:25 +00:00
|
|
|
});
|