mirror of
https://github.com/jquery/jquery-ui.git
synced 2026-05-13 03:01:39 -04:00
Button: Shift to no globals
This commit is contained in:
@@ -1,23 +1,25 @@
|
||||
define( [
|
||||
"qunit",
|
||||
"jquery",
|
||||
"ui/safe-active-element",
|
||||
"ui/widgets/button"
|
||||
], function( $ ) {
|
||||
], function( QUnit, $ ) {
|
||||
|
||||
module( "Button: core" );
|
||||
QUnit.module( "Button: core" );
|
||||
|
||||
asyncTest( "Disabled button loses focus", function() {
|
||||
expect( 2 );
|
||||
QUnit.test( "Disabled button loses focus", function( assert ) {
|
||||
var ready = assert.async();
|
||||
assert.expect( 2 );
|
||||
var element = $( "#button" ).button();
|
||||
|
||||
element.focus();
|
||||
setTimeout( function() {
|
||||
|
||||
equal( element[ 0 ], $.ui.safeActiveElement( document ), "Button is focused" );
|
||||
assert.equal( element[ 0 ], $.ui.safeActiveElement( document ), "Button is focused" );
|
||||
|
||||
element.button( "disable" );
|
||||
notEqual( element[ 0 ], $.ui.safeActiveElement( document ), "Button has had focus removed" );
|
||||
start();
|
||||
assert.notEqual( element[ 0 ], $.ui.safeActiveElement( document ), "Button has had focus removed" );
|
||||
ready();
|
||||
} );
|
||||
} );
|
||||
|
||||
|
||||
@@ -1,134 +1,135 @@
|
||||
define( [
|
||||
"qunit",
|
||||
"jquery",
|
||||
"ui/widgets/button"
|
||||
], function( $ ) {
|
||||
], function( QUnit, $ ) {
|
||||
|
||||
module( "Button (deprecated): core" );
|
||||
QUnit.module( "Button (deprecated): core" );
|
||||
|
||||
test( "Calling button on a checkbox input calls checkboxradio widget", function() {
|
||||
QUnit.test( "Calling button on a checkbox input calls checkboxradio widget", function( assert ) {
|
||||
var checkbox = $( "#checkbox01" );
|
||||
|
||||
expect( 2 );
|
||||
assert.expect( 2 );
|
||||
checkbox.button();
|
||||
|
||||
ok( !!checkbox.checkboxradio( "instance" ),
|
||||
assert.ok( !!checkbox.checkboxradio( "instance" ),
|
||||
"Calling button on a checkbox creates checkboxradio instance" );
|
||||
ok( !checkbox.checkboxradio( "option", "icon" ),
|
||||
assert.ok( !checkbox.checkboxradio( "option", "icon" ),
|
||||
"Calling button on a checkbox sets the checkboxradio icon option to false" );
|
||||
} );
|
||||
|
||||
test( "Calling buttonset calls controlgroup", function() {
|
||||
QUnit.test( "Calling buttonset calls controlgroup", function( assert ) {
|
||||
var controlgroup = $( ".buttonset" );
|
||||
|
||||
expect( 1 );
|
||||
assert.expect( 1 );
|
||||
controlgroup.buttonset();
|
||||
|
||||
ok( controlgroup.is( ":ui-controlgroup" ), "Calling buttonset creates controlgroup instance" );
|
||||
assert.ok( controlgroup.is( ":ui-controlgroup" ), "Calling buttonset creates controlgroup instance" );
|
||||
} );
|
||||
|
||||
module( "Button (deprecated): methods" );
|
||||
QUnit.module( "Button (deprecated): methods" );
|
||||
|
||||
test( "destroy", function( assert ) {
|
||||
expect( 1 );
|
||||
QUnit.test( "destroy", function( assert ) {
|
||||
assert.expect( 1 );
|
||||
assert.domEqual( "#checkbox02", function() {
|
||||
$( "#checkbox02" ).button().button( "destroy" );
|
||||
} );
|
||||
} );
|
||||
|
||||
test( "refresh: Ensure disabled state is preserved correctly.", function() {
|
||||
expect( 5 );
|
||||
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" );
|
||||
ok( element.button( "option", "disabled" ), "Checkboxes should remain disabled after refresh" );
|
||||
ok( element.prop( "disabled" ), "Input remains disabled after 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" );
|
||||
ok( element.button( "option", "disabled" ), "Radio buttons should remain disabled after 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" );
|
||||
ok( !element.button( "option", "disabled" ), "Changing a checkbox's disabled property should update the state after 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" );
|
||||
ok( !element.button( "option", "disabled" ), "Changing a radio button's disabled property should update the state after refresh." );
|
||||
assert.ok( !element.button( "option", "disabled" ), "Changing a radio button's disabled property should update the state after refresh." );
|
||||
|
||||
} );
|
||||
|
||||
module( "button (deprecated): options" );
|
||||
QUnit.module( "button (deprecated): options" );
|
||||
|
||||
test( "Setting items option on buttonset sets the button properties on the items option", function() {
|
||||
expect( 2 );
|
||||
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" } );
|
||||
equal( controlgroup.controlgroup( "option", "items.button" ), "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" );
|
||||
equal( controlgroup.controlgroup( "option", "items.button" ), "foo",
|
||||
assert.equal( controlgroup.controlgroup( "option", "items.button" ), "foo",
|
||||
"items.button set when setting items option on buttonset" );
|
||||
} );
|
||||
|
||||
test( "disabled, null", function() {
|
||||
expect( 2 );
|
||||
QUnit.test( "disabled, null", function( assert ) {
|
||||
assert.expect( 2 );
|
||||
|
||||
$( "#radio02" ).prop( "disabled", true ).button( { disabled: null } );
|
||||
deepEqual( $( "#radio02" ).button( "option", "disabled" ), true,
|
||||
assert.deepEqual( $( "#radio02" ).button( "option", "disabled" ), true,
|
||||
"disabled option set to true" );
|
||||
deepEqual( true, $( "#radio02" ).prop( "disabled" ), "element is not disabled" );
|
||||
assert.deepEqual( true, $( "#radio02" ).prop( "disabled" ), "element is not disabled" );
|
||||
} );
|
||||
|
||||
test( "text / showLabel options proxied", function() {
|
||||
expect( 8 );
|
||||
QUnit.test( "text / showLabel options proxied", function( assert ) {
|
||||
assert.expect( 8 );
|
||||
var button = $( "#button" );
|
||||
button.button( {
|
||||
text: false,
|
||||
icon: "ui-icon-gear"
|
||||
} );
|
||||
equal( button.button( "option", "showLabel" ), false,
|
||||
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 );
|
||||
equal( button.button( "option", "text" ), true,
|
||||
assert.equal( button.button( "option", "text" ), true,
|
||||
"Setting showLabel true with option method sets text option to true" );
|
||||
button.button( "option", "text", false );
|
||||
equal( button.button( "option", "showLabel" ), false,
|
||||
assert.equal( button.button( "option", "showLabel" ), false,
|
||||
"Setting text false with option method sets showLabel option to false" );
|
||||
button.button( "option", "text", true );
|
||||
equal( button.button( "option", "showLabel" ), true,
|
||||
assert.equal( button.button( "option", "showLabel" ), true,
|
||||
"Setting text true with option method sets showLabel option to true" );
|
||||
button.button( "option", "showLabel", false );
|
||||
equal( button.button( "option", "text" ), 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"
|
||||
} );
|
||||
equal( button.button( "option", "showLabel" ), true,
|
||||
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"
|
||||
} );
|
||||
equal( button.button( "option", "text" ), true,
|
||||
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"
|
||||
} );
|
||||
equal( button.button( "option", "text" ), false,
|
||||
assert.equal( button.button( "option", "text" ), false,
|
||||
"Setting the showLabel option to false sets the text option to false on init" );
|
||||
} );
|
||||
|
||||
test( "icon / icons options properly proxied", function() {
|
||||
expect( 10 );
|
||||
QUnit.test( "icon / icons options properly proxied", function( assert ) {
|
||||
assert.expect( 10 );
|
||||
|
||||
var button = $( "#button" );
|
||||
|
||||
@@ -136,14 +137,14 @@ test( "icon / icons options properly proxied", function() {
|
||||
icon: "foo"
|
||||
} );
|
||||
|
||||
equal( button.button( "option", "icons.primary" ), "foo",
|
||||
assert.equal( button.button( "option", "icons.primary" ), "foo",
|
||||
"Icon option properly proxied on init" );
|
||||
|
||||
button.button( {
|
||||
icon: "bar"
|
||||
} );
|
||||
|
||||
equal( button.button( "option", "icons.primary" ), "bar",
|
||||
assert.equal( button.button( "option", "icons.primary" ), "bar",
|
||||
"Icon option properly proxied with option method" );
|
||||
|
||||
button.button( {
|
||||
@@ -152,9 +153,9 @@ test( "icon / icons options properly proxied", function() {
|
||||
}
|
||||
} );
|
||||
|
||||
equal( button.button( "option", "icon" ), "foo",
|
||||
assert.equal( button.button( "option", "icon" ), "foo",
|
||||
"Icons primary option properly proxied with option method" );
|
||||
equal( button.button( "option", "iconPosition" ), "beginning",
|
||||
assert.equal( button.button( "option", "iconPosition" ), "beginning",
|
||||
"Icons primary option sets iconPosition option to beginning" );
|
||||
|
||||
button.button( {
|
||||
@@ -163,9 +164,9 @@ test( "icon / icons options properly proxied", function() {
|
||||
}
|
||||
} );
|
||||
|
||||
equal( button.button( "option", "icon" ), "bar",
|
||||
assert.equal( button.button( "option", "icon" ), "bar",
|
||||
"Icons secondary option properly proxied with option method" );
|
||||
equal( button.button( "option", "iconPosition" ), "end",
|
||||
assert.equal( button.button( "option", "iconPosition" ), "end",
|
||||
"Icons secondary option sets iconPosition option to end" );
|
||||
|
||||
button.button( "destroy" );
|
||||
@@ -176,9 +177,9 @@ test( "icon / icons options properly proxied", function() {
|
||||
}
|
||||
} );
|
||||
|
||||
equal( button.button( "option", "icon" ), "foo",
|
||||
assert.equal( button.button( "option", "icon" ), "foo",
|
||||
"Icons primary option properly proxied on init" );
|
||||
equal( button.button( "option", "iconPosition" ), "beginning",
|
||||
assert.equal( button.button( "option", "iconPosition" ), "beginning",
|
||||
"Icons primary option sets iconPosition option to beginning on init" );
|
||||
|
||||
button.button( {
|
||||
@@ -187,9 +188,9 @@ test( "icon / icons options properly proxied", function() {
|
||||
}
|
||||
} );
|
||||
|
||||
equal( button.button( "option", "icon" ), "bar",
|
||||
assert.equal( button.button( "option", "icon" ), "bar",
|
||||
"Icons secondary option properly proxied on init" );
|
||||
equal( button.button( "option", "iconPosition" ), "end",
|
||||
assert.equal( button.button( "option", "iconPosition" ), "end",
|
||||
"Icons secondary option sets iconPosition option to end on init" );
|
||||
} );
|
||||
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
define( [
|
||||
"qunit",
|
||||
"jquery",
|
||||
"ui/widgets/button"
|
||||
], function( $ ) {
|
||||
], function( QUnit, $ ) {
|
||||
|
||||
module( "Button: events" );
|
||||
QUnit.module( "Button: events" );
|
||||
|
||||
asyncTest( "Anchor recieves click event when spacebar is pressed", function() {
|
||||
expect( 1 );
|
||||
QUnit.test( "Anchor recieves click event when spacebar is pressed", function( assert ) {
|
||||
var ready = assert.async();
|
||||
assert.expect( 1 );
|
||||
var element = $( "#anchor-button" ).button();
|
||||
|
||||
element.on( "click", function( event ) {
|
||||
event.preventDefault();
|
||||
ok( true, "click occcured as a result of spacebar" );
|
||||
start();
|
||||
assert.ok( true, "click occcured as a result of spacebar" );
|
||||
ready();
|
||||
} );
|
||||
|
||||
element.trigger( $.Event( "keyup", { keyCode: $.ui.keyCode.SPACE } ) );
|
||||
|
||||
@@ -1,32 +1,33 @@
|
||||
define( [
|
||||
"qunit",
|
||||
"jquery",
|
||||
"ui/widgets/button"
|
||||
], function( $ ) {
|
||||
], function( QUnit, $ ) {
|
||||
|
||||
module( "Button: methods" );
|
||||
QUnit.module( "Button: methods" );
|
||||
|
||||
test( "destroy", function( assert ) {
|
||||
expect( 1 );
|
||||
QUnit.test( "destroy", function( assert ) {
|
||||
assert.expect( 1 );
|
||||
assert.domEqual( "#button", function() {
|
||||
$( "#button" ).button().button( "destroy" );
|
||||
} );
|
||||
} );
|
||||
|
||||
test( "refresh: Ensure disabled state is preserved correctly.", function() {
|
||||
expect( 3 );
|
||||
QUnit.test( "refresh: Ensure disabled state is preserved correctly.", function( assert ) {
|
||||
assert.expect( 3 );
|
||||
|
||||
var element = $( "<a href='#'></a>" );
|
||||
element.button( { disabled: true } ).button( "refresh" );
|
||||
ok( element.button( "option", "disabled" ),
|
||||
assert.ok( element.button( "option", "disabled" ),
|
||||
"Anchor button should remain disabled after refresh" );
|
||||
|
||||
element = $( "<button></button>" );
|
||||
element.button( { disabled: true } ).button( "refresh" );
|
||||
ok( element.button( "option", "disabled" ), "<button> should remain disabled after refresh" );
|
||||
assert.ok( element.button( "option", "disabled" ), "<button> should remain disabled after refresh" );
|
||||
|
||||
element = $( "<button></button>" );
|
||||
element.button( { disabled: true } ).prop( "disabled", false ).button( "refresh" );
|
||||
ok( !element.button( "option", "disabled" ),
|
||||
assert.ok( !element.button( "option", "disabled" ),
|
||||
"Changing a <button>'s disabled property should update the state after refresh." );
|
||||
|
||||
} );
|
||||
|
||||
@@ -1,66 +1,67 @@
|
||||
define( [
|
||||
"qunit",
|
||||
"jquery",
|
||||
"ui/widgets/button"
|
||||
], function( $ ) {
|
||||
], function( QUnit, $ ) {
|
||||
|
||||
module( "button: options" );
|
||||
QUnit.module( "button: options" );
|
||||
|
||||
test( "disabled, explicit value", function( assert ) {
|
||||
expect( 8 );
|
||||
QUnit.test( "disabled, explicit value", function( assert ) {
|
||||
assert.expect( 8 );
|
||||
|
||||
var element = $( "#button" ).button( { disabled: false } );
|
||||
|
||||
strictEqual( element.button( "option", "disabled" ), false, "disabled option set to false" );
|
||||
strictEqual( element.prop( "disabled" ), false, "Disabled property is false" );
|
||||
assert.strictEqual( element.button( "option", "disabled" ), false, "disabled option set to false" );
|
||||
assert.strictEqual( element.prop( "disabled" ), false, "Disabled property is false" );
|
||||
|
||||
assert.lacksClasses( element.button( "widget" ), "ui-state-disabled ui-button-disabled" );
|
||||
|
||||
element = $( "#button" ).button( { disabled: true } );
|
||||
|
||||
assert.hasClasses( element.button( "widget" ), "ui-state-disabled" );
|
||||
strictEqual( element.button( "widget" ).attr( "aria-disabled" ), undefined,
|
||||
assert.strictEqual( element.button( "widget" ).attr( "aria-disabled" ), undefined,
|
||||
"element does not get aria-disabled" );
|
||||
assert.hasClasses( element.button( "widget" ), "ui-button-disabled" );
|
||||
|
||||
strictEqual( element.button( "option", "disabled" ), true, "disabled option set to true" );
|
||||
strictEqual( element.prop( "disabled" ), true, "Disabled property is set" );
|
||||
assert.strictEqual( element.button( "option", "disabled" ), true, "disabled option set to true" );
|
||||
assert.strictEqual( element.prop( "disabled" ), true, "Disabled property is set" );
|
||||
} );
|
||||
|
||||
// We are testing the default here because the default null is a special value which means to check
|
||||
// the DOM. We need to make sure this happens correctly. Checking the options should never return
|
||||
// null, it should always be true or false.
|
||||
test( "disabled, null", function() {
|
||||
expect( 4 );
|
||||
QUnit.test( "disabled, null", function( assert ) {
|
||||
assert.expect( 4 );
|
||||
var element = $( "#button" ),
|
||||
elementDisabled = $( "#button-disabled" );
|
||||
|
||||
element.add( elementDisabled ).button( { disabled: null } );
|
||||
strictEqual( element.button( "option", "disabled" ), false, "disabled option set to false" );
|
||||
strictEqual( element.prop( "disabled" ), false, "element is disabled" );
|
||||
strictEqual( elementDisabled.button( "option", "disabled" ), true,
|
||||
assert.strictEqual( element.button( "option", "disabled" ), false, "disabled option set to false" );
|
||||
assert.strictEqual( element.prop( "disabled" ), false, "element is disabled" );
|
||||
assert.strictEqual( elementDisabled.button( "option", "disabled" ), true,
|
||||
"disabled option set to true" );
|
||||
strictEqual( elementDisabled.prop( "disabled" ), true, "element is disabled" );
|
||||
assert.strictEqual( elementDisabled.prop( "disabled" ), true, "element is disabled" );
|
||||
} );
|
||||
|
||||
test( "showLabel, false, without icon", function( assert ) {
|
||||
expect( 4 );
|
||||
QUnit.test( "showLabel, false, without icon", function( assert ) {
|
||||
assert.expect( 4 );
|
||||
|
||||
var button = $( "#button" ).button( {
|
||||
showLabel: false
|
||||
} );
|
||||
|
||||
assert.lacksClasses( button, "ui-button-icon-only" );
|
||||
strictEqual( button.button( "option", "showLabel" ), true,
|
||||
assert.strictEqual( button.button( "option", "showLabel" ), true,
|
||||
"showLabel false only allowed if icon true" );
|
||||
|
||||
button.button( "option", "showLabel", false );
|
||||
assert.lacksClasses( button, "ui-button-icon-only" );
|
||||
strictEqual( button.button( "option", "showLabel" ), true,
|
||||
assert.strictEqual( button.button( "option", "showLabel" ), true,
|
||||
"showLabel false only allowed if icon true" );
|
||||
} );
|
||||
|
||||
test( "showLabel, false, with icon", function( assert ) {
|
||||
expect( 1 );
|
||||
QUnit.test( "showLabel, false, with icon", function( assert ) {
|
||||
assert.expect( 1 );
|
||||
var button = $( "#button" ).button( {
|
||||
showLabel: false,
|
||||
icon: "iconclass"
|
||||
@@ -68,53 +69,53 @@ test( "showLabel, false, with icon", function( assert ) {
|
||||
assert.hasClasses( button, "ui-button ui-corner-all ui-widget ui-button-icon-only" );
|
||||
} );
|
||||
|
||||
test( "label, default", function() {
|
||||
expect( 2 );
|
||||
QUnit.test( "label, default", function( assert ) {
|
||||
assert.expect( 2 );
|
||||
var button = $( "#button" ).button();
|
||||
|
||||
deepEqual( button.text(), "Label" );
|
||||
deepEqual( button.button( "option", "label" ), "Label" );
|
||||
assert.deepEqual( button.text(), "Label" );
|
||||
assert.deepEqual( button.button( "option", "label" ), "Label" );
|
||||
} );
|
||||
|
||||
test( "label, with html markup", function() {
|
||||
expect( 3 );
|
||||
QUnit.test( "label, with html markup", function( assert ) {
|
||||
assert.expect( 3 );
|
||||
var button = $( "#button2" ).button();
|
||||
|
||||
deepEqual( button.text(), "label with span" );
|
||||
deepEqual( button.html().toLowerCase(), "label <span>with span</span>" );
|
||||
deepEqual( button.button( "option", "label" ).toLowerCase(), "label <span>with span</span>" );
|
||||
assert.deepEqual( button.text(), "label with span" );
|
||||
assert.deepEqual( button.html().toLowerCase(), "label <span>with span</span>" );
|
||||
assert.deepEqual( button.button( "option", "label" ).toLowerCase(), "label <span>with span</span>" );
|
||||
} );
|
||||
|
||||
test( "label, explicit value", function() {
|
||||
expect( 2 );
|
||||
QUnit.test( "label, explicit value", function( assert ) {
|
||||
assert.expect( 2 );
|
||||
var button = $( "#button" ).button( {
|
||||
label: "xxx"
|
||||
} );
|
||||
|
||||
deepEqual( button.text(), "xxx" );
|
||||
deepEqual( button.button( "option", "label" ), "xxx" );
|
||||
assert.deepEqual( button.text(), "xxx" );
|
||||
assert.deepEqual( button.button( "option", "label" ), "xxx" );
|
||||
} );
|
||||
|
||||
test( "label, default, with input type submit", function() {
|
||||
expect( 2 );
|
||||
QUnit.test( "label, default, with input type submit", function( assert ) {
|
||||
assert.expect( 2 );
|
||||
var button = $( "#submit" ).button();
|
||||
|
||||
deepEqual( button.val(), "Label" );
|
||||
deepEqual( button.button( "option", "label" ), "Label" );
|
||||
assert.deepEqual( button.val(), "Label" );
|
||||
assert.deepEqual( button.button( "option", "label" ), "Label" );
|
||||
} );
|
||||
|
||||
test( "label, explicit value, with input type submit", function() {
|
||||
expect( 2 );
|
||||
QUnit.test( "label, explicit value, with input type submit", function( assert ) {
|
||||
assert.expect( 2 );
|
||||
var button = $( "#submit" ).button( {
|
||||
label: "xxx"
|
||||
} );
|
||||
|
||||
deepEqual( button.val(), "xxx" );
|
||||
deepEqual( button.button( "option", "label" ), "xxx" );
|
||||
assert.deepEqual( button.val(), "xxx" );
|
||||
assert.deepEqual( button.button( "option", "label" ), "xxx" );
|
||||
} );
|
||||
|
||||
test( "icon", function( assert ) {
|
||||
expect( 4 );
|
||||
QUnit.test( "icon", function( assert ) {
|
||||
assert.expect( 4 );
|
||||
var button = $( "#button" ).button( {
|
||||
showLabel: false,
|
||||
icon: "iconclass"
|
||||
@@ -122,18 +123,18 @@ test( "icon", function( assert ) {
|
||||
icon = button.find( ".ui-icon" );
|
||||
|
||||
assert.hasClasses( icon, "iconclass" );
|
||||
equal( icon.length, 1, "button with icon option set has icon" );
|
||||
assert.equal( icon.length, 1, "button with icon option set has icon" );
|
||||
|
||||
button.button( "option", "icon", false );
|
||||
equal( button.find( ".ui-icon" ).length, 0, "setting icon to false removes the icon" );
|
||||
assert.equal( button.find( ".ui-icon" ).length, 0, "setting icon to false removes the icon" );
|
||||
|
||||
button.button( "option", "icon", "iconclass" );
|
||||
ok( button.find( ".ui-icon" ).length, "setting icon to a value adds the icon" );
|
||||
assert.ok( button.find( ".ui-icon" ).length, "setting icon to a value adds the icon" );
|
||||
|
||||
} );
|
||||
|
||||
test( "icon position", function( assert ) {
|
||||
expect( 22 );
|
||||
QUnit.test( "icon position", function( assert ) {
|
||||
assert.expect( 22 );
|
||||
|
||||
var button = $( "#button" ).button( {
|
||||
icon: "ui-icon-gear"
|
||||
@@ -141,41 +142,41 @@ test( "icon position", function( assert ) {
|
||||
icon = button.find( ".ui-icon" ),
|
||||
space = button.find( ".ui-button-icon-space" );
|
||||
|
||||
equal( icon.length, 1, "button with icon option set has icon" );
|
||||
equal( button.button( "option", "iconPosition" ), "beginning",
|
||||
assert.equal( icon.length, 1, "button with icon option set has icon" );
|
||||
assert.equal( button.button( "option", "iconPosition" ), "beginning",
|
||||
"Button has iconPosition beginning by default" );
|
||||
equal( button.contents()[ 0 ], icon[ 0 ], "icon is prepended when position is begining" );
|
||||
equal( icon.next()[ 0 ], space[ 0 ], "icon is followed by a space when position is begining" );
|
||||
equal( space.length, 1,
|
||||
assert.equal( button.contents()[ 0 ], icon[ 0 ], "icon is prepended when position is begining" );
|
||||
assert.equal( icon.next()[ 0 ], space[ 0 ], "icon is followed by a space when position is begining" );
|
||||
assert.equal( space.length, 1,
|
||||
"ui-button-icon-space contains a breaking space iconPosition:beginning" );
|
||||
assert.lacksClasses( icon, "ui-widget-icon-block" );
|
||||
|
||||
button.button( "option", "iconPosition", "end" );
|
||||
icon = button.find( ".ui-icon" );
|
||||
space = button.find( ".ui-button-icon-space" );
|
||||
equal( icon.length, 1, "Changing position to end does not re-create or duplicate icon" );
|
||||
equal( button.button( "option", "iconPosition" ), "end", "Button has iconPosition end" );
|
||||
equal( button.contents().last()[ 0 ], icon[ 0 ], "icon is appended when position is end" );
|
||||
equal( icon.prev()[ 0 ], space[ 0 ], "icon is preceeded by a space when position is end" );
|
||||
equal( space.length, 1,
|
||||
assert.equal( icon.length, 1, "Changing position to end does not re-create or duplicate icon" );
|
||||
assert.equal( button.button( "option", "iconPosition" ), "end", "Button has iconPosition end" );
|
||||
assert.equal( button.contents().last()[ 0 ], icon[ 0 ], "icon is appended when position is end" );
|
||||
assert.equal( icon.prev()[ 0 ], space[ 0 ], "icon is preceeded by a space when position is end" );
|
||||
assert.equal( space.length, 1,
|
||||
"ui-button-icon-space contains a breaking space iconPosition:beginning" );
|
||||
assert.lacksClasses( icon, "ui-widget-icon-block" );
|
||||
|
||||
button.button( "option", "iconPosition", "top" );
|
||||
icon = button.find( ".ui-icon" );
|
||||
equal( icon.length, 1, "Changing position to top does not re-create or duplicate icon" );
|
||||
equal( button.button( "option", "iconPosition" ), "top", "Button has iconPosition top" );
|
||||
equal( button.contents()[ 0 ], icon[ 0 ], "icon is prepended when position is top" );
|
||||
ok( !button.find( "ui-button-icon-space" ).length,
|
||||
assert.equal( icon.length, 1, "Changing position to top does not re-create or duplicate icon" );
|
||||
assert.equal( button.button( "option", "iconPosition" ), "top", "Button has iconPosition top" );
|
||||
assert.equal( button.contents()[ 0 ], icon[ 0 ], "icon is prepended when position is top" );
|
||||
assert.ok( !button.find( "ui-button-icon-space" ).length,
|
||||
"Button should not have an iconSpace with position: top" );
|
||||
assert.hasClasses( icon, "ui-widget-icon-block" );
|
||||
|
||||
button.button( "option", "iconPosition", "bottom" );
|
||||
icon = button.find( ".ui-icon" );
|
||||
equal( icon.length, 1, "Changing position to bottom does not re-create or duplicate icon" );
|
||||
equal( button.button( "option", "iconPosition" ), "bottom", "Button has iconPosition top" );
|
||||
equal( button.contents().last()[ 0 ], icon[ 0 ], "icon is prepended when position is bottom" );
|
||||
ok( !button.find( "ui-button-icon-space" ).length,
|
||||
assert.equal( icon.length, 1, "Changing position to bottom does not re-create or duplicate icon" );
|
||||
assert.equal( button.button( "option", "iconPosition" ), "bottom", "Button has iconPosition top" );
|
||||
assert.equal( button.contents().last()[ 0 ], icon[ 0 ], "icon is prepended when position is bottom" );
|
||||
assert.ok( !button.find( "ui-button-icon-space" ).length,
|
||||
"Button should not have an iconSpace with position: bottom" );
|
||||
assert.hasClasses( icon, "ui-widget-icon-block" );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user