Data: camelCasing should not ignore case
[jquery.git] / test / unit / queue.js
blob5cc84f913d6f6604a7891e6b33ea3a546ebc9396
1 module( "queue", { teardown: moduleTeardown });
3 test( "queue() with other types", 14, function() {
4         stop();
6         var $div = jQuery({}),
7                 counter = 0;
9         $div.promise( "foo" ).done(function() {
10                 equal( counter, 0, "Deferred for collection with no queue is automatically resolved" );
11         });
13         $div
14                 .queue("foo",function(){
15                         equal( ++counter, 1, "Dequeuing" );
16                         jQuery.dequeue(this,"foo");
17                 })
18                 .queue("foo",function(){
19                         equal( ++counter, 2, "Dequeuing" );
20                         jQuery(this).dequeue("foo");
21                 })
22                 .queue("foo",function(){
23                         equal( ++counter, 3, "Dequeuing" );
24                 })
25                 .queue("foo",function(){
26                         equal( ++counter, 4, "Dequeuing" );
27                 });
29         $div.promise("foo").done(function() {
30                 equal( counter, 4, "Testing previous call to dequeue in deferred"  );
31                 start();
32         });
34         equal( $div.queue("foo").length, 4, "Testing queue length" );
36         equal( $div.queue("foo", undefined).queue("foo").length, 4, ".queue('name',undefined) does nothing but is chainable (#5571)");
38         $div.dequeue("foo");
40         equal( counter, 3, "Testing previous call to dequeue" );
41         equal( $div.queue("foo").length, 1, "Testing queue length" );
43         $div.dequeue("foo");
45         equal( counter, 4, "Testing previous call to dequeue" );
46         equal( $div.queue("foo").length, 0, "Testing queue length" );
48         $div.dequeue("foo");
50         equal( counter, 4, "Testing previous call to dequeue" );
51         equal( $div.queue("foo").length, 0, "Testing queue length" );
53 });
55 test("queue(name) passes in the next item in the queue as a parameter", function() {
56         expect(2);
58         var div = jQuery({}),
59                 counter = 0;
61         div.queue("foo", function(next) {
62                 equal(++counter, 1, "Dequeueing");
63                 next();
64         }).queue("foo", function(next) {
65                 equal(++counter, 2, "Next was called");
66                 next();
67         }).queue("bar", function() {
68                 equal(++counter, 3, "Other queues are not triggered by next()");
69         });
71         div.dequeue("foo");
72 });
74 test("queue() passes in the next item in the queue as a parameter to fx queues", function() {
75         expect(3);
76         stop();
78         var div = jQuery({}),
79                 counter = 0;
81         div.queue(function(next) {
82                 equal(++counter, 1, "Dequeueing");
83                 setTimeout(function() { next(); }, 500);
84         }).queue(function(next) {
85                 equal(++counter, 2, "Next was called");
86                 next();
87         }).queue("bar", function() {
88                 equal(++counter, 3, "Other queues are not triggered by next()");
89         });
91         jQuery.when( div.promise("fx"), div ).done(function() {
92                 equal(counter, 2, "Deferreds resolved");
93                 start();
94         });
95 });
97 test("callbacks keep their place in the queue", function() {
98         expect(5);
99         stop();
100         var div = jQuery("<div>"),
101                 counter = 0;
103         div.queue(function( next ) {
104                 equal( ++counter, 1, "Queue/callback order: first called" );
105                 setTimeout( next, 200 );
106         }).delay( 100 ).queue(function( next ) {
107                 equal( ++counter, 2, "Queue/callback order: second called" );
108                 jQuery( this ).delay( 100 ).queue(function( next ) {
109                         equal( ++counter, 4, "Queue/callback order: fourth called" );
110                         next();
111                 });
112                 next();
113         }).queue(function( next ) {
114                 equal( ++counter, 3, "Queue/callback order: third called" );
115                 next();
116         });
118         div.promise("fx").done(function() {
119                 equal(counter, 4, "Deferreds resolved");
120                 start();
121         });
124 test( "jQuery.queue should return array while manipulating the queue", 1, function() {
125         var div = document.createElement("div");
127         ok( jQuery.isArray( jQuery.queue( div, "fx", jQuery.noop ) ), "jQuery.queue should return an array while manipulating the queue" );
130 test("delay()", function() {
131         expect(2);
132         stop();
134         var foo = jQuery({}), run = 0;
136         foo.delay(100).queue(function(){
137                 run = 1;
138                 ok( true, "The function was dequeued." );
139                 start();
140         });
142         equal( run, 0, "The delay delayed the next function from running." );
145 test("clearQueue(name) clears the queue", function() {
146         expect(2);
148         stop();
150         var div = jQuery({}),
151                 counter = 0;
153         div.queue("foo", function( next ) {
154                 counter++;
155                 jQuery(this).clearQueue("foo");
156                 next();
157         }).queue("foo", function() {
158                 counter++;
159         });
161         div.promise("foo").done(function() {
162                 ok( true, "dequeue resolves the deferred" );
163                 start();
164         });
166         div.dequeue("foo");
168         equal(counter, 1, "the queue was cleared");
171 test("clearQueue() clears the fx queue", function() {
172         expect(1);
174         var div = jQuery({}),
175                 counter = 0;
177         div.queue(function( next ) {
178                 counter++;
179                 var self = this;
180                 setTimeout(function() { jQuery(self).clearQueue(); next(); }, 50);
181         }).queue(function() {
182                 counter++;
183         });
185         equal(counter, 1, "the queue was cleared");
187         div.removeData();
190 asyncTest( "fn.promise() - called when fx queue is empty", 3, function() {
191         var foo = jQuery( "#foo" ).clone().addBack(),
192                 promised = false;
194         foo.queue( function( next ) {
195                 // called twice!
196                 ok( !promised, "Promised hasn't been called" );
197                 setTimeout( next, 10 );
198         });
199         foo.promise().done( function() {
200                 ok( promised = true, "Promised" );
201                 start();
202         });
205 asyncTest( "fn.promise( \"queue\" ) - called whenever last queue function is dequeued", 5, function() {
206         var foo = jQuery( "#foo" ),
207                 test;
208         foo.promise( "queue" ).done( function() {
209                 strictEqual( test, undefined, "called immediately when queue was already empty" );
210         });
211         test = 1;
212         foo.queue( "queue", function( next ) {
213                 strictEqual( test++, 1, "step one" );
214                 setTimeout( next, 0 );
215         }).queue( "queue", function( next ) {
216                 strictEqual( test++, 2, "step two" );
217                 setTimeout( function() {
218                         next();
219                         strictEqual( test++, 4, "step four" );
220                         start();
221                 }, 10 );
222         }).promise( "queue" ).done( function() {
223                 strictEqual( test++, 3, "step three" );
224         });
226         foo.dequeue( "queue" );
229 asyncTest( "fn.promise( \"queue\" ) - waits for animation to complete before resolving", 2, function() {
230         var foo = jQuery( "#foo" ),
231                 test = 1;
233         foo.animate({
234                 top: 100
235         }, {
236                 duration: 1,
237                 queue: "queue",
238                 complete: function() {
239                         strictEqual( test++, 1, "step one" );
240                 }
241         }).dequeue( "queue" );
243         foo.promise( "queue" ).done( function() {
244                 strictEqual( test++, 2, "step two" );
245                 start();
246         });
250 test( ".promise(obj)", function() {
251         expect(2);
253         var obj = {},
254                 promise = jQuery( "#foo" ).promise( "promise", obj );
256         ok( jQuery.isFunction( promise.promise ), ".promise(type, obj) returns a promise" );
257         strictEqual( promise, obj, ".promise(type, obj) returns obj" );
261 if ( jQuery.fn.stop ) {
262         test("delay() can be stopped", function() {
263                 expect( 3 );
264                 stop();
266                 var done = {};
267                 jQuery({})
268                         .queue( "alternate", function( next ) {
269                                 done.alt1 = true;
270                                 ok( true, "This first function was dequeued" );
271                                 next();
272                         })
273                         .delay( 1000, "alternate" )
274                         .queue( "alternate", function() {
275                                 done.alt2 = true;
276                                 ok( true, "The function was dequeued immediately, the delay was stopped" );
277                         })
278                         .dequeue( "alternate" )
280                         // stop( "alternate", false ) will NOT clear the queue, so it should automatically dequeue the next
281                         .stop( "alternate", false, false )
283                         // this test
284                         .delay( 1 )
285                         .queue(function() {
286                                 done.default1 = true;
287                                 ok( false, "This queue should never run" );
288                         })
290                         // stop( clearQueue ) should clear the queue
291                         .stop( true, false );
293                 deepEqual( done, { alt1: true, alt2: true }, "Queue ran the proper functions" );
295                 setTimeout(function() {
296                         start();
297                 }, 1500 );
298         });
300         asyncTest( "queue stop hooks", 2, function() {
301                 var foo = jQuery( "#foo" );
303                 foo.queue( function( next, hooks ) {
304                         hooks.stop = function( gotoEnd ) {
305                                 equal( !!gotoEnd, false, "Stopped without gotoEnd" );
306                         };
307                 });
308                 foo.stop();
310                 foo.queue( function( next, hooks ) {
311                         hooks.stop = function( gotoEnd ) {
312                                 equal( gotoEnd, true, "Stopped with gotoEnd" );
313                                 start();
314                         };
315                 });
317                 foo.stop( false, true );
318         });
320 } // if ( jQuery.fn.stop )