8ef55aa115c2f1d8b18eb7c44f9cccea6d1718b8
[myslice.git] / third-party / jquery-ui-1.10.2 / tests / unit / widget / widget_animation.js
1
2 module( "widget animation", (function() {
3         var show = $.fn.show,
4                 fadeIn = $.fn.fadeIn,
5                 slideDown = $.fn.slideDown;
6         return {
7                 setup: function() {
8                         $.widget( "ui.testWidget", {
9                                 _create: function() {
10                                         this.element.hide();
11                                 },
12                                 show: function( fn ) {
13                                         this._show( this.element, this.options.show, fn );
14                                 }
15                         });
16                         $.effects = { effect: { testEffect: $.noop } };
17                 },
18                 teardown: function() {
19                         delete $.ui.testWidget;
20                         delete $.effects.effect.testEffect;
21                         $.fn.show = show;
22                         $.fn.fadeIn = fadeIn;
23                         $.fn.slideDown = slideDown;
24                 }
25         };
26 }()));
27
28 asyncTest( "show: null", function() {
29         expect( 4 );
30
31         var element = $( "#widget" ).testWidget(),
32                 hasRun = false;
33         $.fn.show = function() {
34                 ok( true, "show called" );
35                 equal( arguments.length, 0, "no args passed to show" );
36         };
37
38         element
39                 .delay( 50 )
40                 .queue(function( next ) {
41                         ok( !hasRun, "queue before show" );
42                         next();
43                 })
44                 .testWidget( "show", function() {
45                         hasRun = true;
46                 })
47                 .queue(function( next ) {
48                         ok( hasRun, "queue after show" );
49                         start();
50                         next();
51                 });
52 });
53
54 asyncTest( "show: true", function() {
55         expect( 4 );
56
57         var element = $( "#widget" ).testWidget({
58                         show: true
59                 }),
60                 hasRun = false;
61         $.fn.fadeIn = function( duration, easing, complete ) {
62                 return this.queue(function( next ) {
63                         strictEqual( duration, undefined, "duration" );
64                         strictEqual( easing, undefined, "easing" );
65                         complete();
66                         next();
67                 });
68         };
69
70         element
71                 .delay( 50 )
72                 .queue(function( next ) {
73                         ok( !hasRun, "queue before show" );
74                         next();
75                 })
76                 .testWidget( "show", function() {
77                         hasRun = true;
78                 })
79                 .queue(function( next ) {
80                         ok( hasRun, "queue after show" );
81                         start();
82                         next();
83                 });
84 });
85
86 asyncTest( "show: number", function() {
87         expect( 4 );
88
89         var element = $( "#widget" ).testWidget({
90                 show: 123
91         }),
92         hasRun = false;
93         $.fn.fadeIn = function( duration, easing, complete ) {
94                 return this.queue(function( next ) {
95                         strictEqual( duration, 123, "duration" );
96                         strictEqual( easing, undefined, "easing" );
97                         complete();
98                         next();
99                 });
100         };
101
102         element
103                 .delay( 50 )
104                 .queue(function( next ) {
105                         ok( !hasRun, "queue before show" );
106                         next();
107                 })
108                 .testWidget( "show", function() {
109                         hasRun = true;
110                 })
111                 .queue(function( next ) {
112                         ok( hasRun, "queue after show" );
113                         start();
114                         next();
115                 });
116 });
117
118 asyncTest( "show: core animation", function() {
119         expect( 4 );
120
121         var element = $( "#widget" ).testWidget({
122                 show: "slideDown"
123         }),
124         hasRun = false;
125         $.fn.slideDown = function( duration, easing, complete ) {
126                 return this.queue(function( next ) {
127                         strictEqual( duration, undefined, "duration" );
128                         strictEqual( easing, undefined, "easing" );
129                         complete();
130                         next();
131                 });
132         };
133
134         element
135                 .delay( 50 )
136                 .queue(function( next ) {
137                         ok( !hasRun, "queue before show" );
138                         next();
139                 })
140                 .testWidget( "show", function() {
141                         hasRun = true;
142                 })
143                 .queue(function( next ) {
144                         ok( hasRun, "queue after show" );
145                         start();
146                         next();
147                 });
148 });
149
150 asyncTest( "show: effect", function() {
151         expect( 5 );
152
153         var element = $( "#widget" ).testWidget({
154                 show: "testEffect"
155         }),
156         hasRun = false;
157         $.fn.show = function( options ) {
158                 return this.queue(function( next ) {
159                         equal( options.effect, "testEffect", "effect" );
160                         ok( !("duration" in options), "duration" );
161                         ok( !("easing" in options), "easing" );
162                         options.complete();
163                         next();
164                 });
165         };
166
167         element
168                 .delay( 50 )
169                 .queue(function( next ) {
170                         ok( !hasRun, "queue before show" );
171                         next();
172                 })
173                 .testWidget( "show", function() {
174                         hasRun = true;
175                 })
176                 .queue(function( next ) {
177                         ok( hasRun, "queue after show" );
178                         start();
179                         next();
180                 });
181 });
182
183 asyncTest( "show: object(core animation)", function() {
184         expect( 4 );
185
186         var element = $( "#widget" ).testWidget({
187                 show: {
188                         effect: "slideDown",
189                         duration: 123,
190                         easing: "testEasing"
191                 }
192         }),
193         hasRun = false;
194         $.fn.slideDown = function( duration, easing, complete ) {
195                 return this.queue(function( next ) {
196                         equal( duration, 123, "duration" );
197                         equal( easing, "testEasing", "easing" );
198                         complete();
199                         next();
200                 });
201         };
202
203         element
204                 .delay( 50 )
205                 .queue(function( next ) {
206                         ok( !hasRun, "queue before show" );
207                         next();
208                 })
209                 .testWidget( "show", function() {
210                         hasRun = true;
211                 })
212                 .queue(function( next ) {
213                         ok( hasRun, "queue after show" );
214                         start();
215                         next();
216                 });
217 });
218
219 asyncTest( "show: object(effect)", function() {
220         expect( 3 );
221
222         var element = $( "#widget" ).testWidget({
223                 show: {
224                         effect: "testEffect",
225                         duration: 123,
226                         easing: "testEasing"
227                 }
228         }),
229         hasRun = false;
230         $.fn.show = function( options ) {
231                 return this.queue(function( next ) {
232                         deepEqual( options, {
233                                 effect: "testEffect",
234                                 duration: 123,
235                                 easing: "testEasing",
236                                 complete: options.complete
237                         });
238                         options.complete();
239                         next();
240                 });
241         };
242
243         element
244                 .delay( 50 )
245                 .queue(function( next ) {
246                         ok( !hasRun, "queue before show" );
247                         next();
248                 })
249                 .testWidget( "show", function() {
250                         hasRun = true;
251                 })
252                 .queue(function( next ) {
253                         ok( hasRun, "queue after show" );
254                         start();
255                         next();
256                 });
257 });