Debian Codegraph @

tests/unit/accordion/methods.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: methods", beforeAfterEach() );
14
15 QUnit.test( "destroy", function( assert ) {
16 assert.expect( 1 );
17 assert.domEqual( "#list1", function() {
18 $( "#list1" ).accordion().accordion( "destroy" );
19 } );
20 } );
21
22 QUnit.test( "enable/disable", function( assert ) {
23 assert.expect( 7 );
24 var element = $( "#list1" ).accordion();
25 state( assert, element, 1, 0, 0 );
26 element.accordion( "disable" );
27
28 assert.hasClasses( element, "ui-state-disabled" );
29
30 assert.equal( element.attr( "aria-disabled" ), "true", "element gets aria-disabled" );
31 assert.hasClasses( element, "ui-accordion-disabled" );
32
33 // Event does nothing
34 element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "click" );
35 state( assert, element, 1, 0, 0 );
36
37 // Option still works
38 element.accordion( "option", "active", 1 );
39 state( assert, element, 0, 1, 0 );
40 element.accordion( "enable" );
41 element.accordion( "option", "active", 2 );
42 state( assert, element, 0, 0, 1 );
43 } );
44
45 QUnit.test( "refresh", function( assert ) {
46 assert.expect( 19 );
47 var element = $( "#navigation" )
48 .parent()
49 .height( 300 )
50 .end()
51 .accordion( {
52 heightStyle: "fill"
53 } );
54 equalHeight( assert, element, 255 );
55
56 element.parent().height( 500 );
57 element.accordion( "refresh" );
58 equalHeight( assert, element, 455 );
59
60 element = $( "#list1" );
61 element.accordion();
62 state( assert, element, 1, 0, 0 );
63
64 // Disable panel via markup
65 element.find( "h3.bar" ).eq( 1 ).addClass( "ui-state-disabled" );
66 element.accordion( "refresh" );
67 state( assert, element, 1, 0, 0 );
68
69 // Don't add multiple icons
70 element.accordion( "refresh" );
71 assert.equal( element.find( ".ui-accordion-header-icon" ).length, 3 );
72
73 // Add a panel
74 element
75 .append( "<h3 class='bar' id='new_1'>new 1</h3>" )
76 .append( "<div class='foo' id='new_1_panel'>new 1</div>" );
77 element.accordion( "refresh" );
78 state( assert, element, 1, 0, 0, 0 );
79
80 // Remove all tabs
81 element.find( "h3.bar, div.foo" ).remove();
82 element.accordion( "refresh" );
83 state( assert, element );
84 assert.equal( element.accordion( "option", "active" ), false, "no active accordion panel" );
85
86 // Add panels
87 element
88 .append( "<h3 class='bar' id='new_2'>new 2</h3>" )
89 .append( "<div class='foo' id='new_2_panel'>new 2</div>" )
90 .append( "<h3 class='bar' id='new_3'>new 3</h3>" )
91 .append( "<div class='foo' id='new_3_panel'>new 3</div>" )
92 .append( "<h3 class='bar' id='new_4'>new 4</h3>" )
93 .append( "<div class='foo' id='new_4_panel'>new 4</div>" )
94 .append( "<h3 class='bar' id='new_5'>new 5</h3>" )
95 .append( "<div class='foo' id='new_5_panel'>new 5</div>" );
96 element.accordion( "refresh" );
97 state( assert, element, 1, 0, 0, 0 );
98
99 // Activate third tab
100 element.accordion( "option", "active", 2 );
101 state( assert, element, 0, 0, 1, 0 );
102
103 // Remove fourth panel, third panel should stay active
104 element.find( "h3.bar" ).eq( 3 ).remove();
105 element.find( "div.foo" ).eq( 3 ).remove();
106 element.accordion( "refresh" );
107 state( assert, element, 0, 0, 1 );
108
109 // Remove third (active) panel, second panel should become active
110 element.find( "h3.bar" ).eq( 2 ).remove();
111 element.find( "div.foo" ).eq( 2 ).remove();
112 element.accordion( "refresh" );
113 state( assert, element, 0, 1 );
114
115 // Remove first panel, previously active panel (now first) should stay active
116 element.find( "h3.bar" ).eq( 0 ).remove();
117 element.find( "div.foo" ).eq( 0 ).remove();
118 element.accordion( "refresh" );
119 state( assert, element, 1 );
120
121 // Collapse all panels
122 element.accordion( "option", {
123 collapsible: true,
124 active: false
125 } );
126 state( assert, element, 0 );
127 element.accordion( "refresh" );
128 state( assert, element, 0 );
129 } );
130
131 QUnit.test( "widget", function( assert ) {
132 assert.expect( 2 );
133 var element = $( "#list1" ).accordion(),
134 widgetElement = element.accordion( "widget" );
135 assert.equal( widgetElement.length, 1, "one element" );
136 assert.strictEqual( widgetElement[ 0 ], element[ 0 ], "same element" );
137 } );
138
139 } );