55
66( function ( $ ) {
77
8- module ( "Checkboxradio: core" ) ;
8+ module ( "Checkboxradio: core" ) ;
99test ( "Checkbox - Initial class structure" , function ( assert ) {
10- expect ( 4 ) ;
10+ expect ( 2 ) ;
1111 var input = $ ( "#check" ) ,
1212 label = $ ( "label[for=check]" ) ;
13- ok ( input . is ( ":visible" ) ) ;
14- assert . lacksClasses ( label , "ui-button" ) ;
13+
1514 input . checkboxradio ( ) ;
1615 assert . hasClasses ( input , "ui-helper-hidden-accessible ui-checkboxradio" ) ;
1716 assert . hasClasses ( label , "ui-button ui-widget ui-checkboxradio-label ui-corner-all" ,
1817 true , "Label has proper classes" ) ;
1918} ) ;
2019
2120test ( "Radios - Initial class structure" , function ( assert ) {
22- expect ( 10 ) ;
21+ expect ( 6 ) ;
2322 var inputs = $ ( "#radio0 input" ) ,
2423 labels = $ ( "#radio0 label" ) ;
25- ok ( inputs . is ( ":visible" ) ) ;
26- labels . each ( function ( ) {
27- assert . lacksClasses ( this , "ui-button" ) ;
28- } ) ;
24+
2925 inputs . checkboxradio ( ) ;
3026 inputs . each ( function ( ) {
3127 assert . hasClasses ( this , "ui-helper-hidden-accessible" ) ;
@@ -35,48 +31,48 @@ test( "Radios - Initial class structure", function( assert ) {
3531 } ) ;
3632} ) ;
3733
38- function assert ( noForm , form1 , form2 ) {
34+ function radioFormAssert ( noForm , form1 , form2 , assert ) {
3935 var others ,
4036 noFormElement = $ ( "#radio0 .ui-button" + noForm ) ,
4137 form1Element = $ ( "#radio1 .ui-button" + form1 ) ,
4238 form2Element = $ ( "#radio2 .ui-button" + form2 ) ;
4339
44- QUnit . assert . hasClasses ( noFormElement , "ui-state-active" ) ;
40+ assert . hasClasses ( noFormElement , "ui-state-active" ) ;
4541 $ ( "#radio0" ) . find ( ".ui-button" ) . not ( noFormElement ) . each ( function ( ) {
46- QUnit . assert . lacksClasses ( this , "ui-state-active" ) ;
42+ assert . lacksClasses ( this , "ui-state-active" ) ;
4743 } ) ;
4844
49- QUnit . assert . hasClasses ( form1Element , "ui-state-active" ) ;
45+ assert . hasClasses ( form1Element , "ui-state-active" ) ;
5046 others = $ ( "#radio1" ) . find ( ".ui-button" ) . not ( form1Element ) ;
5147 others . each ( function ( ) {
52- QUnit . assert . lacksClasses ( this , "ui-state-active" ) ;
48+ assert . lacksClasses ( this , "ui-state-active" ) ;
5349 } ) ;
54- QUnit . assert . hasClasses ( form2Element , "ui-state-active" ) ;
50+ assert . hasClasses ( form2Element , "ui-state-active" ) ;
5551 $ ( "#radio2" ) . find ( ".ui-button" ) . not ( form2Element ) . each ( function ( ) {
56- QUnit . assert . lacksClasses ( this , "ui-state-active" ) ;
52+ assert . lacksClasses ( this , "ui-state-active" ) ;
5753 } ) ;
5854}
5955
60- test ( "radio groups" , function ( ) {
56+ test ( "radio groups" , function ( assert ) {
6157 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 ) ;
6460
6561 // 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 ) ;
6864
6965 // 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 ) ;
7268
7369 // 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 ) ;
7672} ) ;
7773
7874asyncTest (
79- "Checkbox/Radiobutton do not Show Focused State when using Keyboard Navigation " ,
75+ "Checkbox/Radiobutton do not show focused State when using keyboard navigation " ,
8076 function ( assert ) {
8177 expect ( 2 ) ;
8278 var check = $ ( "#check" ) . checkboxradio ( ) ,
@@ -86,7 +82,7 @@ asyncTest(
8682 setTimeout ( function ( ) {
8783 assert . hasClasses ( label , "ui-state-focus" ) ;
8884 start ( ) ;
89- } ) ;
85+ } ) ;
9086 }
9187) ;
9288
@@ -97,8 +93,6 @@ asyncTest( "Ensure checked after single click on checkbox label button", functio
9793 var label = $ ( this ) . checkboxradio ( "widget" ) ;
9894 ok ( this . checked , "checked ok" ) ;
9995
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" );
10296 assert . hasClasses ( label , "ui-state-active" ) ;
10397 } ) ;
10498
@@ -111,53 +105,44 @@ asyncTest( "Ensure checked after single click on checkbox label button", functio
111105 start ( ) ;
112106 } ) ;
113107} ) ;
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" ) ;
119108
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+ } ) ;
143127} ) ;
144128
145129asyncTest (
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." ,
147131 function ( assert ) {
148132 expect ( 2 ) ;
149133 var form = $ ( "<form>" +
150134 "<label for='c1'></label><input id='c1' type='checkbox' checked>" +
151135 "</form>" ) ,
152- checkbox = form . find ( "input[type=checkbox]" ) . checkboxradio ( ) ;
136+ checkbox = form . find ( "input[type=checkbox]" ) . checkboxradio ( ) ,
137+ widget = checkbox . checkboxradio ( "widget" ) ;
153138
154139 checkbox . prop ( "checked" , false ) . checkboxradio ( "refresh" ) ;
155- assert . lacksClasses ( checkbox . checkboxradio ( " widget" ) , "ui-state-active" ) ;
140+ assert . lacksClasses ( widget , "ui-state-active" ) ;
156141
157142 form . get ( 0 ) . reset ( ) ;
158143
159144 setTimeout ( function ( ) {
160- assert . hasClasses ( checkbox . checkboxradio ( " widget" ) , "ui-state-active" ) ;
145+ assert . hasClasses ( widget , "ui-state-active" ) ;
161146 start ( ) ;
162147 } , 1 ) ;
163148 }
0 commit comments