2014-08-28 19:16:51 +00:00
|
|
|
define( [
|
2016-04-03 14:53:34 +00:00
|
|
|
"qunit",
|
2014-08-28 19:16:51 +00:00
|
|
|
"jquery",
|
2020-05-16 07:16:24 +00:00
|
|
|
"lib/helper",
|
2015-01-08 02:51:38 +00:00
|
|
|
"ui/widgets/checkboxradio"
|
2020-05-16 07:16:24 +00:00
|
|
|
], function( QUnit, $, helper ) {
|
2021-06-06 22:58:12 +00:00
|
|
|
"use strict";
|
2014-08-28 19:16:51 +00:00
|
|
|
|
2020-05-16 07:16:24 +00:00
|
|
|
QUnit.module( "Checkboxradio: methods", { afterEach: helper.moduleAfterEach } );
|
2014-08-28 19:16:51 +00:00
|
|
|
|
|
|
|
$.each( [ "checkbox", "radio" ], function( index, value ) {
|
2016-04-03 14:53:34 +00:00
|
|
|
QUnit.test( value + ": refresh", function( assert ) {
|
2014-08-28 19:16:51 +00:00
|
|
|
var widget, icon,
|
|
|
|
checkbox = value === "checkbox",
|
|
|
|
input = $( "#" + value + "-method-refresh" );
|
|
|
|
|
2016-04-03 14:53:34 +00:00
|
|
|
assert.expect( checkbox ? 11 : 8 );
|
2014-08-28 19:16:51 +00:00
|
|
|
|
|
|
|
input.checkboxradio();
|
|
|
|
|
|
|
|
widget = input.checkboxradio( "widget" );
|
|
|
|
icon = widget.find( ".ui-icon" );
|
2016-04-03 14:53:34 +00:00
|
|
|
assert.strictEqual( icon.length, 1,
|
2014-08-28 19:16:51 +00:00
|
|
|
"There is initally one icon" );
|
|
|
|
|
|
|
|
icon.remove();
|
|
|
|
input.checkboxradio( "refresh" );
|
|
|
|
icon = widget.find( ".ui-icon" );
|
2016-04-03 14:53:34 +00:00
|
|
|
assert.strictEqual( icon.length, 1,
|
2014-08-28 19:16:51 +00:00
|
|
|
"Icon is recreated on refresh if absent" );
|
|
|
|
assert.hasClasses( icon, "ui-icon-blank" );
|
|
|
|
if ( checkbox ) {
|
|
|
|
assert.lacksClasses( icon, "ui-icon-check" );
|
|
|
|
}
|
|
|
|
assert.lacksClasses( widget, "ui-checkboxradio-checked" );
|
|
|
|
|
|
|
|
input.prop( "checked", true );
|
|
|
|
input.checkboxradio( "refresh" );
|
|
|
|
if ( checkbox ) {
|
|
|
|
assert.hasClasses( icon, "ui-icon-check" );
|
|
|
|
}
|
|
|
|
assert[ !checkbox ? "hasClasses" : "lacksClasses" ]( icon, "ui-icon-blank" );
|
|
|
|
assert.hasClasses( widget, "ui-checkboxradio-checked" );
|
|
|
|
|
|
|
|
input.prop( "checked", false );
|
|
|
|
input.checkboxradio( "refresh" );
|
|
|
|
assert.hasClasses( icon, "ui-icon-blank" );
|
|
|
|
if ( checkbox ) {
|
|
|
|
assert.lacksClasses( icon, "ui-icon-check" );
|
|
|
|
}
|
|
|
|
assert.lacksClasses( widget, "ui-checkboxradio-checked" );
|
2015-09-11 14:48:20 +00:00
|
|
|
} );
|
2014-08-28 19:16:51 +00:00
|
|
|
|
2016-04-03 14:53:34 +00:00
|
|
|
QUnit.test( value + ": destroy", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2014-08-28 19:16:51 +00:00
|
|
|
assert.domEqual( "#" + value + "-method-destroy", function() {
|
|
|
|
$( "#" + value + "-method-destroy" ).checkboxradio().checkboxradio( "destroy" );
|
2015-09-11 14:48:20 +00:00
|
|
|
} );
|
|
|
|
} );
|
2014-08-28 19:16:51 +00:00
|
|
|
|
2016-04-03 14:53:34 +00:00
|
|
|
QUnit.test( value + ": disable / enable", function( assert ) {
|
|
|
|
assert.expect( 4 );
|
2014-08-28 19:16:51 +00:00
|
|
|
var input = $( "#" + value + "-method-disable" ),
|
|
|
|
widget = input.checkboxradio().checkboxradio( "widget" );
|
|
|
|
|
|
|
|
input.checkboxradio( "disable" );
|
|
|
|
assert.hasClasses( widget, "ui-state-disabled" );
|
2016-04-03 14:53:34 +00:00
|
|
|
assert.strictEqual( input.is( ":disabled" ), true,
|
2014-08-28 19:16:51 +00:00
|
|
|
value + " is disabled when disable is called" );
|
|
|
|
|
|
|
|
input.checkboxradio( "enable" );
|
|
|
|
assert.lacksClasses( widget, "ui-state-disabled" );
|
2016-04-03 14:53:34 +00:00
|
|
|
assert.strictEqual( input.is( ":disabled" ), false,
|
2014-08-28 19:16:51 +00:00
|
|
|
value + " has disabled prop removed when enable is called" );
|
2015-09-11 14:48:20 +00:00
|
|
|
} );
|
2014-08-28 19:16:51 +00:00
|
|
|
|
2016-04-03 14:53:34 +00:00
|
|
|
QUnit.test( value + ": widget returns the label", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2015-10-27 20:05:52 +00:00
|
|
|
|
2014-08-28 19:16:51 +00:00
|
|
|
var input = $( "#" + value + "-method-refresh" ),
|
|
|
|
label = $( "#" + value + "-method-refresh-label" );
|
|
|
|
|
|
|
|
input.checkboxradio();
|
2016-04-03 14:53:34 +00:00
|
|
|
assert.strictEqual( input.checkboxradio( "widget" )[ 0 ], label[ 0 ],
|
2014-08-28 19:16:51 +00:00
|
|
|
"widget method returns label" );
|
2015-09-11 14:48:20 +00:00
|
|
|
} );
|
2014-08-28 19:16:51 +00:00
|
|
|
} );
|
|
|
|
|
2016-04-03 14:53:34 +00:00
|
|
|
QUnit.test( "Input wrapped in a label preserved on refresh", function( assert ) {
|
2014-08-28 19:16:51 +00:00
|
|
|
var input = $( "#label-with-no-for" ).checkboxradio(),
|
|
|
|
element = input.checkboxradio( "widget" );
|
|
|
|
|
2016-04-03 14:53:34 +00:00
|
|
|
assert.expect( 1 );
|
2014-08-28 19:16:51 +00:00
|
|
|
|
|
|
|
input.checkboxradio( "refresh" );
|
2016-04-03 14:53:34 +00:00
|
|
|
assert.strictEqual( input.parent()[ 0 ], element[ 0 ], "Input preserved" );
|
2015-09-11 14:48:20 +00:00
|
|
|
} );
|
2014-08-28 19:16:51 +00:00
|
|
|
|
|
|
|
} );
|