1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
define( [
"qunit",
"jquery",
"ui/widgets/button"
], function( QUnit, $ ) {
QUnit.module( "Button (deprecated): core" );
QUnit.test( "Calling button on a checkbox input calls checkboxradio widget", function( assert ) {
var checkbox = $( "#checkbox01" );
assert.expect( 2 );
checkbox.button();
assert.ok( !!checkbox.checkboxradio( "instance" ),
"Calling button on a checkbox creates checkboxradio instance" );
assert.ok( !checkbox.checkboxradio( "option", "icon" ),
"Calling button on a checkbox sets the checkboxradio icon option to false" );
} );
QUnit.test( "Calling buttonset calls controlgroup", function( assert ) {
var controlgroup = $( ".buttonset" );
assert.expect( 1 );
controlgroup.buttonset();
assert.ok( controlgroup.is( ":ui-controlgroup" ), "Calling buttonset creates controlgroup instance" );
} );
QUnit.module( "Button (deprecated): methods" );
QUnit.test( "destroy", function( assert ) {
assert.expect( 1 );
assert.domEqual( "#checkbox02", function() {
$( "#checkbox02" ).button().button( "destroy" );
} );
} );
QUnit.test( "refresh: Ensure disabled state is preserved correctly.", function( assert ) {
assert.expect( 5 );
var element = null;
element = $( "#checkbox02" );
element.button( { disabled: true } ).button( "refresh" );
assert.ok( element.button( "option", "disabled" ), "Checkboxes should remain disabled after refresh" );
assert.ok( element.prop( "disabled" ), "Input remains disabled after refresh" );
element = $( "#radio02" );
element.button( { disabled: true } ).button( "refresh" );
assert.ok( element.button( "option", "disabled" ), "Radio buttons should remain disabled after refresh" );
element = $( "#checkbox02" );
element.button( { disabled: true } ).prop( "disabled", false ).button( "refresh" );
assert.ok( !element.button( "option", "disabled" ), "Changing a checkbox's disabled property should update the state after refresh." );
element = $( "#radio02" );
element.button( { disabled: true } ).prop( "disabled", false ).button( "refresh" );
assert.ok( !element.button( "option", "disabled" ), "Changing a radio button's disabled property should update the state after refresh." );
} );
QUnit.module( "button (deprecated): options" );
QUnit.test( "Setting items option on buttonset sets the button properties on the items option", function( assert ) {
assert.expect( 2 );
var controlgroup = $( ".buttonset" );
controlgroup.buttonset( { items: "bar" } );
assert.equal( controlgroup.controlgroup( "option", "items.button" ), "bar",
"items.button set when setting items option on init on buttonset" );
controlgroup.buttonset( "option", "items", "foo" );
assert.equal( controlgroup.controlgroup( "option", "items.button" ), "foo",
"items.button set when setting items option on buttonset" );
} );
QUnit.test( "disabled, null", function( assert ) {
assert.expect( 2 );
$( "#radio02" ).prop( "disabled", true ).button( { disabled: null } );
assert.deepEqual( $( "#radio02" ).button( "option", "disabled" ), true,
"disabled option set to true" );
assert.deepEqual( true, $( "#radio02" ).prop( "disabled" ), "element is not disabled" );
} );
QUnit.test( "text / showLabel options proxied", function( assert ) {
assert.expect( 8 );
var button = $( "#button" );
button.button( {
text: false,
icon: "ui-icon-gear"
} );
assert.equal( button.button( "option", "showLabel" ), false,
"Setting the text option to false sets the showLabel option to false on init" );
button.button( "option", "showLabel", true );
assert.equal( button.button( "option", "text" ), true,
"Setting showLabel true with option method sets text option to true" );
button.button( "option", "text", false );
assert.equal( button.button( "option", "showLabel" ), false,
"Setting text false with option method sets showLabel option to false" );
button.button( "option", "text", true );
assert.equal( button.button( "option", "showLabel" ), true,
"Setting text true with option method sets showLabel option to true" );
button.button( "option", "showLabel", false );
assert.equal( button.button( "option", "text" ), false,
"Setting showLabel false with option method sets text option to false" );
button.button( "destroy" );
button.button( {
text: true,
icon: "ui-icon-gear"
} );
assert.equal( button.button( "option", "showLabel" ), true,
"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"
} );
assert.equal( button.button( "option", "text" ), true,
"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"
} );
assert.equal( button.button( "option", "text" ), false,
"Setting the showLabel option to false sets the text option to false on init" );
} );
QUnit.test( "icon / icons options properly proxied", function( assert ) {
assert.expect( 10 );
var button = $( "#button" );
button.button( {
icon: "foo"
} );
assert.equal( button.button( "option", "icons.primary" ), "foo",
"Icon option properly proxied on init" );
button.button( {
icon: "bar"
} );
assert.equal( button.button( "option", "icons.primary" ), "bar",
"Icon option properly proxied with option method" );
button.button( {
icons: {
primary: "foo"
}
} );
assert.equal( button.button( "option", "icon" ), "foo",
"Icons primary option properly proxied with option method" );
assert.equal( button.button( "option", "iconPosition" ), "beginning",
"Icons primary option sets iconPosition option to beginning" );
button.button( {
icons: {
secondary: "bar"
}
} );
assert.equal( button.button( "option", "icon" ), "bar",
"Icons secondary option properly proxied with option method" );
assert.equal( button.button( "option", "iconPosition" ), "end",
"Icons secondary option sets iconPosition option to end" );
button.button( "destroy" );
button.button( {
icons: {
primary: "foo"
}
} );
assert.equal( button.button( "option", "icon" ), "foo",
"Icons primary option properly proxied on init" );
assert.equal( button.button( "option", "iconPosition" ), "beginning",
"Icons primary option sets iconPosition option to beginning on init" );
button.button( {
icons: {
secondary: "bar"
}
} );
assert.equal( button.button( "option", "icon" ), "bar",
"Icons secondary option properly proxied on init" );
assert.equal( button.button( "option", "iconPosition" ), "end",
"Icons secondary option sets iconPosition option to end on init" );
} );
} );
|