aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott González <scott.gonzalez@gmail.com>2015-10-27 16:05:52 -0400
committerScott González <scott.gonzalez@gmail.com>2015-10-27 16:05:52 -0400
commitd4b0699578f5cfc3c69be13af64e2440214b112e (patch)
tree405fe3f9b21c23c61da106ae46da5a0e0e63d853
parent17b5386e8cb48c522ddb581a001fef5434e57f9a (diff)
downloadjquery-ui-d4b0699578f5cfc3c69be13af64e2440214b112e.tar.gz
jquery-ui-d4b0699578f5cfc3c69be13af64e2440214b112e.zip
Checkboxradio: Test cleanup
-rw-r--r--tests/unit/checkboxradio/common.js6
-rw-r--r--tests/unit/checkboxradio/core.js13
-rw-r--r--tests/unit/checkboxradio/events.js21
-rw-r--r--tests/unit/checkboxradio/methods.js5
-rw-r--r--tests/unit/checkboxradio/options.js26
5 files changed, 42 insertions, 29 deletions
diff --git a/tests/unit/checkboxradio/common.js b/tests/unit/checkboxradio/common.js
index 5e03cc9df..48c348a3e 100644
--- a/tests/unit/checkboxradio/common.js
+++ b/tests/unit/checkboxradio/common.js
@@ -6,13 +6,13 @@ define( [
common.testWidget( "checkboxradio", {
noDefaultElement: true,
defaults: {
- disabled: null,
- label: null,
- icon: true,
classes: {
"ui-checkboxradio-label": "ui-corner-all",
"ui-checkboxradio-icon": "ui-corner-all"
},
+ disabled: null,
+ icon: true,
+ label: null,
// Callbacks
create: null
diff --git a/tests/unit/checkboxradio/core.js b/tests/unit/checkboxradio/core.js
index 5fb13f586..ac4f2705a 100644
--- a/tests/unit/checkboxradio/core.js
+++ b/tests/unit/checkboxradio/core.js
@@ -4,6 +4,7 @@ define( [
], function( $ ) {
module( "Checkboxradio: core" );
+
test( "Checkbox - Initial class structure", function( assert ) {
expect( 2 );
var input = $( "#check" ),
@@ -70,7 +71,10 @@ test( "Checkbox creation requires a label, and finds it in all cases", function(
test( "Calling checkboxradio on an unsupported element throws an error", function( assert ) {
expect( 2 );
- var error = new Error( "Can't create checkboxradio on element.nodeName=div and element.type=undefined" );
+
+ var error = new Error(
+ "Can't create checkboxradio on element.nodeName=div and element.type=undefined"
+ );
assert.raises(
function() {
$( "<div>" ).checkboxradio();
@@ -78,7 +82,10 @@ test( "Calling checkboxradio on an unsupported element throws an error", functio
error,
"Proper error thrown"
);
- error = new Error( "Can't create checkboxradio on element.nodeName=input and element.type=button" );
+
+ error = new Error(
+ "Can't create checkboxradio on element.nodeName=input and element.type=button"
+ );
assert.raises(
function() {
$( "<input type='button'>" ).checkboxradio();
@@ -87,8 +94,10 @@ test( "Calling checkboxradio on an unsupported element throws an error", functio
"Proper error thrown"
);
} );
+
test( "Calling checkboxradio on an input with no label throws an error", function( assert ) {
expect( 1 );
+
var error = new Error( "No label found for checkboxradio widget" );
assert.raises(
function() {
diff --git a/tests/unit/checkboxradio/events.js b/tests/unit/checkboxradio/events.js
index 498491bd1..838e0ca63 100644
--- a/tests/unit/checkboxradio/events.js
+++ b/tests/unit/checkboxradio/events.js
@@ -28,16 +28,15 @@ asyncTest(
);
asyncTest( "Checkbox shows focus when using keyboard navigation", function( assert ) {
- expect( 2 );
- var check = $( "#check" ).checkboxradio(),
- label = $( "label[for='check']" );
- assert.lacksClasses( label, "ui-state-focus" );
- check.focus();
- setTimeout( function() {
- assert.hasClasses( label, "ui-state-focus" );
- start();
- } );
- }
-);
+ expect( 2 );
+ var check = $( "#check" ).checkboxradio(),
+ label = $( "label[for='check']" );
+ assert.lacksClasses( label, "ui-state-focus" );
+ check.focus();
+ setTimeout( function() {
+ assert.hasClasses( label, "ui-state-focus" );
+ start();
+ } );
+} );
} );
diff --git a/tests/unit/checkboxradio/methods.js b/tests/unit/checkboxradio/methods.js
index a749ef450..ec3a3f667 100644
--- a/tests/unit/checkboxradio/methods.js
+++ b/tests/unit/checkboxradio/methods.js
@@ -72,16 +72,15 @@ $.each( [ "checkbox", "radio" ], function( index, value ) {
} );
test( value + ": widget returns the label", function() {
+ expect( 1 );
+
var input = $( "#" + value + "-method-refresh" ),
label = $( "#" + value + "-method-refresh-label" );
- expect( 1 );
-
input.checkboxradio();
strictEqual( input.checkboxradio( "widget" )[ 0 ], label[ 0 ],
"widget method returns label" );
} );
-
} );
test( "Input wrapped in a label preserved on refresh", function() {
diff --git a/tests/unit/checkboxradio/options.js b/tests/unit/checkboxradio/options.js
index 56daf7445..1f862c242 100644
--- a/tests/unit/checkboxradio/options.js
+++ b/tests/unit/checkboxradio/options.js
@@ -8,8 +8,7 @@ module( "Checkboxradio: options" );
function assertDisabled( checkbox, assert ) {
assert.hasClasses( checkbox.checkboxradio( "widget" ), "ui-state-disabled",
"label gets ui-state-disabled" );
- strictEqual( checkbox.is( ":disabled" ), true,
- "checkbox is disabled" );
+ strictEqual( checkbox.is( ":disabled" ), true, "checkbox is disabled" );
}
function assertEnabled( checkbox, assert ) {
@@ -20,8 +19,9 @@ function assertEnabled( checkbox, assert ) {
}
test( "disabled", function( assert ) {
- var checkbox = $( "#checkbox-option-disabled" );
expect( 6 );
+
+ var checkbox = $( "#checkbox-option-disabled" );
checkbox.checkboxradio( {
disabled: true
} );
@@ -34,6 +34,7 @@ test( "disabled", function( assert ) {
checkbox.checkboxradio( "option", "disabled", true );
assertDisabled( checkbox, assert );
} );
+
test( "disabled - prop true on init", function( assert ) {
expect( 2 );
var checkbox = $( "#checkbox-option-disabled" );
@@ -43,6 +44,7 @@ test( "disabled - prop true on init", function( assert ) {
assertDisabled( checkbox, assert );
} );
+
test( "disabled - explicit null value, checks the DOM", function( assert ) {
expect( 2 );
var checkbox = $( "#checkbox-option-disabled" );
@@ -58,6 +60,7 @@ function assertNoIcon( checkbox ) {
strictEqual( checkbox.checkboxradio( "widget" ).find( "span.ui-icon" ).length, 0,
"Label does not contain an icon" );
}
+
function assertIcon( checkbox, icon, assert ) {
var iconElement = checkbox.checkboxradio( "widget" ).find( ".ui-icon" );
@@ -71,6 +74,7 @@ function assertIcon( checkbox, icon, assert ) {
assert.lacksClasses( iconElement, "ui-icon-check ui-state-highlight" );
}
}
+
test( "icon - false on init", function() {
var checkbox = $( "#checkbox-option-icon" );
@@ -79,6 +83,7 @@ test( "icon - false on init", function() {
checkbox.checkboxradio( { icon: false } );
assertNoIcon( checkbox );
} );
+
test( "icon - default unchecked", function( assert ) {
var checkbox = $( "#checkbox-option-icon" );
@@ -87,6 +92,7 @@ test( "icon - default unchecked", function( assert ) {
checkbox.checkboxradio();
assertIcon( checkbox, false, assert );
} );
+
test( "icon - default checked", function( assert ) {
var checkbox = $( "#checkbox-option-icon" ).attr( "checked", true );
@@ -95,6 +101,7 @@ test( "icon - default checked", function( assert ) {
checkbox.checkboxradio();
assertIcon( checkbox, "check ui-state-highlight", assert );
} );
+
test( "icon", function( assert ) {
var checkbox = $( "#checkbox-option-icon" );
@@ -117,7 +124,6 @@ test( "icon", function( assert ) {
checkbox.checkboxradio( "option", "icon", true );
checkbox.prop( "checked", false ).checkboxradio( "refresh" );
assertIcon( checkbox, false, assert );
-
} );
test( "label - default", function() {
@@ -133,6 +139,7 @@ test( "label - default", function() {
strictEqual( $.trim( widget.text() ),
"checkbox label", "When no value passed on create text from dom is used in dom" );
} );
+
test( "label - explicit value", function() {
expect( 5 );
var checkbox = $( "#checkbox-option-label" ).checkboxradio( {
@@ -160,9 +167,9 @@ test( "label - explicit null value", function() {
expect( 2 );
- // We are testing the default here because the default null is a special value which means to check
- // the DOM, so we need to make sure this happens correctly checking the options should never return
- // null. It should always be true or false
+ // The default null is a special value which means to check the DOM.
+ // We need to make sure that the option never return null.
+ // It should always be true or false after initialization.
checkbox.checkboxradio( {
label: null
} );
@@ -175,11 +182,11 @@ test( "label - explicit null value", function() {
} );
test( "label", function() {
+ expect( 4 );
+
var checkbox = $( "#checkbox-option-label" ),
widget;
- expect( 4 );
-
checkbox.checkboxradio();
widget = checkbox.checkboxradio( "widget" );
checkbox.checkboxradio( "option", "label", "bar" );
@@ -193,7 +200,6 @@ test( "label", function() {
"bar", "When null is passed text from dom is used for option" );
strictEqual( $.trim( widget.text() ),
"bar", "When null is passed text from dom is used in dom" );
-
} );
} );