jquery-ui/tests/unit/dialog/deprecated.js
Scott González 6c754b4b5b Dialog: Support deprecated button options
Fixes #15016
Closes gh-1723
2016-07-25 08:38:51 -04:00

62 lines
1.9 KiB
JavaScript

define( [
"qunit",
"jquery",
"ui/widgets/dialog"
], function( QUnit, $ ) {
QUnit.module( "dialog (deprecated): options" );
QUnit.test( "dialogClass", function( assert ) {
assert.expect( 5 );
var element = $( "<div>" ).dialog(),
widget = element.dialog( "widget" );
assert.lacksClasses( widget, "foo", "dialogClass not specified. class not added" );
element.remove();
element = $( "<div>" ).dialog( { dialogClass: "foo" } );
widget = element.dialog( "widget" );
assert.hasClasses( widget, "foo", "dialogClass in init, foo class added" );
element.dialog( "option", "dialogClass", "foobar" );
assert.lacksClasses( widget, "foo", "dialogClass changed, previous one was removed" );
assert.hasClasses( widget, "foobar", "dialogClass changed, new one was added" );
element.remove();
element = $( "<div>" ).dialog( { dialogClass: "foo bar" } );
widget = element.dialog( "widget" );
assert.hasClasses( widget, "foo bar", "dialogClass in init, two classes." );
element.remove();
} );
QUnit.test( "buttons - deprecated options", function( assert ) {
assert.expect( 7 );
var buttons,
element = $( "<div></div>" ).dialog( {
buttons: [
{
html: "a button",
"class": "additional-class",
id: "my-button-id",
click: function() {
assert.equal( this, element[ 0 ], "correct context" );
},
icons: { primary: "ui-icon-cancel" },
text: false
}
]
} );
buttons = element.dialog( "widget" ).find( ".ui-dialog-buttonpane button" );
assert.equal( buttons.length, 1, "correct number of buttons" );
assert.equal( buttons.attr( "id" ), "my-button-id", "correct id" );
assert.equal( $.trim( buttons.text() ), "a button", "correct label" );
assert.hasClasses( buttons, "additional-class" );
assert.deepEqual( buttons.button( "option", "icon" ), "ui-icon-cancel" );
assert.equal( buttons.button( "option", "showLabel" ), false );
buttons.trigger( "click" );
element.remove();
} );
} );