2014-08-23 03:39:35 +00:00
|
|
|
define( [
|
2016-04-03 14:56:10 +00:00
|
|
|
"qunit",
|
2014-08-23 03:39:35 +00:00
|
|
|
"jquery",
|
2015-08-09 04:30:34 +00:00
|
|
|
"ui/widgets/controlgroup",
|
|
|
|
"ui/widgets/checkboxradio",
|
|
|
|
"ui/widgets/selectmenu",
|
|
|
|
"ui/widgets/button"
|
2016-04-03 14:56:10 +00:00
|
|
|
], function( QUnit, $ ) {
|
2014-08-23 03:39:35 +00:00
|
|
|
|
2016-04-03 14:56:10 +00:00
|
|
|
QUnit.module( "Controlgroup: options" );
|
2014-08-23 03:39:35 +00:00
|
|
|
|
2016-04-03 14:56:10 +00:00
|
|
|
QUnit.test( "disabled", function( assert ) {
|
|
|
|
assert.expect( 4 );
|
2014-08-23 03:39:35 +00:00
|
|
|
var element = $( ".controlgroup" ).controlgroup().controlgroup( "option", "disabled", true );
|
|
|
|
assert.lacksClasses( element, "ui-state-disabled" );
|
2016-04-03 14:56:10 +00:00
|
|
|
assert.equal( element.find( ".ui-state-disabled" ).length, 6, "Child widgets are disabled" );
|
2014-08-23 03:39:35 +00:00
|
|
|
|
|
|
|
element.controlgroup( "option", "disabled", false );
|
|
|
|
assert.lacksClasses( element, "ui-state-disabled" );
|
2016-04-03 14:56:10 +00:00
|
|
|
assert.strictEqual( element.find( ".ui-state-disabled" ).length, 0, "Child widgets are not disabled" );
|
2014-08-23 03:39:35 +00:00
|
|
|
|
2015-09-11 14:48:51 +00:00
|
|
|
} );
|
2014-08-23 03:39:35 +00:00
|
|
|
|
2016-04-03 14:56:10 +00:00
|
|
|
QUnit.test( "items - null", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2015-09-11 14:48:51 +00:00
|
|
|
var element = $( ".controlgroup" ).controlgroup( {
|
2014-08-23 03:39:35 +00:00
|
|
|
items: {
|
|
|
|
"button": null,
|
|
|
|
"selectmenu": null,
|
|
|
|
"checkboxradio": null
|
|
|
|
}
|
2015-09-11 14:48:51 +00:00
|
|
|
} );
|
2014-08-23 03:39:35 +00:00
|
|
|
|
2016-04-03 14:56:10 +00:00
|
|
|
assert.strictEqual( element.children( ".ui-button" ).length, 0,
|
2014-08-23 03:39:35 +00:00
|
|
|
"Child widgets are not called when selector is null" );
|
|
|
|
|
|
|
|
element.controlgroup( "option", "items", {
|
|
|
|
"button": "button"
|
2015-09-11 14:48:51 +00:00
|
|
|
} );
|
2016-04-03 14:56:10 +00:00
|
|
|
assert.strictEqual( element.children( ".ui-button" ).length, 2,
|
2014-08-23 03:39:35 +00:00
|
|
|
"Correct child widgets are called when selector is updated" );
|
2015-09-11 14:48:51 +00:00
|
|
|
} );
|
2014-08-23 03:39:35 +00:00
|
|
|
|
2016-04-03 14:56:10 +00:00
|
|
|
QUnit.test( "items: custom selector", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2015-09-11 14:48:51 +00:00
|
|
|
var element = $( ".controlgroup" ).controlgroup( {
|
2014-08-23 03:39:35 +00:00
|
|
|
items: {
|
|
|
|
"button": ".button"
|
|
|
|
}
|
2015-09-11 14:48:51 +00:00
|
|
|
} );
|
2016-04-03 14:56:10 +00:00
|
|
|
assert.strictEqual( element.children( ".ui-button" ).length, 4,
|
2014-08-23 03:39:35 +00:00
|
|
|
"Correct child widgets are called when custom selector used" );
|
2015-09-11 14:48:51 +00:00
|
|
|
} );
|
2014-08-23 03:39:35 +00:00
|
|
|
|
|
|
|
$.widget( "ui.test", {
|
2015-09-11 14:48:51 +00:00
|
|
|
_create: function() {
|
2014-08-23 03:39:35 +00:00
|
|
|
this.element.addClass( "ui-test ui-button" );
|
|
|
|
},
|
|
|
|
|
|
|
|
// Controlgroup requires a refresh method to exist
|
|
|
|
refresh: $.noop
|
2015-09-11 14:48:51 +00:00
|
|
|
} );
|
2015-10-27 20:32:30 +00:00
|
|
|
|
2016-04-03 14:56:10 +00:00
|
|
|
QUnit.test( "items: custom widget", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2015-09-11 14:48:51 +00:00
|
|
|
var element = $( ".controlgroup" ).controlgroup( {
|
2014-08-23 03:39:35 +00:00
|
|
|
items: {
|
|
|
|
"test": ".test"
|
|
|
|
}
|
2015-09-11 14:48:51 +00:00
|
|
|
} );
|
2014-08-23 03:39:35 +00:00
|
|
|
|
2016-04-03 14:56:10 +00:00
|
|
|
assert.strictEqual( element.children( ".ui-button" ).length, 7,
|
2014-08-23 03:39:35 +00:00
|
|
|
"Correct child widgets are called when custom selector used" );
|
2016-04-03 14:56:10 +00:00
|
|
|
assert.strictEqual( element.children( ".ui-test" ).length, 1,
|
2014-08-23 03:39:35 +00:00
|
|
|
"Custom widget called" );
|
2015-09-11 14:48:51 +00:00
|
|
|
} );
|
2014-08-23 03:39:35 +00:00
|
|
|
|
2016-04-03 14:56:10 +00:00
|
|
|
QUnit.test( "onlyVisible", function( assert ) {
|
|
|
|
assert.expect( 4 );
|
2015-09-11 14:48:51 +00:00
|
|
|
var element = $( ".controlgroup" ).controlgroup( {
|
2015-09-30 13:38:42 +00:00
|
|
|
onlyVisible: false
|
2015-09-11 14:48:51 +00:00
|
|
|
} ),
|
2014-08-23 03:39:35 +00:00
|
|
|
buttons = element.children( ".ui-button" );
|
|
|
|
|
|
|
|
assert.lacksClassStart( buttons.eq( 1 ), "ui-corner" );
|
|
|
|
assert.hasClasses( buttons.eq( 0 ), "ui-corner-left",
|
2015-09-30 13:38:42 +00:00
|
|
|
"onlyVisible: false: First button hidden second button doesn't get a corner class" );
|
2014-08-23 03:39:35 +00:00
|
|
|
|
2015-09-30 13:38:42 +00:00
|
|
|
element.controlgroup( "option", "onlyVisible", true );
|
2014-08-23 03:39:35 +00:00
|
|
|
assert.lacksClassStart( buttons.eq( 0 ), "ui-corner" );
|
|
|
|
assert.hasClasses( buttons.eq( 1 ), "ui-corner-left",
|
2015-09-30 13:38:42 +00:00
|
|
|
"onlyVisible: true: First button is hidden second button get corner class" );
|
2015-09-11 14:48:51 +00:00
|
|
|
} );
|
2014-08-23 03:39:35 +00:00
|
|
|
|
2016-04-03 14:56:10 +00:00
|
|
|
QUnit.test( "direction", function( assert ) {
|
|
|
|
assert.expect( 6 );
|
2014-08-23 03:39:35 +00:00
|
|
|
var element = $( ".controlgroup" ).controlgroup(),
|
|
|
|
buttons = element.children( ".ui-button" ).filter( ":visible" );
|
|
|
|
|
|
|
|
assert.hasClasses( element, "ui-controlgroup-horizontal" );
|
|
|
|
assert.hasClasses( buttons.first(), "ui-corner-left" );
|
|
|
|
assert.hasClasses( buttons.last(), "ui-corner-right" );
|
|
|
|
|
|
|
|
element.controlgroup( "option", "direction", "vertical" );
|
|
|
|
assert.hasClasses( element, "ui-controlgroup-vertical" );
|
|
|
|
assert.hasClasses( buttons.first(), "ui-corner-top" );
|
|
|
|
assert.hasClasses( buttons.last(), "ui-corner-bottom" );
|
2015-09-11 14:48:51 +00:00
|
|
|
} );
|
2014-08-23 03:39:35 +00:00
|
|
|
|
|
|
|
} );
|