5
5
6
6
( function ( $ ) {
7
7
8
- module ( "Checkboxradio: core" ) ;
8
+ module ( "Checkboxradio: core" ) ;
9
9
test ( "Checkbox - Initial class structure" , function ( assert ) {
10
- expect ( 4 ) ;
10
+ expect ( 2 ) ;
11
11
var input = $ ( "#check" ) ,
12
12
label = $ ( "label[for=check]" ) ;
13
- ok ( input . is ( ":visible" ) ) ;
14
- assert . lacksClasses ( label , "ui-button" ) ;
13
+
15
14
input . checkboxradio ( ) ;
16
15
assert . hasClasses ( input , "ui-helper-hidden-accessible ui-checkboxradio" ) ;
17
16
assert . hasClasses ( label , "ui-button ui-widget ui-checkboxradio-label ui-corner-all" ,
18
17
true , "Label has proper classes" ) ;
19
18
} ) ;
20
19
21
20
test ( "Radios - Initial class structure" , function ( assert ) {
22
- expect ( 10 ) ;
21
+ expect ( 6 ) ;
23
22
var inputs = $ ( "#radio0 input" ) ,
24
23
labels = $ ( "#radio0 label" ) ;
25
- ok ( inputs . is ( ":visible" ) ) ;
26
- labels . each ( function ( ) {
27
- assert . lacksClasses ( this , "ui-button" ) ;
28
- } ) ;
24
+
29
25
inputs . checkboxradio ( ) ;
30
26
inputs . each ( function ( ) {
31
27
assert . hasClasses ( this , "ui-helper-hidden-accessible" ) ;
@@ -35,48 +31,48 @@ test( "Radios - Initial class structure", function( assert ) {
35
31
} ) ;
36
32
} ) ;
37
33
38
- function assert ( noForm , form1 , form2 ) {
34
+ function radioFormAssert ( noForm , form1 , form2 , assert ) {
39
35
var others ,
40
36
noFormElement = $ ( "#radio0 .ui-button" + noForm ) ,
41
37
form1Element = $ ( "#radio1 .ui-button" + form1 ) ,
42
38
form2Element = $ ( "#radio2 .ui-button" + form2 ) ;
43
39
44
- QUnit . assert . hasClasses ( noFormElement , "ui-state-active" ) ;
40
+ assert . hasClasses ( noFormElement , "ui-state-active" ) ;
45
41
$ ( "#radio0" ) . find ( ".ui-button" ) . not ( noFormElement ) . each ( function ( ) {
46
- QUnit . assert . lacksClasses ( this , "ui-state-active" ) ;
42
+ assert . lacksClasses ( this , "ui-state-active" ) ;
47
43
} ) ;
48
44
49
- QUnit . assert . hasClasses ( form1Element , "ui-state-active" ) ;
45
+ assert . hasClasses ( form1Element , "ui-state-active" ) ;
50
46
others = $ ( "#radio1" ) . find ( ".ui-button" ) . not ( form1Element ) ;
51
47
others . each ( function ( ) {
52
- QUnit . assert . lacksClasses ( this , "ui-state-active" ) ;
48
+ assert . lacksClasses ( this , "ui-state-active" ) ;
53
49
} ) ;
54
- QUnit . assert . hasClasses ( form2Element , "ui-state-active" ) ;
50
+ assert . hasClasses ( form2Element , "ui-state-active" ) ;
55
51
$ ( "#radio2" ) . find ( ".ui-button" ) . not ( form2Element ) . each ( function ( ) {
56
- QUnit . assert . lacksClasses ( this , "ui-state-active" ) ;
52
+ assert . lacksClasses ( this , "ui-state-active" ) ;
57
53
} ) ;
58
54
}
59
55
60
- test ( "radio groups" , function ( ) {
56
+ test ( "radio groups" , function ( assert ) {
61
57
expect ( 36 ) ;
62
- $ ( "input[type=radio]" ) . checkboxradio ( ) ;
63
- assert ( ":eq(0)" , ":eq(1)" , ":eq(2)" ) ;
58
+ $ ( "input[type=radio]" ) . checkboxradio ( ) ;
59
+ radioFormAssert ( ":eq(0)" , ":eq(1)" , ":eq(2)" , assert ) ;
64
60
65
61
// click outside of forms
66
- $ ( "#radio0 .ui-button:eq(1)" ) . simulate ( "click" ) ;
67
- assert ( ":eq(1)" , ":eq(1)" , ":eq(2)" ) ;
62
+ $ ( "#radio0 .ui-button:eq(1)" ) . simulate ( "click" ) ;
63
+ radioFormAssert ( ":eq(1)" , ":eq(1)" , ":eq(2)" , assert ) ;
68
64
69
65
// click in first form
70
- $ ( "#radio1 .ui-button:eq(0)" ) . simulate ( "click" ) ;
71
- assert ( ":eq(1)" , ":eq(0)" , ":eq(2)" ) ;
66
+ $ ( "#radio1 .ui-button:eq(0)" ) . simulate ( "click" ) ;
67
+ radioFormAssert ( ":eq(1)" , ":eq(0)" , ":eq(2)" , assert ) ;
72
68
73
69
// click in second form
74
- $ ( "#radio2 .ui-button:eq(0)" ) . simulate ( "click" ) ;
75
- assert ( ":eq(1)" , ":eq(0)" , ":eq(0)" ) ;
70
+ $ ( "#radio2 .ui-button:eq(0)" ) . simulate ( "click" ) ;
71
+ radioFormAssert ( ":eq(1)" , ":eq(0)" , ":eq(0)" , assert ) ;
76
72
} ) ;
77
73
78
74
asyncTest (
79
- "Checkbox/Radiobutton do not Show Focused State when using Keyboard Navigation " ,
75
+ "Checkbox/Radiobutton do not show focused State when using keyboard navigation " ,
80
76
function ( assert ) {
81
77
expect ( 2 ) ;
82
78
var check = $ ( "#check" ) . checkboxradio ( ) ,
@@ -86,7 +82,7 @@ asyncTest(
86
82
setTimeout ( function ( ) {
87
83
assert . hasClasses ( label , "ui-state-focus" ) ;
88
84
start ( ) ;
89
- } ) ;
85
+ } ) ;
90
86
}
91
87
) ;
92
88
@@ -97,8 +93,6 @@ asyncTest( "Ensure checked after single click on checkbox label button", functio
97
93
var label = $ ( this ) . checkboxradio ( "widget" ) ;
98
94
ok ( this . checked , "checked ok" ) ;
99
95
100
- // The following test is commented out for now because with new markup we are trying to avoid aria
101
- //ok( lbl.attr("aria-pressed") === "true", "aria ok" );
102
96
assert . hasClasses ( label , "ui-state-active" ) ;
103
97
} ) ;
104
98
@@ -111,53 +105,44 @@ asyncTest( "Ensure checked after single click on checkbox label button", functio
111
105
start ( ) ;
112
106
} ) ;
113
107
} ) ;
114
- test ( "Checkbox creation that requires a matching finds label in all cases" , function ( assert ) {
115
- expect ( 7 ) ;
116
- var group = $ ( "<span><label for='t7092a'></label><input type='checkbox' id='t7092a'></span>" ) ;
117
- group . find ( "input[type=checkbox]" ) . checkboxradio ( ) ;
118
- assert . hasClasses ( group . find ( "label" ) , "ui-button" ) ;
119
108
120
- group = $ ( "<input type='checkbox' id='t7092b'><label for='t7092b'></label>" ) ;
121
- group . filter ( "input[type=checkbox]" ) . checkboxradio ( ) ;
122
- assert . hasClasses ( group . filter ( "label" ) , "ui-button" ) ;
123
-
124
- group = $ ( "<span><input type='checkbox' id='t7092c'></span><label for='t7092c'></label>" ) ;
125
- group . find ( "input[type=checkbox]" ) . checkboxradio ( ) ;
126
- assert . hasClasses ( group . filter ( "label" ) , "ui-button" ) ;
127
-
128
- group = $ ( "<span><input type='checkbox' id='t7092d'></span><span><label for='t7092d'></label></span>" ) ;
129
- group . find ( "input[type=checkbox]" ) . checkboxradio ( ) ;
130
- assert . hasClasses ( group . find ( "label" ) , "ui-button" ) ;
131
-
132
- group = $ ( "<input type='checkbox' id='t7092e'><span><label for='t7092e'></label></span>" ) ;
133
- group . filter ( "input[type=checkbox]" ) . checkboxradio ( ) ;
134
- assert . hasClasses ( group . find ( "label" ) , "ui-button" ) ;
135
-
136
- group = $ ( "<span><label><input type='checkbox' id='t7092f'></label></span>" ) ;
137
- group . find ( "input[type=checkbox]" ) . checkboxradio ( ) ;
138
- assert . hasClasses ( group . find ( "label" ) , "ui-button" ) ;
139
-
140
- group = $ ( "<span><input type='checkbox' id='check:7534'><label for='check:7534'>Label</label></span>" ) ;
141
- group . find ( "input" ) . checkboxradio ( ) ;
142
- assert . hasClasses ( group . find ( "label" ) , "ui-button" , "Found an label with id containing a :" ) ;
109
+ test ( "Checkbox creation requires a label, and finds it in all cases" , function ( assert ) {
110
+ expect ( 7 ) ;
111
+ var groups = [
112
+ "<span><label for='t7092a'></label><input type='checkbox' id='t7092a'></span>" ,
113
+ "<span><input type='checkbox' id='t7092b'><label for='t7092b'></label></span>" ,
114
+ "<span><span><input type='checkbox' id='t7092c'></span><label for='t7092c'></label></span>" ,
115
+ "<span><input type='checkbox' id='t7092d'></span><span><label for='t7092d'></label></span>" ,
116
+ "<span><input type='checkbox' id='t7092e'><span><label for='t7092e'></label></span>" ,
117
+ "<span><label><input type='checkbox' id='t7092f'></label></span>" ,
118
+ "<span><input type='checkbox' id='check:7534'><label for='check:7534'>Label</label></span>"
119
+ ] ;
120
+
121
+ $ . each ( groups , function ( index , markup ) {
122
+ var group = $ ( markup ) ;
123
+
124
+ group . find ( "input[type=checkbox]" ) . checkboxradio ( ) ;
125
+ assert . hasClasses ( group . find ( "label" ) , "ui-button" ) ;
126
+ } ) ;
143
127
} ) ;
144
128
145
129
asyncTest (
146
- "Resetting a button's form should refresh, the visual state of the button to match." ,
130
+ "Resetting a button's form should refresh, the visual state of the checkbox to match." ,
147
131
function ( assert ) {
148
132
expect ( 2 ) ;
149
133
var form = $ ( "<form>" +
150
134
"<label for='c1'></label><input id='c1' type='checkbox' checked>" +
151
135
"</form>" ) ,
152
- checkbox = form . find ( "input[type=checkbox]" ) . checkboxradio ( ) ;
136
+ checkbox = form . find ( "input[type=checkbox]" ) . checkboxradio ( ) ,
137
+ widget = checkbox . checkboxradio ( "widget" ) ;
153
138
154
139
checkbox . prop ( "checked" , false ) . checkboxradio ( "refresh" ) ;
155
- assert . lacksClasses ( checkbox . checkboxradio ( " widget" ) , "ui-state-active" ) ;
140
+ assert . lacksClasses ( widget , "ui-state-active" ) ;
156
141
157
142
form . get ( 0 ) . reset ( ) ;
158
143
159
144
setTimeout ( function ( ) {
160
- assert . hasClasses ( checkbox . checkboxradio ( " widget" ) , "ui-state-active" ) ;
145
+ assert . hasClasses ( widget , "ui-state-active" ) ;
161
146
start ( ) ;
162
147
} , 1 ) ;
163
148
}
0 commit comments