Debian Codegraph @

tests/unit/accordion/options.js

raw symbols SCIP
1 define( [
2 "qunit",
3 "jquery",
4 "./helper",
5 "ui/widgets/accordion"
6 ], function( QUnit, $, testHelper ) {
7 "use strict";
8
9 var equalHeight = testHelper.equalHeight,
10 beforeAfterEach = testHelper.beforeAfterEach,
11 state = testHelper.state;
12
13 QUnit.module( "accordion: options", beforeAfterEach() );
14
15 QUnit.test( "{ active: default }", function( assert ) {
16 assert.expect( 2 );
17 var element = $( "#list1" ).accordion();
18 assert.equal( element.accordion( "option", "active" ), 0 );
19 state( assert, element, 1, 0, 0 );
20 } );
21
22 QUnit.test( "{ active: null }", function( assert ) {
23 assert.expect( 2 );
24 var element = $( "#list1" ).accordion( {
25 active: null
26 } );
27 assert.equal( element.accordion( "option", "active" ), 0 );
28 state( assert, element, 1, 0, 0 );
29 } );
30
31 QUnit.test( "{ active: false }", function( assert ) {
32 assert.expect( 7 );
33 var element = $( "#list1" ).accordion( {
34 active: false,
35 collapsible: true
36 } );
37 state( assert, element, 0, 0, 0 );
38 assert.equal( element.find( ".ui-accordion-header.ui-state-active" ).length, 0, "no headers selected" );
39 assert.equal( element.accordion( "option", "active" ), false );
40
41 element.accordion( "option", "collapsible", false );
42 state( assert, element, 1, 0, 0 );
43 assert.equal( element.accordion( "option", "active" ), 0 );
44
45 element.accordion( "destroy" );
46 element.accordion( {
47 active: false
48 } );
49 state( assert, element, 1, 0, 0 );
50 assert.strictEqual( element.accordion( "option", "active" ), 0 );
51 } );
52
53 // https://bugs.jqueryui.com/ticket/11938
54 QUnit.test( "{ active: false, collapsible: true }", function( assert ) {
55 assert.expect( 1 );
56 var element = $( "#collapsible" ).accordion(),
57 height = element.outerHeight();
58
59 element
60 .accordion( "destroy" )
61 .accordion( {
62 active: false,
63 collapsible: true
64 } )
65 .accordion( "option", "active", 0 );
66 assert.equal( element.outerHeight(), height );
67 } );
68
69 QUnit.test( "{ active: Number }", function( assert ) {
70 assert.expect( 8 );
71 var element = $( "#list1" ).accordion( {
72 active: 2
73 } );
74 assert.equal( element.accordion( "option", "active" ), 2 );
75 state( assert, element, 0, 0, 1 );
76
77 element.accordion( "option", "active", 0 );
78 assert.equal( element.accordion( "option", "active" ), 0 );
79 state( assert, element, 1, 0, 0 );
80
81 element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "click" );
82 assert.equal( element.accordion( "option", "active" ), 1 );
83 state( assert, element, 0, 1, 0 );
84
85 element.accordion( "option", "active", 10 );
86 assert.equal( element.accordion( "option", "active" ), 1 );
87 state( assert, element, 0, 1, 0 );
88 } );
89
90 QUnit.test( "{ active: -Number }", function( assert ) {
91 assert.expect( 8 );
92 var element = $( "#list1" ).accordion( {
93 active: -1
94 } );
95 assert.equal( element.accordion( "option", "active" ), 2 );
96 state( assert, element, 0, 0, 1 );
97
98 element.accordion( "option", "active", -2 );
99 assert.equal( element.accordion( "option", "active" ), 1 );
100 state( assert, element, 0, 1, 0 );
101
102 element.accordion( "option", "active", -10 );
103 assert.equal( element.accordion( "option", "active" ), 1 );
104 state( assert, element, 0, 1, 0 );
105
106 element.accordion( "option", "active", -3 );
107 assert.equal( element.accordion( "option", "active" ), 0 );
108 state( assert, element, 1, 0, 0 );
109 } );
110
111 QUnit.test( "{ animate: false }", function( assert ) {
112 assert.expect( 3 );
113 var element = $( "#list1" ).accordion( {
114 animate: false
115 } ),
116 panels = element.find( ".ui-accordion-content" ),
117 animate = $.fn.animate;
118 $.fn.animate = function() {
119 assert.ok( false, ".animate() called" );
120 };
121
122 assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel visible" );
123 element.accordion( "option", "active", 1 );
124 assert.ok( panels.eq( 0 ).is( ":hidden" ), "first panel hidden" );
125 assert.ok( panels.eq( 1 ).is( ":visible" ), "second panel visible" );
126 $.fn.animate = animate;
127 } );
128
129 QUnit.test( "{ animate: Number }", function( assert ) {
130 var ready = assert.async();
131 assert.expect( 7 );
132 var element = $( "#list1" ).accordion( {
133 animate: 100
134 } ),
135 panels = element.find( ".ui-accordion-content" ),
136 animate = $.fn.animate;
137
138 // Called twice (both panels)
139 $.fn.animate = function( props, options ) {
140 assert.equal( options.duration, 100, "correct duration" );
141 assert.equal( options.easing, undefined, "default easing" );
142 animate.apply( this, arguments );
143 };
144
145 assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel visible" );
146 element.accordion( "option", "active", 1 );
147 panels.promise().done( function() {
148 assert.ok( panels.eq( 0 ).is( ":hidden" ), "first panel hidden" );
149 assert.ok( panels.eq( 1 ).is( ":visible" ), "second panel visible" );
150 $.fn.animate = animate;
151 ready();
152 } );
153 } );
154
155 QUnit.test( "{ animate: String }", function( assert ) {
156 var ready = assert.async();
157 assert.expect( 7 );
158 var element = $( "#list1" ).accordion( {
159 animate: "linear"
160 } ),
161 panels = element.find( ".ui-accordion-content" ),
162 animate = $.fn.animate;
163
164 // Called twice (both panels)
165 $.fn.animate = function( props, options ) {
166 assert.equal( options.duration, undefined, "default duration" );
167 assert.equal( options.easing, "linear", "correct easing" );
168 animate.apply( this, arguments );
169 };
170
171 assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel visible" );
172 element.accordion( "option", "active", 1 );
173 panels.promise().done( function() {
174 assert.ok( panels.eq( 0 ).is( ":hidden" ), "first panel hidden" );
175 assert.ok( panels.eq( 1 ).is( ":visible" ), "second panel visible" );
176 $.fn.animate = animate;
177 ready();
178 } );
179 } );
180
181 QUnit.test( "{ animate: {} }", function( assert ) {
182 var ready = assert.async();
183 assert.expect( 7 );
184 var element = $( "#list1" ).accordion( {
185 animate: {}
186 } ),
187 panels = element.find( ".ui-accordion-content" ),
188 animate = $.fn.animate;
189
190 // Called twice (both panels)
191 $.fn.animate = function( props, options ) {
192 assert.equal( options.duration, undefined, "default duration" );
193 assert.equal( options.easing, undefined, "default easing" );
194 animate.apply( this, arguments );
195 };
196
197 assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel visible" );
198 element.accordion( "option", "active", 1 );
199 panels.promise().done( function() {
200 assert.ok( panels.eq( 0 ).is( ":hidden" ), "first panel hidden" );
201 assert.ok( panels.eq( 1 ).is( ":visible" ), "second panel visible" );
202 $.fn.animate = animate;
203 ready();
204 } );
205 } );
206
207 QUnit.test( "{ animate: { duration, easing } }", function( assert ) {
208 var ready = assert.async();
209 assert.expect( 7 );
210 var element = $( "#list1" ).accordion( {
211 animate: { duration: 100, easing: "linear" }
212 } ),
213 panels = element.find( ".ui-accordion-content" ),
214 animate = $.fn.animate;
215
216 // Called twice (both panels)
217 $.fn.animate = function( props, options ) {
218 assert.equal( options.duration, 100, "correct duration" );
219 assert.equal( options.easing, "linear", "correct easing" );
220 animate.apply( this, arguments );
221 };
222
223 assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel visible" );
224 element.accordion( "option", "active", 1 );
225 panels.promise().done( function() {
226 assert.ok( panels.eq( 0 ).is( ":hidden" ), "first panel hidden" );
227 assert.ok( panels.eq( 1 ).is( ":visible" ), "second panel visible" );
228 $.fn.animate = animate;
229 ready();
230 } );
231 } );
232
233 QUnit.test( "{ animate: { duration, easing } }, animate down", function( assert ) {
234 var ready = assert.async();
235 assert.expect( 7 );
236 var element = $( "#list1" ).accordion( {
237 active: 1,
238 animate: { duration: 100, easing: "linear" }
239 } ),
240 panels = element.find( ".ui-accordion-content" ),
241 animate = $.fn.animate;
242
243 // Called twice (both panels)
244 $.fn.animate = function( props, options ) {
245 assert.equal( options.duration, 100, "correct duration" );
246 assert.equal( options.easing, "linear", "correct easing" );
247 animate.apply( this, arguments );
248 };
249
250 assert.ok( panels.eq( 1 ).is( ":visible" ), "first panel visible" );
251 element.accordion( "option", "active", 0 );
252 panels.promise().done( function() {
253 assert.ok( panels.eq( 1 ).is( ":hidden" ), "first panel hidden" );
254 assert.ok( panels.eq( 0 ).is( ":visible" ), "second panel visible" );
255 $.fn.animate = animate;
256 ready();
257 } );
258 } );
259
260 QUnit.test( "{ animate: { duration, easing, down } }, animate down", function( assert ) {
261 var ready = assert.async();
262 assert.expect( 7 );
263 var element = $( "#list1" ).accordion( {
264 active: 1,
265 animate: {
266 duration: 100,
267 easing: "linear",
268 down: {
269 easing: "swing"
270 }
271 }
272 } ),
273 panels = element.find( ".ui-accordion-content" ),
274 animate = $.fn.animate;
275
276 // Called twice (both panels)
277 $.fn.animate = function( props, options ) {
278 assert.equal( options.duration, 100, "correct duration" );
279 assert.equal( options.easing, "swing", "correct easing" );
280 animate.apply( this, arguments );
281 };
282
283 assert.ok( panels.eq( 1 ).is( ":visible" ), "first panel visible" );
284 element.accordion( "option", "active", 0 );
285 panels.promise().done( function() {
286 assert.ok( panels.eq( 1 ).is( ":hidden" ), "first panel hidden" );
287 assert.ok( panels.eq( 0 ).is( ":visible" ), "second panel visible" );
288 $.fn.animate = animate;
289 ready();
290 } );
291 } );
292
293 QUnit.test( "{ collapsible: false }", function( assert ) {
294 assert.expect( 4 );
295 var element = $( "#list1" ).accordion( {
296 active: 1
297 } );
298 element.accordion( "option", "active", false );
299 assert.equal( element.accordion( "option", "active" ), 1 );
300 state( assert, element, 0, 1, 0 );
301
302 element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "click" );
303 assert.equal( element.accordion( "option", "active" ), 1 );
304 state( assert, element, 0, 1, 0 );
305 } );
306
307 QUnit.test( "{ collapsible: true }", function( assert ) {
308 assert.expect( 6 );
309 var element = $( "#list1" ).accordion( {
310 active: 1,
311 collapsible: true
312 } );
313
314 element.accordion( "option", "active", false );
315 assert.equal( element.accordion( "option", "active" ), false );
316 state( assert, element, 0, 0, 0 );
317
318 element.accordion( "option", "active", 1 );
319 assert.equal( element.accordion( "option", "active" ), 1 );
320 state( assert, element, 0, 1, 0 );
321
322 element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "click" );
323 assert.equal( element.accordion( "option", "active" ), false );
324 state( assert, element, 0, 0, 0 );
325 } );
326
327 QUnit.test( "{ event: null }", function( assert ) {
328 assert.expect( 5 );
329 var element = $( "#list1" ).accordion( {
330 event: null
331 } );
332 state( assert, element, 1, 0, 0 );
333
334 element.accordion( "option", "active", 1 );
335 assert.equal( element.accordion( "option", "active" ), 1 );
336 state( assert, element, 0, 1, 0 );
337
338 // Ensure default click handler isn't bound
339 element.find( ".ui-accordion-header" ).eq( 2 ).trigger( "click" );
340 assert.equal( element.accordion( "option", "active" ), 1 );
341 state( assert, element, 0, 1, 0 );
342 } );
343
344 QUnit.test( "{ event: custom }", function( assert ) {
345 assert.expect( 11 );
346 var element = $( "#list1" ).accordion( {
347 event: "custom1 custom2"
348 } );
349 state( assert, element, 1, 0, 0 );
350
351 element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "custom1" );
352 assert.equal( element.accordion( "option", "active" ), 1 );
353 state( assert, element, 0, 1, 0 );
354
355 // Ensure default click handler isn't bound
356 element.find( ".ui-accordion-header" ).eq( 2 ).trigger( "click" );
357 assert.equal( element.accordion( "option", "active" ), 1 );
358 state( assert, element, 0, 1, 0 );
359
360 element.find( ".ui-accordion-header" ).eq( 2 ).trigger( "custom2" );
361 assert.equal( element.accordion( "option", "active" ), 2 );
362 state( assert, element, 0, 0, 1 );
363
364 element.accordion( "option", "event", "custom3" );
365
366 // Ensure old event handlers are unbound
367 element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "custom1" );
368 element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "custom2" );
369 assert.equal( element.accordion( "option", "active" ), 2 );
370 state( assert, element, 0, 0, 1 );
371
372 element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "custom3" );
373 assert.equal( element.accordion( "option", "active" ), 1 );
374 state( assert, element, 0, 1, 0 );
375 } );
376
377 QUnit.test( "{ header: default }", function( assert ) {
378 assert.expect( 2 );
379
380 // Default: elem.find( "> li > :first-child" ).add( elem.find( "> :not(li)" ).even() )
381 // elem.find( "> :not(li)" ).even()
382 state( assert, $( "#list1" ).accordion(), 1, 0, 0 );
383
384 // > li > :first-child
385 state( assert, $( "#navigation" ).accordion(), 1, 0, 0 );
386 } );
387
388 QUnit.test( "{ header: customString }", function( assert ) {
389 assert.expect( 6 );
390 var element = $( "#navigationWrapper" ).accordion( {
391 header: "h2"
392 } );
393 element.find( "h2" ).each( function() {
394 assert.hasClasses( this, "ui-accordion-header" );
395 } );
396 assert.equal( element.find( ".ui-accordion-header" ).length, 3 );
397 state( assert, element, 1, 0, 0 );
398 element.accordion( "option", "active", 2 );
399 state( assert, element, 0, 0, 1 );
400 } );
401
402 QUnit.test( "{ header: customFunction }", function( assert ) {
403 assert.expect( 6 );
404 var element = $( "#navigationWrapper" ).accordion( {
405 header: function( elem ) {
406 return elem.find( "h2" );
407 }
408 } );
409 element.find( "h2" ).each( function() {
410 assert.hasClasses( this, "ui-accordion-header" );
411 } );
412 assert.equal( element.find( ".ui-accordion-header" ).length, 3 );
413 state( assert, element, 1, 0, 0 );
414 element.accordion( "option", "active", 2 );
415 state( assert, element, 0, 0, 1 );
416 } );
417
418 QUnit.test( "{ heightStyle: 'auto' }", function( assert ) {
419 assert.expect( 3 );
420 var element = $( "#navigation" ).accordion( { heightStyle: "auto" } );
421 equalHeight( assert, element, 105 );
422 } );
423
424 QUnit.test( "{ heightStyle: 'content' }", function( assert ) {
425 assert.expect( 3 );
426 var element = $( "#navigation" ).accordion( { heightStyle: "content" } ),
427 sizes = element.find( ".ui-accordion-content" ).map( function() {
428 return $( this ).height();
429 } ).get();
430 assert.equal( sizes[ 0 ], 75 );
431 assert.equal( sizes[ 1 ], 105 );
432 assert.equal( sizes[ 2 ], 45 );
433 } );
434
435 QUnit.test( "{ heightStyle: 'fill' }", function( assert ) {
436 assert.expect( 3 );
437 $( "#navigationWrapper" ).height( 500 );
438 var element = $( "#navigation" ).accordion( { heightStyle: "fill" } );
439 equalHeight( assert, element, 455 );
440 } );
441
442 QUnit.test( "{ heightStyle: 'fill' } with sibling", function( assert ) {
443 assert.expect( 3 );
444 $( "#navigationWrapper" ).height( 500 );
445 $( "<p>Lorem Ipsum</p>" )
446 .css( {
447 height: 50,
448 marginTop: 20,
449 marginBottom: 30
450 } )
451 .prependTo( "#navigationWrapper" );
452 var element = $( "#navigation" ).accordion( { heightStyle: "fill" } );
453 equalHeight( assert, element, 355 );
454 } );
455
456 QUnit.test( "{ heightStyle: 'fill' } with multiple siblings", function( assert ) {
457 assert.expect( 3 );
458 $( "#navigationWrapper" ).height( 500 );
459 $( "<p>Lorem Ipsum</p>" )
460 .css( {
461 height: 50,
462 marginTop: 20,
463 marginBottom: 30
464 } )
465 .prependTo( "#navigationWrapper" );
466 $( "<p>Lorem Ipsum</p>" )
467 .css( {
468 height: 50,
469 marginTop: 20,
470 marginBottom: 30,
471 position: "absolute"
472 } )
473 .prependTo( "#navigationWrapper" );
474 $( "<p>Lorem Ipsum</p>" )
475 .css( {
476 height: 25,
477 marginTop: 10,
478 marginBottom: 15
479 } )
480 .prependTo( "#navigationWrapper" );
481 var element = $( "#navigation" ).accordion( { heightStyle: "fill" } );
482 equalHeight( assert, element, 305 );
483 } );
484
485 QUnit.test( "{ icons: false }", function( assert ) {
486 assert.expect( 8 );
487 var element = $( "#list1" );
488 function icons( on ) {
489 assert.deepEqual( element.find( "span.ui-icon" ).length, on ? 3 : 0 );
490 assert.deepEqual( element.find( ".ui-accordion-header.ui-accordion-icons" ).length, on ? 3 : 0 );
491 }
492 element.accordion();
493 icons( true );
494 element.accordion( "destroy" ).accordion( {
495 icons: false
496 } );
497 icons( false );
498 element.accordion( "option", "icons", { header: "foo", activeHeader: "bar" } );
499 icons( true );
500 element.accordion( "option", "icons", false );
501 icons( false );
502 } );
503
504 QUnit.test( "{ icons: hash }", function( assert ) {
505 assert.expect( 3 );
506 var element = $( "#list1" ).accordion( {
507 icons: { activeHeader: "a1", header: "h1" }
508 } );
509 assert.hasClasses( element.find( ".ui-accordion-header.ui-state-active span.ui-icon" ), "a1" );
510 element.accordion( "option", "icons", { activeHeader: "a2", header: "h2" } );
511 assert.lacksClasses( element.find( ".ui-accordion-header.ui-state-active span.ui-icon" ), "a1" );
512 assert.hasClasses( element.find( ".ui-accordion-header.ui-state-active span.ui-icon" ), "a2" );
513 } );
514
515 } );