2014-01-22 17:02:32 +00:00
|
|
|
define( [
|
2016-04-03 14:43:27 +00:00
|
|
|
"qunit",
|
2014-01-22 17:02:32 +00:00
|
|
|
"jquery",
|
2015-01-08 02:51:38 +00:00
|
|
|
"ui/widgets/button"
|
2016-04-03 14:43:27 +00:00
|
|
|
], function( QUnit, $ ) {
|
2014-01-22 17:02:32 +00:00
|
|
|
|
2016-04-03 14:43:27 +00:00
|
|
|
QUnit.module( "Button (deprecated): core" );
|
2014-01-22 17:02:32 +00:00
|
|
|
|
2016-04-03 14:43:27 +00:00
|
|
|
QUnit.test( "Calling button on a checkbox input calls checkboxradio widget", function( assert ) {
|
2014-01-22 17:02:32 +00:00
|
|
|
var checkbox = $( "#checkbox01" );
|
|
|
|
|
2016-04-03 14:43:27 +00:00
|
|
|
assert.expect( 2 );
|
2014-01-22 17:02:32 +00:00
|
|
|
checkbox.button();
|
|
|
|
|
2016-04-03 14:43:27 +00:00
|
|
|
assert.ok( !!checkbox.checkboxradio( "instance" ),
|
2014-01-22 17:02:32 +00:00
|
|
|
"Calling button on a checkbox creates checkboxradio instance" );
|
2016-04-03 14:43:27 +00:00
|
|
|
assert.ok( !checkbox.checkboxradio( "option", "icon" ),
|
2014-01-22 17:02:32 +00:00
|
|
|
"Calling button on a checkbox sets the checkboxradio icon option to false" );
|
|
|
|
} );
|
|
|
|
|
2016-04-03 14:43:27 +00:00
|
|
|
QUnit.test( "Calling buttonset calls controlgroup", function( assert ) {
|
2014-01-22 17:02:32 +00:00
|
|
|
var controlgroup = $( ".buttonset" );
|
|
|
|
|
2016-04-03 14:43:27 +00:00
|
|
|
assert.expect( 1 );
|
2014-01-22 17:02:32 +00:00
|
|
|
controlgroup.buttonset();
|
|
|
|
|
2016-04-03 14:43:27 +00:00
|
|
|
assert.ok( controlgroup.is( ":ui-controlgroup" ), "Calling buttonset creates controlgroup instance" );
|
2014-01-22 17:02:32 +00:00
|
|
|
} );
|
|
|
|
|
2016-04-03 14:43:27 +00:00
|
|
|
QUnit.module( "Button (deprecated): methods" );
|
2014-01-22 17:02:32 +00:00
|
|
|
|
2016-04-03 14:43:27 +00:00
|
|
|
QUnit.test( "destroy", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2014-01-22 17:02:32 +00:00
|
|
|
assert.domEqual( "#checkbox02", function() {
|
|
|
|
$( "#checkbox02" ).button().button( "destroy" );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2016-04-03 14:43:27 +00:00
|
|
|
QUnit.test( "refresh: Ensure disabled state is preserved correctly.", function( assert ) {
|
|
|
|
assert.expect( 5 );
|
2014-01-22 17:02:32 +00:00
|
|
|
var element = null;
|
|
|
|
|
|
|
|
element = $( "#checkbox02" );
|
|
|
|
element.button( { disabled: true } ).button( "refresh" );
|
2016-04-03 14:43:27 +00:00
|
|
|
assert.ok( element.button( "option", "disabled" ), "Checkboxes should remain disabled after refresh" );
|
|
|
|
assert.ok( element.prop( "disabled" ), "Input remains disabled after refresh" );
|
2014-01-22 17:02:32 +00:00
|
|
|
|
|
|
|
element = $( "#radio02" );
|
|
|
|
element.button( { disabled: true } ).button( "refresh" );
|
2016-04-03 14:43:27 +00:00
|
|
|
assert.ok( element.button( "option", "disabled" ), "Radio buttons should remain disabled after refresh" );
|
2014-01-22 17:02:32 +00:00
|
|
|
|
|
|
|
element = $( "#checkbox02" );
|
|
|
|
element.button( { disabled: true } ).prop( "disabled", false ).button( "refresh" );
|
2016-04-03 14:43:27 +00:00
|
|
|
assert.ok( !element.button( "option", "disabled" ), "Changing a checkbox's disabled property should update the state after refresh." );
|
2014-01-22 17:02:32 +00:00
|
|
|
|
|
|
|
element = $( "#radio02" );
|
|
|
|
element.button( { disabled: true } ).prop( "disabled", false ).button( "refresh" );
|
2016-04-03 14:43:27 +00:00
|
|
|
assert.ok( !element.button( "option", "disabled" ), "Changing a radio button's disabled property should update the state after refresh." );
|
2014-01-22 17:02:32 +00:00
|
|
|
|
|
|
|
} );
|
|
|
|
|
2016-04-03 14:43:27 +00:00
|
|
|
QUnit.module( "button (deprecated): options" );
|
2014-01-22 17:02:32 +00:00
|
|
|
|
2016-04-03 14:43:27 +00:00
|
|
|
QUnit.test( "Setting items option on buttonset sets the button properties on the items option", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2014-01-22 17:02:32 +00:00
|
|
|
|
|
|
|
var controlgroup = $( ".buttonset" );
|
|
|
|
|
|
|
|
controlgroup.buttonset( { items: "bar" } );
|
2016-04-03 14:43:27 +00:00
|
|
|
assert.equal( controlgroup.controlgroup( "option", "items.button" ), "bar",
|
2014-01-22 17:02:32 +00:00
|
|
|
"items.button set when setting items option on init on buttonset" );
|
|
|
|
|
|
|
|
controlgroup.buttonset( "option", "items", "foo" );
|
2016-04-03 14:43:27 +00:00
|
|
|
assert.equal( controlgroup.controlgroup( "option", "items.button" ), "foo",
|
2014-01-22 17:02:32 +00:00
|
|
|
"items.button set when setting items option on buttonset" );
|
|
|
|
} );
|
|
|
|
|
2016-04-03 14:43:27 +00:00
|
|
|
QUnit.test( "disabled, null", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2014-01-22 17:02:32 +00:00
|
|
|
|
|
|
|
$( "#radio02" ).prop( "disabled", true ).button( { disabled: null } );
|
2016-04-03 14:43:27 +00:00
|
|
|
assert.deepEqual( $( "#radio02" ).button( "option", "disabled" ), true,
|
2014-01-22 17:02:32 +00:00
|
|
|
"disabled option set to true" );
|
2016-04-03 14:43:27 +00:00
|
|
|
assert.deepEqual( true, $( "#radio02" ).prop( "disabled" ), "element is not disabled" );
|
2014-01-22 17:02:32 +00:00
|
|
|
} );
|
|
|
|
|
2016-04-03 14:43:27 +00:00
|
|
|
QUnit.test( "text / showLabel options proxied", function( assert ) {
|
|
|
|
assert.expect( 8 );
|
2014-01-22 17:02:32 +00:00
|
|
|
var button = $( "#button" );
|
|
|
|
button.button( {
|
|
|
|
text: false,
|
|
|
|
icon: "ui-icon-gear"
|
|
|
|
} );
|
2016-04-03 14:43:27 +00:00
|
|
|
assert.equal( button.button( "option", "showLabel" ), false,
|
2014-01-22 17:02:32 +00:00
|
|
|
"Setting the text option to false sets the showLabel option to false on init" );
|
|
|
|
button.button( "option", "showLabel", true );
|
2016-04-03 14:43:27 +00:00
|
|
|
assert.equal( button.button( "option", "text" ), true,
|
2014-01-22 17:02:32 +00:00
|
|
|
"Setting showLabel true with option method sets text option to true" );
|
|
|
|
button.button( "option", "text", false );
|
2016-04-03 14:43:27 +00:00
|
|
|
assert.equal( button.button( "option", "showLabel" ), false,
|
2014-01-22 17:02:32 +00:00
|
|
|
"Setting text false with option method sets showLabel option to false" );
|
|
|
|
button.button( "option", "text", true );
|
2016-04-03 14:43:27 +00:00
|
|
|
assert.equal( button.button( "option", "showLabel" ), true,
|
2014-01-22 17:02:32 +00:00
|
|
|
"Setting text true with option method sets showLabel option to true" );
|
|
|
|
button.button( "option", "showLabel", false );
|
2016-04-03 14:43:27 +00:00
|
|
|
assert.equal( button.button( "option", "text" ), false,
|
2014-01-22 17:02:32 +00:00
|
|
|
"Setting showLabel false with option method sets text option to false" );
|
|
|
|
button.button( "destroy" );
|
|
|
|
button.button( {
|
|
|
|
text: true,
|
|
|
|
icon: "ui-icon-gear"
|
|
|
|
} );
|
2016-04-03 14:43:27 +00:00
|
|
|
assert.equal( button.button( "option", "showLabel" ), true,
|
2014-01-22 17:02:32 +00:00
|
|
|
"Setting the text option to true sets the showLabel option to true on init" );
|
|
|
|
button.button( "destroy" );
|
|
|
|
button.button( {
|
|
|
|
showLabel: true,
|
|
|
|
icon: "ui-icon-gear"
|
|
|
|
} );
|
2016-04-03 14:43:27 +00:00
|
|
|
assert.equal( button.button( "option", "text" ), true,
|
2014-01-22 17:02:32 +00:00
|
|
|
"Setting the showLabel option to true sets the text option to true on init" );
|
|
|
|
button.button( "destroy" );
|
|
|
|
button.button( {
|
|
|
|
showLabel: false,
|
|
|
|
icon: "ui-icon-gear"
|
|
|
|
} );
|
2016-04-03 14:43:27 +00:00
|
|
|
assert.equal( button.button( "option", "text" ), false,
|
2014-01-22 17:02:32 +00:00
|
|
|
"Setting the showLabel option to false sets the text option to false on init" );
|
|
|
|
} );
|
|
|
|
|
2016-04-03 14:43:27 +00:00
|
|
|
QUnit.test( "icon / icons options properly proxied", function( assert ) {
|
|
|
|
assert.expect( 10 );
|
2014-01-22 17:02:32 +00:00
|
|
|
|
|
|
|
var button = $( "#button" );
|
|
|
|
|
|
|
|
button.button( {
|
|
|
|
icon: "foo"
|
|
|
|
} );
|
|
|
|
|
2016-04-03 14:43:27 +00:00
|
|
|
assert.equal( button.button( "option", "icons.primary" ), "foo",
|
2014-01-22 17:02:32 +00:00
|
|
|
"Icon option properly proxied on init" );
|
|
|
|
|
|
|
|
button.button( {
|
|
|
|
icon: "bar"
|
|
|
|
} );
|
|
|
|
|
2016-04-03 14:43:27 +00:00
|
|
|
assert.equal( button.button( "option", "icons.primary" ), "bar",
|
2014-01-22 17:02:32 +00:00
|
|
|
"Icon option properly proxied with option method" );
|
|
|
|
|
|
|
|
button.button( {
|
|
|
|
icons: {
|
|
|
|
primary: "foo"
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2016-04-03 14:43:27 +00:00
|
|
|
assert.equal( button.button( "option", "icon" ), "foo",
|
2014-01-22 17:02:32 +00:00
|
|
|
"Icons primary option properly proxied with option method" );
|
2016-04-03 14:43:27 +00:00
|
|
|
assert.equal( button.button( "option", "iconPosition" ), "beginning",
|
2014-01-22 17:02:32 +00:00
|
|
|
"Icons primary option sets iconPosition option to beginning" );
|
|
|
|
|
|
|
|
button.button( {
|
|
|
|
icons: {
|
|
|
|
secondary: "bar"
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2016-04-03 14:43:27 +00:00
|
|
|
assert.equal( button.button( "option", "icon" ), "bar",
|
2014-01-22 17:02:32 +00:00
|
|
|
"Icons secondary option properly proxied with option method" );
|
2016-04-03 14:43:27 +00:00
|
|
|
assert.equal( button.button( "option", "iconPosition" ), "end",
|
2014-01-22 17:02:32 +00:00
|
|
|
"Icons secondary option sets iconPosition option to end" );
|
|
|
|
|
|
|
|
button.button( "destroy" );
|
|
|
|
|
|
|
|
button.button( {
|
|
|
|
icons: {
|
|
|
|
primary: "foo"
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2016-04-03 14:43:27 +00:00
|
|
|
assert.equal( button.button( "option", "icon" ), "foo",
|
2014-01-22 17:02:32 +00:00
|
|
|
"Icons primary option properly proxied on init" );
|
2016-04-03 14:43:27 +00:00
|
|
|
assert.equal( button.button( "option", "iconPosition" ), "beginning",
|
2014-01-22 17:02:32 +00:00
|
|
|
"Icons primary option sets iconPosition option to beginning on init" );
|
|
|
|
|
|
|
|
button.button( {
|
|
|
|
icons: {
|
|
|
|
secondary: "bar"
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2016-04-03 14:43:27 +00:00
|
|
|
assert.equal( button.button( "option", "icon" ), "bar",
|
2014-01-22 17:02:32 +00:00
|
|
|
"Icons secondary option properly proxied on init" );
|
2016-04-03 14:43:27 +00:00
|
|
|
assert.equal( button.button( "option", "iconPosition" ), "end",
|
2014-01-22 17:02:32 +00:00
|
|
|
"Icons secondary option sets iconPosition option to end on init" );
|
|
|
|
} );
|
|
|
|
|
|
|
|
} );
|