Skip to content

Commit d4b0699

Browse files
committed
Checkboxradio: Test cleanup
1 parent 17b5386 commit d4b0699

File tree

5 files changed

+42
-29
lines changed

5 files changed

+42
-29
lines changed

tests/unit/checkboxradio/common.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ define( [
66
common.testWidget( "checkboxradio", {
77
noDefaultElement: true,
88
defaults: {
9-
disabled: null,
10-
label: null,
11-
icon: true,
129
classes: {
1310
"ui-checkboxradio-label": "ui-corner-all",
1411
"ui-checkboxradio-icon": "ui-corner-all"
1512
},
13+
disabled: null,
14+
icon: true,
15+
label: null,
1616

1717
// Callbacks
1818
create: null

tests/unit/checkboxradio/core.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ define( [
44
], function( $ ) {
55

66
module( "Checkboxradio: core" );
7+
78
test( "Checkbox - Initial class structure", function( assert ) {
89
expect( 2 );
910
var input = $( "#check" ),
@@ -70,15 +71,21 @@ test( "Checkbox creation requires a label, and finds it in all cases", function(
7071

7172
test( "Calling checkboxradio on an unsupported element throws an error", function( assert ) {
7273
expect( 2 );
73-
var error = new Error( "Can't create checkboxradio on element.nodeName=div and element.type=undefined" );
74+
75+
var error = new Error(
76+
"Can't create checkboxradio on element.nodeName=div and element.type=undefined"
77+
);
7478
assert.raises(
7579
function() {
7680
$( "<div>" ).checkboxradio();
7781
},
7882
error,
7983
"Proper error thrown"
8084
);
81-
error = new Error( "Can't create checkboxradio on element.nodeName=input and element.type=button" );
85+
86+
error = new Error(
87+
"Can't create checkboxradio on element.nodeName=input and element.type=button"
88+
);
8289
assert.raises(
8390
function() {
8491
$( "<input type='button'>" ).checkboxradio();
@@ -87,8 +94,10 @@ test( "Calling checkboxradio on an unsupported element throws an error", functio
8794
"Proper error thrown"
8895
);
8996
} );
97+
9098
test( "Calling checkboxradio on an input with no label throws an error", function( assert ) {
9199
expect( 1 );
100+
92101
var error = new Error( "No label found for checkboxradio widget" );
93102
assert.raises(
94103
function() {

tests/unit/checkboxradio/events.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,15 @@ asyncTest(
2828
);
2929

3030
asyncTest( "Checkbox shows focus when using keyboard navigation", function( assert ) {
31-
expect( 2 );
32-
var check = $( "#check" ).checkboxradio(),
33-
label = $( "label[for='check']" );
34-
assert.lacksClasses( label, "ui-state-focus" );
35-
check.focus();
36-
setTimeout( function() {
37-
assert.hasClasses( label, "ui-state-focus" );
38-
start();
39-
} );
40-
}
41-
);
31+
expect( 2 );
32+
var check = $( "#check" ).checkboxradio(),
33+
label = $( "label[for='check']" );
34+
assert.lacksClasses( label, "ui-state-focus" );
35+
check.focus();
36+
setTimeout( function() {
37+
assert.hasClasses( label, "ui-state-focus" );
38+
start();
39+
} );
40+
} );
4241

4342
} );

tests/unit/checkboxradio/methods.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,15 @@ $.each( [ "checkbox", "radio" ], function( index, value ) {
7272
} );
7373

7474
test( value + ": widget returns the label", function() {
75+
expect( 1 );
76+
7577
var input = $( "#" + value + "-method-refresh" ),
7678
label = $( "#" + value + "-method-refresh-label" );
7779

78-
expect( 1 );
79-
8080
input.checkboxradio();
8181
strictEqual( input.checkboxradio( "widget" )[ 0 ], label[ 0 ],
8282
"widget method returns label" );
8383
} );
84-
8584
} );
8685

8786
test( "Input wrapped in a label preserved on refresh", function() {

tests/unit/checkboxradio/options.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ module( "Checkboxradio: options" );
88
function assertDisabled( checkbox, assert ) {
99
assert.hasClasses( checkbox.checkboxradio( "widget" ), "ui-state-disabled",
1010
"label gets ui-state-disabled" );
11-
strictEqual( checkbox.is( ":disabled" ), true,
12-
"checkbox is disabled" );
11+
strictEqual( checkbox.is( ":disabled" ), true, "checkbox is disabled" );
1312
}
1413

1514
function assertEnabled( checkbox, assert ) {
@@ -20,8 +19,9 @@ function assertEnabled( checkbox, assert ) {
2019
}
2120

2221
test( "disabled", function( assert ) {
23-
var checkbox = $( "#checkbox-option-disabled" );
2422
expect( 6 );
23+
24+
var checkbox = $( "#checkbox-option-disabled" );
2525
checkbox.checkboxradio( {
2626
disabled: true
2727
} );
@@ -34,6 +34,7 @@ test( "disabled", function( assert ) {
3434
checkbox.checkboxradio( "option", "disabled", true );
3535
assertDisabled( checkbox, assert );
3636
} );
37+
3738
test( "disabled - prop true on init", function( assert ) {
3839
expect( 2 );
3940
var checkbox = $( "#checkbox-option-disabled" );
@@ -43,6 +44,7 @@ test( "disabled - prop true on init", function( assert ) {
4344

4445
assertDisabled( checkbox, assert );
4546
} );
47+
4648
test( "disabled - explicit null value, checks the DOM", function( assert ) {
4749
expect( 2 );
4850
var checkbox = $( "#checkbox-option-disabled" );
@@ -58,6 +60,7 @@ function assertNoIcon( checkbox ) {
5860
strictEqual( checkbox.checkboxradio( "widget" ).find( "span.ui-icon" ).length, 0,
5961
"Label does not contain an icon" );
6062
}
63+
6164
function assertIcon( checkbox, icon, assert ) {
6265
var iconElement = checkbox.checkboxradio( "widget" ).find( ".ui-icon" );
6366

@@ -71,6 +74,7 @@ function assertIcon( checkbox, icon, assert ) {
7174
assert.lacksClasses( iconElement, "ui-icon-check ui-state-highlight" );
7275
}
7376
}
77+
7478
test( "icon - false on init", function() {
7579
var checkbox = $( "#checkbox-option-icon" );
7680

@@ -79,6 +83,7 @@ test( "icon - false on init", function() {
7983
checkbox.checkboxradio( { icon: false } );
8084
assertNoIcon( checkbox );
8185
} );
86+
8287
test( "icon - default unchecked", function( assert ) {
8388
var checkbox = $( "#checkbox-option-icon" );
8489

@@ -87,6 +92,7 @@ test( "icon - default unchecked", function( assert ) {
8792
checkbox.checkboxradio();
8893
assertIcon( checkbox, false, assert );
8994
} );
95+
9096
test( "icon - default checked", function( assert ) {
9197
var checkbox = $( "#checkbox-option-icon" ).attr( "checked", true );
9298

@@ -95,6 +101,7 @@ test( "icon - default checked", function( assert ) {
95101
checkbox.checkboxradio();
96102
assertIcon( checkbox, "check ui-state-highlight", assert );
97103
} );
104+
98105
test( "icon", function( assert ) {
99106
var checkbox = $( "#checkbox-option-icon" );
100107

@@ -117,7 +124,6 @@ test( "icon", function( assert ) {
117124
checkbox.checkboxradio( "option", "icon", true );
118125
checkbox.prop( "checked", false ).checkboxradio( "refresh" );
119126
assertIcon( checkbox, false, assert );
120-
121127
} );
122128

123129
test( "label - default", function() {
@@ -133,6 +139,7 @@ test( "label - default", function() {
133139
strictEqual( $.trim( widget.text() ),
134140
"checkbox label", "When no value passed on create text from dom is used in dom" );
135141
} );
142+
136143
test( "label - explicit value", function() {
137144
expect( 5 );
138145
var checkbox = $( "#checkbox-option-label" ).checkboxradio( {
@@ -160,9 +167,9 @@ test( "label - explicit null value", function() {
160167

161168
expect( 2 );
162169

163-
// We are testing the default here because the default null is a special value which means to check
164-
// the DOM, so we need to make sure this happens correctly checking the options should never return
165-
// null. It should always be true or false
170+
// The default null is a special value which means to check the DOM.
171+
// We need to make sure that the option never return null.
172+
// It should always be true or false after initialization.
166173
checkbox.checkboxradio( {
167174
label: null
168175
} );
@@ -175,11 +182,11 @@ test( "label - explicit null value", function() {
175182
} );
176183

177184
test( "label", function() {
185+
expect( 4 );
186+
178187
var checkbox = $( "#checkbox-option-label" ),
179188
widget;
180189

181-
expect( 4 );
182-
183190
checkbox.checkboxradio();
184191
widget = checkbox.checkboxradio( "widget" );
185192
checkbox.checkboxradio( "option", "label", "bar" );
@@ -193,7 +200,6 @@ test( "label", function() {
193200
"bar", "When null is passed text from dom is used for option" );
194201
strictEqual( $.trim( widget.text() ),
195202
"bar", "When null is passed text from dom is used in dom" );
196-
197203
} );
198204

199205
} );

0 commit comments

Comments
 (0)