Checkboxradio: Test cleanup

This commit is contained in:
Scott González 2015-10-27 16:05:52 -04:00
parent 17b5386e8c
commit d4b0699578
5 changed files with 42 additions and 29 deletions

View File

@ -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

View File

@ -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() {

View File

@ -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();
} );
} );
} );

View File

@ -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() {

View File

@ -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" );
} );
} );