2014-08-28 19:16:51 +00:00
|
|
|
define( [
|
|
|
|
"jquery",
|
2015-01-08 02:51:38 +00:00
|
|
|
"ui/widgets/checkboxradio"
|
2014-08-28 19:16:51 +00:00
|
|
|
], function( $ ) {
|
|
|
|
|
|
|
|
module( "Checkboxradio: core" );
|
2015-10-27 20:05:52 +00:00
|
|
|
|
2014-08-28 19:16:51 +00:00
|
|
|
test( "Checkbox - Initial class structure", function( assert ) {
|
|
|
|
expect( 2 );
|
2015-09-11 14:48:20 +00:00
|
|
|
var input = $( "#check" ),
|
|
|
|
label = $( "label[for=check]" );
|
2014-08-28 19:16:51 +00:00
|
|
|
|
|
|
|
input.checkboxradio();
|
|
|
|
assert.hasClasses( input, "ui-helper-hidden-accessible ui-checkboxradio" );
|
|
|
|
assert.hasClasses( label, "ui-button ui-widget ui-checkboxradio-label ui-corner-all" );
|
2015-09-11 14:48:20 +00:00
|
|
|
} );
|
2014-08-28 19:16:51 +00:00
|
|
|
|
|
|
|
test( "Radios - Initial class structure", function( assert ) {
|
|
|
|
expect( 6 );
|
|
|
|
var inputs = $( "#radio0 input" ),
|
|
|
|
labels = $( "#radio0 label" );
|
|
|
|
|
|
|
|
inputs.checkboxradio();
|
|
|
|
inputs.each( function() {
|
|
|
|
assert.hasClasses( this, "ui-helper-hidden-accessible" );
|
2015-09-11 14:48:20 +00:00
|
|
|
} );
|
2014-08-28 19:16:51 +00:00
|
|
|
labels.each( function() {
|
|
|
|
assert.hasClasses( this, "ui-button" );
|
2015-09-11 14:48:20 +00:00
|
|
|
} );
|
|
|
|
} );
|
2014-08-28 19:16:51 +00:00
|
|
|
|
|
|
|
asyncTest( "Ensure checked after single click on checkbox label button", function( assert ) {
|
|
|
|
expect( 2 );
|
|
|
|
|
|
|
|
$( "#check2" ).checkboxradio().change( function() {
|
|
|
|
var label = $( this ).checkboxradio( "widget" );
|
|
|
|
ok( this.checked, "checked ok" );
|
|
|
|
|
|
|
|
assert.hasClasses( label, "ui-state-active" );
|
2015-09-11 14:48:20 +00:00
|
|
|
} );
|
2014-08-28 19:16:51 +00:00
|
|
|
|
|
|
|
// Support: Opera
|
|
|
|
// Opera doesn't trigger a change event when this is done synchronously.
|
|
|
|
// This seems to be a side effect of another test, but until that can be
|
|
|
|
// tracked down, this delay will have to do.
|
2015-09-11 14:48:20 +00:00
|
|
|
setTimeout( function() {
|
2014-08-28 19:16:51 +00:00
|
|
|
$( "#check2" ).checkboxradio( "widget" ).simulate( "click" );
|
|
|
|
start();
|
2015-09-11 14:48:20 +00:00
|
|
|
} );
|
|
|
|
} );
|
2014-08-28 19:16:51 +00:00
|
|
|
|
|
|
|
test( "Checkbox creation requires a label, and finds it in all cases", function( assert ) {
|
|
|
|
expect( 7 );
|
|
|
|
var groups = [
|
|
|
|
"<span><label for='t7092a'></label><input type='checkbox' id='t7092a'></span>",
|
|
|
|
"<span><input type='checkbox' id='t7092b'><label for='t7092b'></label></span>",
|
|
|
|
"<span><span><input type='checkbox' id='t7092c'></span><label for='t7092c'></label></span>",
|
|
|
|
"<span><input type='checkbox' id='t7092d'></span><span><label for='t7092d'></label></span>",
|
2015-10-06 13:38:32 +00:00
|
|
|
"<span><input type='checkbox' id='t7092e'><span><label for='t7092e'></label></span></span>",
|
2014-08-28 19:16:51 +00:00
|
|
|
"<span><label><input type='checkbox' id='t7092f'></label></span>",
|
|
|
|
"<span><input type='checkbox' id='check:7534'><label for='check:7534'>Label</label></span>"
|
|
|
|
];
|
|
|
|
|
|
|
|
$.each( groups, function( index, markup ) {
|
|
|
|
var group = $( markup );
|
|
|
|
|
|
|
|
group.find( "input[type=checkbox]" ).checkboxradio();
|
|
|
|
assert.hasClasses( group.find( "label" ), "ui-button" );
|
|
|
|
} );
|
2015-09-11 14:48:20 +00:00
|
|
|
} );
|
2014-08-28 19:16:51 +00:00
|
|
|
|
|
|
|
test( "Calling checkboxradio on an unsupported element throws an error", function( assert ) {
|
|
|
|
expect( 2 );
|
2015-10-27 20:05:52 +00:00
|
|
|
|
2015-10-28 13:23:28 +00:00
|
|
|
var errorMessage =
|
|
|
|
"Can't create checkboxradio on element.nodeName=div and element.type=undefined";
|
|
|
|
var error = new Error( errorMessage );
|
2014-08-28 19:16:51 +00:00
|
|
|
assert.raises(
|
|
|
|
function() {
|
|
|
|
$( "<div>" ).checkboxradio();
|
|
|
|
},
|
2015-10-28 13:23:28 +00:00
|
|
|
|
|
|
|
// Support: jQuery 1.7.0 only
|
|
|
|
$.fn.jquery === "1.7" ? errorMessage : error,
|
2014-08-28 19:16:51 +00:00
|
|
|
"Proper error thrown"
|
|
|
|
);
|
2015-10-27 20:05:52 +00:00
|
|
|
|
2015-10-28 13:23:28 +00:00
|
|
|
errorMessage = "Can't create checkboxradio on element.nodeName=input and element.type=button";
|
|
|
|
error = new Error( errorMessage );
|
2014-08-28 19:16:51 +00:00
|
|
|
assert.raises(
|
|
|
|
function() {
|
|
|
|
$( "<input type='button'>" ).checkboxradio();
|
|
|
|
},
|
2015-10-28 13:23:28 +00:00
|
|
|
|
|
|
|
// Support: jQuery 1.7.0 only
|
|
|
|
$.fn.jquery === "1.7" ? errorMessage : error,
|
2014-08-28 19:16:51 +00:00
|
|
|
"Proper error thrown"
|
|
|
|
);
|
2015-09-11 14:48:20 +00:00
|
|
|
} );
|
2015-10-27 20:05:52 +00:00
|
|
|
|
2014-08-28 19:16:51 +00:00
|
|
|
test( "Calling checkboxradio on an input with no label throws an error", function( assert ) {
|
|
|
|
expect( 1 );
|
2015-10-27 20:05:52 +00:00
|
|
|
|
2015-10-28 13:23:28 +00:00
|
|
|
var errorMessage = "No label found for checkboxradio widget";
|
|
|
|
var error = new Error( errorMessage );
|
2014-08-28 19:16:51 +00:00
|
|
|
assert.raises(
|
|
|
|
function() {
|
|
|
|
$( "<input type='checkbox'>" ).checkboxradio();
|
|
|
|
},
|
2015-10-28 13:23:28 +00:00
|
|
|
|
|
|
|
// Support: jQuery 1.7.0 only
|
|
|
|
$.fn.jquery === "1.7" ? errorMessage : error,
|
2014-08-28 19:16:51 +00:00
|
|
|
"Proper error thrown"
|
|
|
|
);
|
2015-09-11 14:48:20 +00:00
|
|
|
} );
|
2014-08-28 19:16:51 +00:00
|
|
|
|
|
|
|
} );
|