1
1
define ( [
2
+ "qunit" ,
2
3
"jquery" ,
3
4
"./helper" ,
4
5
"ui/widgets/accordion"
5
- ] , function ( $ , testHelper ) {
6
+ ] , function ( QUnit , $ , testHelper ) {
6
7
7
8
var setupTeardown = testHelper . setupTeardown ,
8
9
state = testHelper . state ;
9
10
10
- module ( "accordion: core" , setupTeardown ( ) ) ;
11
+ QUnit . module ( "accordion: core" , setupTeardown ( ) ) ;
11
12
12
13
$ . each ( { div : "#list1" , ul : "#navigation" , dl : "#accordion-dl" } , function ( type , selector ) {
13
- test ( "markup structure: " + type , function ( assert ) {
14
- expect ( 10 ) ;
14
+ QUnit . test ( "markup structure: " + type , function ( assert ) {
15
+ assert . expect ( 10 ) ;
15
16
var element = $ ( selector ) . accordion ( ) ,
16
17
headers = element . find ( ".ui-accordion-header" ) ,
17
18
content = headers . next ( ) ;
18
19
19
20
assert . hasClasses ( element , "ui-accordion ui-widget" ) ;
20
- equal ( headers . length , 3 , ".ui-accordion-header elements exist, correct number" ) ;
21
+ assert . equal ( headers . length , 3 , ".ui-accordion-header elements exist, correct number" ) ;
21
22
assert . hasClasses ( headers [ 0 ] ,
22
23
"ui-accordion-header ui-accordion-header-active ui-accordion-icons" ) ;
23
24
assert . hasClasses ( headers [ 1 ] ,
24
25
"ui-accordion-header ui-accordion-header-collapsed ui-accordion-icons" ) ;
25
26
assert . hasClasses ( headers [ 2 ] ,
26
27
"ui-accordion-header ui-accordion-header-collapsed ui-accordion-icons" ) ;
27
- equal ( content . length , 3 , ".ui-accordion-content elements exist, correct number" ) ;
28
+ assert . equal ( content . length , 3 , ".ui-accordion-content elements exist, correct number" ) ;
28
29
assert . hasClasses ( content [ 0 ] ,
29
30
"ui-accordion-content ui-widget-content ui-accordion-content-active" ) ;
30
31
assert . hasClasses ( content [ 1 ] , "ui-accordion-content ui-widget-content" ) ;
31
32
assert . hasClasses ( content [ 2 ] , "ui-accordion-content ui-widget-content" ) ;
32
- deepEqual ( element . find ( ".ui-accordion-header" ) . next ( ) . get ( ) ,
33
+ assert . deepEqual ( element . find ( ".ui-accordion-header" ) . next ( ) . get ( ) ,
33
34
element . find ( ".ui-accordion-content" ) . get ( ) ,
34
35
"content panels come immediately after headers" ) ;
35
36
} ) ;
36
37
} ) ;
37
38
38
- test ( "handle click on header-descendant" , function ( ) {
39
- expect ( 1 ) ;
39
+ QUnit . test ( "handle click on header-descendant" , function ( assert ) {
40
+ assert . expect ( 1 ) ;
40
41
var element = $ ( "#navigation" ) . accordion ( ) ;
41
42
$ ( "#navigation h2:eq(1) a" ) . trigger ( "click" ) ;
42
- state ( element , 0 , 1 , 0 ) ;
43
+ state ( assert , element , 0 , 1 , 0 ) ;
43
44
} ) ;
44
45
45
- test ( "accessibility" , function ( ) {
46
- expect ( 61 ) ;
46
+ QUnit . test ( "accessibility" , function ( assert ) {
47
+ assert . expect ( 61 ) ;
47
48
var element = $ ( "#list1" ) . accordion ( {
48
49
active : 1 ,
49
50
collapsible : true
50
51
} ) ,
51
52
headers = element . find ( ".ui-accordion-header" ) ;
52
53
53
- equal ( element . attr ( "role" ) , "tablist" , "element role" ) ;
54
+ assert . equal ( element . attr ( "role" ) , "tablist" , "element role" ) ;
54
55
headers . each ( function ( i ) {
55
56
var header = headers . eq ( i ) ,
56
57
panel = header . next ( ) ;
57
- equal ( header . attr ( "role" ) , "tab" , "header " + i + " role" ) ;
58
- equal ( header . attr ( "aria-controls" ) , panel . attr ( "id" ) , "header " + i + " aria-controls" ) ;
59
- equal ( panel . attr ( "role" ) , "tabpanel" , "panel " + i + " role" ) ;
60
- equal ( panel . attr ( "aria-labelledby" ) , header . attr ( "id" ) , "panel " + i + " aria-labelledby" ) ;
58
+ assert . equal ( header . attr ( "role" ) , "tab" , "header " + i + " role" ) ;
59
+ assert . equal ( header . attr ( "aria-controls" ) , panel . attr ( "id" ) , "header " + i + " aria-controls" ) ;
60
+ assert . equal ( panel . attr ( "role" ) , "tabpanel" , "panel " + i + " role" ) ;
61
+ assert . equal ( panel . attr ( "aria-labelledby" ) , header . attr ( "id" ) , "panel " + i + " aria-labelledby" ) ;
61
62
} ) ;
62
63
63
- equal ( headers . eq ( 1 ) . attr ( "tabindex" ) , 0 , "active header has tabindex=0" ) ;
64
- equal ( headers . eq ( 1 ) . attr ( "aria-selected" ) , "true" , "active tab (1) has aria-selected=true" ) ;
65
- equal ( headers . eq ( 1 ) . attr ( "aria-expanded" ) , "true" , "active tab (1) has aria-expanded=true" ) ;
66
- equal ( headers . eq ( 1 ) . next ( ) . attr ( "aria-hidden" ) , "false" , "active tabpanel (1) has aria-hidden=false" ) ;
67
- equal ( headers . eq ( 0 ) . attr ( "tabindex" ) , - 1 , "inactive header (0) has tabindex=-1" ) ;
68
- equal ( headers . eq ( 0 ) . attr ( "aria-selected" ) , "false" , "inactive tab (0) has aria-selected=false" ) ;
69
- equal ( headers . eq ( 0 ) . attr ( "aria-expanded" ) , "false" , "inactive tab (0) has aria-expanded=false" ) ;
70
- equal ( headers . eq ( 0 ) . next ( ) . attr ( "aria-hidden" ) , "true" , "inactive tabpanel (0) has aria-hidden=true" ) ;
71
- equal ( headers . eq ( 2 ) . attr ( "tabindex" ) , - 1 , "inactive header (2) has tabindex=-1" ) ;
72
- equal ( headers . eq ( 2 ) . attr ( "aria-selected" ) , "false" , "inactive tab (2) has aria-selected=false" ) ;
73
- equal ( headers . eq ( 2 ) . attr ( "aria-expanded" ) , "false" , "inactive tab (2) has aria-expanded=false" ) ;
74
- equal ( headers . eq ( 2 ) . next ( ) . attr ( "aria-hidden" ) , "true" , "inactive tabpanel (2) has aria-hidden=true" ) ;
64
+ assert . equal ( headers . eq ( 1 ) . attr ( "tabindex" ) , 0 , "active header has tabindex=0" ) ;
65
+ assert . equal ( headers . eq ( 1 ) . attr ( "aria-selected" ) , "true" , "active tab (1) has aria-selected=true" ) ;
66
+ assert . equal ( headers . eq ( 1 ) . attr ( "aria-expanded" ) , "true" , "active tab (1) has aria-expanded=true" ) ;
67
+ assert . equal ( headers . eq ( 1 ) . next ( ) . attr ( "aria-hidden" ) , "false" , "active tabpanel (1) has aria-hidden=false" ) ;
68
+ assert . equal ( headers . eq ( 0 ) . attr ( "tabindex" ) , - 1 , "inactive header (0) has tabindex=-1" ) ;
69
+ assert . equal ( headers . eq ( 0 ) . attr ( "aria-selected" ) , "false" , "inactive tab (0) has aria-selected=false" ) ;
70
+ assert . equal ( headers . eq ( 0 ) . attr ( "aria-expanded" ) , "false" , "inactive tab (0) has aria-expanded=false" ) ;
71
+ assert . equal ( headers . eq ( 0 ) . next ( ) . attr ( "aria-hidden" ) , "true" , "inactive tabpanel (0) has aria-hidden=true" ) ;
72
+ assert . equal ( headers . eq ( 2 ) . attr ( "tabindex" ) , - 1 , "inactive header (2) has tabindex=-1" ) ;
73
+ assert . equal ( headers . eq ( 2 ) . attr ( "aria-selected" ) , "false" , "inactive tab (2) has aria-selected=false" ) ;
74
+ assert . equal ( headers . eq ( 2 ) . attr ( "aria-expanded" ) , "false" , "inactive tab (2) has aria-expanded=false" ) ;
75
+ assert . equal ( headers . eq ( 2 ) . next ( ) . attr ( "aria-hidden" ) , "true" , "inactive tabpanel (2) has aria-hidden=true" ) ;
75
76
76
77
element . accordion ( "option" , "active" , 0 ) ;
77
- equal ( headers . eq ( 0 ) . attr ( "tabindex" ) , 0 , "active header (0) has tabindex=0" ) ;
78
- equal ( headers . eq ( 0 ) . attr ( "aria-selected" ) , "true" , "active tab (0) has aria-selected=true" ) ;
79
- equal ( headers . eq ( 0 ) . attr ( "aria-expanded" ) , "true" , "active tab (0) has aria-expanded=true" ) ;
80
- equal ( headers . eq ( 0 ) . next ( ) . attr ( "aria-hidden" ) , "false" , "active tabpanel (0) has aria-hidden=false" ) ;
81
- equal ( headers . eq ( 1 ) . attr ( "tabindex" ) , - 1 , "inactive header (1) has tabindex=-1" ) ;
82
- equal ( headers . eq ( 1 ) . attr ( "aria-selected" ) , "false" , "inactive tab (1) has aria-selected=false" ) ;
83
- equal ( headers . eq ( 1 ) . attr ( "aria-expanded" ) , "false" , "inactive tab (1) has aria-expanded=false" ) ;
84
- equal ( headers . eq ( 1 ) . next ( ) . attr ( "aria-hidden" ) , "true" , "inactive tabpanel (1) has aria-hidden=true" ) ;
85
- equal ( headers . eq ( 2 ) . attr ( "tabindex" ) , - 1 , "inactive header (2) has tabindex=-1" ) ;
86
- equal ( headers . eq ( 2 ) . attr ( "aria-selected" ) , "false" , "inactive tab (2) has aria-selected=false" ) ;
87
- equal ( headers . eq ( 2 ) . attr ( "aria-expanded" ) , "false" , "inactive tab (2) has aria-expanded=false" ) ;
88
- equal ( headers . eq ( 2 ) . next ( ) . attr ( "aria-hidden" ) , "true" , "inactive tabpanel (2) has aria-hidden=true" ) ;
78
+ assert . equal ( headers . eq ( 0 ) . attr ( "tabindex" ) , 0 , "active header (0) has tabindex=0" ) ;
79
+ assert . equal ( headers . eq ( 0 ) . attr ( "aria-selected" ) , "true" , "active tab (0) has aria-selected=true" ) ;
80
+ assert . equal ( headers . eq ( 0 ) . attr ( "aria-expanded" ) , "true" , "active tab (0) has aria-expanded=true" ) ;
81
+ assert . equal ( headers . eq ( 0 ) . next ( ) . attr ( "aria-hidden" ) , "false" , "active tabpanel (0) has aria-hidden=false" ) ;
82
+ assert . equal ( headers . eq ( 1 ) . attr ( "tabindex" ) , - 1 , "inactive header (1) has tabindex=-1" ) ;
83
+ assert . equal ( headers . eq ( 1 ) . attr ( "aria-selected" ) , "false" , "inactive tab (1) has aria-selected=false" ) ;
84
+ assert . equal ( headers . eq ( 1 ) . attr ( "aria-expanded" ) , "false" , "inactive tab (1) has aria-expanded=false" ) ;
85
+ assert . equal ( headers . eq ( 1 ) . next ( ) . attr ( "aria-hidden" ) , "true" , "inactive tabpanel (1) has aria-hidden=true" ) ;
86
+ assert . equal ( headers . eq ( 2 ) . attr ( "tabindex" ) , - 1 , "inactive header (2) has tabindex=-1" ) ;
87
+ assert . equal ( headers . eq ( 2 ) . attr ( "aria-selected" ) , "false" , "inactive tab (2) has aria-selected=false" ) ;
88
+ assert . equal ( headers . eq ( 2 ) . attr ( "aria-expanded" ) , "false" , "inactive tab (2) has aria-expanded=false" ) ;
89
+ assert . equal ( headers . eq ( 2 ) . next ( ) . attr ( "aria-hidden" ) , "true" , "inactive tabpanel (2) has aria-hidden=true" ) ;
89
90
90
91
element . accordion ( "option" , "active" , false ) ;
91
- equal ( headers . eq ( 0 ) . attr ( "tabindex" ) , 0 , "previously active header (0) has tabindex=0" ) ;
92
- equal ( headers . eq ( 0 ) . attr ( "aria-selected" ) , "false" , "inactive tab (0) has aria-selected=false" ) ;
93
- equal ( headers . eq ( 0 ) . attr ( "aria-expanded" ) , "false" , "inactive tab (0) has aria-expanded=false" ) ;
94
- equal ( headers . eq ( 0 ) . next ( ) . attr ( "aria-hidden" ) , "true" , "inactive tabpanel (0) has aria-hidden=true" ) ;
95
- equal ( headers . eq ( 1 ) . attr ( "tabindex" ) , - 1 , "inactive header (1) has tabindex=-1" ) ;
96
- equal ( headers . eq ( 1 ) . attr ( "aria-selected" ) , "false" , "inactive tab (1) has aria-selected=false" ) ;
97
- equal ( headers . eq ( 1 ) . attr ( "aria-expanded" ) , "false" , "inactive tab (1) has aria-expanded=false" ) ;
98
- equal ( headers . eq ( 1 ) . next ( ) . attr ( "aria-hidden" ) , "true" , "inactive tabpanel (1) has aria-hidden=true" ) ;
99
- equal ( headers . eq ( 2 ) . attr ( "tabindex" ) , - 1 , "inactive header (2) has tabindex=-1" ) ;
100
- equal ( headers . eq ( 2 ) . attr ( "aria-selected" ) , "false" , "inactive tab (2) has aria-selected=false" ) ;
101
- equal ( headers . eq ( 2 ) . attr ( "aria-expanded" ) , "false" , "inactive tab (2) has aria-expanded=false" ) ;
102
- equal ( headers . eq ( 2 ) . next ( ) . attr ( "aria-hidden" ) , "true" , "inactive tabpanel (2) has aria-hidden=true" ) ;
92
+ assert . equal ( headers . eq ( 0 ) . attr ( "tabindex" ) , 0 , "previously active header (0) has tabindex=0" ) ;
93
+ assert . equal ( headers . eq ( 0 ) . attr ( "aria-selected" ) , "false" , "inactive tab (0) has aria-selected=false" ) ;
94
+ assert . equal ( headers . eq ( 0 ) . attr ( "aria-expanded" ) , "false" , "inactive tab (0) has aria-expanded=false" ) ;
95
+ assert . equal ( headers . eq ( 0 ) . next ( ) . attr ( "aria-hidden" ) , "true" , "inactive tabpanel (0) has aria-hidden=true" ) ;
96
+ assert . equal ( headers . eq ( 1 ) . attr ( "tabindex" ) , - 1 , "inactive header (1) has tabindex=-1" ) ;
97
+ assert . equal ( headers . eq ( 1 ) . attr ( "aria-selected" ) , "false" , "inactive tab (1) has aria-selected=false" ) ;
98
+ assert . equal ( headers . eq ( 1 ) . attr ( "aria-expanded" ) , "false" , "inactive tab (1) has aria-expanded=false" ) ;
99
+ assert . equal ( headers . eq ( 1 ) . next ( ) . attr ( "aria-hidden" ) , "true" , "inactive tabpanel (1) has aria-hidden=true" ) ;
100
+ assert . equal ( headers . eq ( 2 ) . attr ( "tabindex" ) , - 1 , "inactive header (2) has tabindex=-1" ) ;
101
+ assert . equal ( headers . eq ( 2 ) . attr ( "aria-selected" ) , "false" , "inactive tab (2) has aria-selected=false" ) ;
102
+ assert . equal ( headers . eq ( 2 ) . attr ( "aria-expanded" ) , "false" , "inactive tab (2) has aria-expanded=false" ) ;
103
+ assert . equal ( headers . eq ( 2 ) . next ( ) . attr ( "aria-hidden" ) , "true" , "inactive tabpanel (2) has aria-hidden=true" ) ;
103
104
104
105
element . accordion ( "option" , "active" , 1 ) ;
105
- equal ( headers . eq ( 1 ) . attr ( "tabindex" ) , 0 , "active header has tabindex=0" ) ;
106
- equal ( headers . eq ( 1 ) . attr ( "aria-selected" ) , "true" , "active tab (1) has aria-selected=true" ) ;
107
- equal ( headers . eq ( 1 ) . attr ( "aria-expanded" ) , "true" , "active tab (1) has aria-expanded=true" ) ;
108
- equal ( headers . eq ( 1 ) . next ( ) . attr ( "aria-hidden" ) , "false" , "active tabpanel (1) has aria-hidden=false" ) ;
109
- equal ( headers . eq ( 0 ) . attr ( "tabindex" ) , - 1 , "inactive header (0) has tabindex=-1" ) ;
110
- equal ( headers . eq ( 0 ) . attr ( "aria-selected" ) , "false" , "inactive tab (0) has aria-selected=false" ) ;
111
- equal ( headers . eq ( 0 ) . attr ( "aria-expanded" ) , "false" , "inactive tab (0) has aria-expanded=false" ) ;
112
- equal ( headers . eq ( 0 ) . next ( ) . attr ( "aria-hidden" ) , "true" , "inactive tabpanel (0) has aria-hidden=true" ) ;
113
- equal ( headers . eq ( 2 ) . attr ( "tabindex" ) , - 1 , "inactive header (2) has tabindex=-1" ) ;
114
- equal ( headers . eq ( 2 ) . attr ( "aria-selected" ) , "false" , "inactive tab (2) has aria-selected=false" ) ;
115
- equal ( headers . eq ( 2 ) . attr ( "aria-expanded" ) , "false" , "inactive tab (2) has aria-expanded=false" ) ;
116
- equal ( headers . eq ( 2 ) . next ( ) . attr ( "aria-hidden" ) , "true" , "inactive tabpanel (2) has aria-hidden=true" ) ;
106
+ assert . equal ( headers . eq ( 1 ) . attr ( "tabindex" ) , 0 , "active header has tabindex=0" ) ;
107
+ assert . equal ( headers . eq ( 1 ) . attr ( "aria-selected" ) , "true" , "active tab (1) has aria-selected=true" ) ;
108
+ assert . equal ( headers . eq ( 1 ) . attr ( "aria-expanded" ) , "true" , "active tab (1) has aria-expanded=true" ) ;
109
+ assert . equal ( headers . eq ( 1 ) . next ( ) . attr ( "aria-hidden" ) , "false" , "active tabpanel (1) has aria-hidden=false" ) ;
110
+ assert . equal ( headers . eq ( 0 ) . attr ( "tabindex" ) , - 1 , "inactive header (0) has tabindex=-1" ) ;
111
+ assert . equal ( headers . eq ( 0 ) . attr ( "aria-selected" ) , "false" , "inactive tab (0) has aria-selected=false" ) ;
112
+ assert . equal ( headers . eq ( 0 ) . attr ( "aria-expanded" ) , "false" , "inactive tab (0) has aria-expanded=false" ) ;
113
+ assert . equal ( headers . eq ( 0 ) . next ( ) . attr ( "aria-hidden" ) , "true" , "inactive tabpanel (0) has aria-hidden=true" ) ;
114
+ assert . equal ( headers . eq ( 2 ) . attr ( "tabindex" ) , - 1 , "inactive header (2) has tabindex=-1" ) ;
115
+ assert . equal ( headers . eq ( 2 ) . attr ( "aria-selected" ) , "false" , "inactive tab (2) has aria-selected=false" ) ;
116
+ assert . equal ( headers . eq ( 2 ) . attr ( "aria-expanded" ) , "false" , "inactive tab (2) has aria-expanded=false" ) ;
117
+ assert . equal ( headers . eq ( 2 ) . next ( ) . attr ( "aria-hidden" ) , "true" , "inactive tabpanel (2) has aria-hidden=true" ) ;
117
118
118
119
} ) ;
119
120
120
- asyncTest ( "keyboard support" , function ( assert ) {
121
- expect ( 13 ) ;
121
+ QUnit . test ( "keyboard support" , function ( assert ) {
122
+ var ready = assert . async ( ) ;
123
+ assert . expect ( 13 ) ;
122
124
var element = $ ( "#list1" ) . accordion ( ) ,
123
125
headers = element . find ( ".ui-accordion-header" ) ,
124
126
anchor = headers . eq ( 1 ) . next ( ) . find ( "a" ) . eq ( 0 ) ,
125
127
keyCode = $ . ui . keyCode ;
126
- equal ( headers . filter ( ".ui-state-focus" ) . length , 0 , "no headers focused on init" ) ;
128
+ assert . equal ( headers . filter ( ".ui-state-focus" ) . length , 0 , "no headers focused on init" ) ;
127
129
headers . eq ( 0 ) . simulate ( "focus" ) ;
128
130
setTimeout ( step1 ) ;
129
131
@@ -180,13 +182,13 @@ asyncTest( "keyboard support", function( assert ) {
180
182
}
181
183
182
184
function step9 ( ) {
183
- equal ( element . accordion ( "option" , "active" ) , 2 , "ENTER activates panel" ) ;
185
+ assert . equal ( element . accordion ( "option" , "active" ) , 2 , "ENTER activates panel" ) ;
184
186
headers . eq ( 1 ) . simulate ( "keydown" , { keyCode : keyCode . SPACE } ) ;
185
187
setTimeout ( step10 ) ;
186
188
}
187
189
188
190
function step10 ( ) {
189
- equal ( element . accordion ( "option" , "active" ) , 1 , "SPACE activates panel" ) ;
191
+ assert . equal ( element . accordion ( "option" , "active" ) , 1 , "SPACE activates panel" ) ;
190
192
anchor . simulate ( "focus" ) ;
191
193
setTimeout ( step11 ) ;
192
194
}
@@ -200,7 +202,7 @@ asyncTest( "keyboard support", function( assert ) {
200
202
201
203
function step12 ( ) {
202
204
assert . hasClasses ( headers . eq ( 1 ) , "ui-state-focus" , "CTRL+UP moves focus to header" ) ;
203
- start ( ) ;
205
+ ready ( ) ;
204
206
}
205
207
} ) ;
206
208
0 commit comments