2015-04-06 18:40:47 +00:00
|
|
|
define( [
|
2016-04-06 13:16:23 +00:00
|
|
|
"qunit",
|
2015-04-06 18:40:47 +00:00
|
|
|
"jquery",
|
2015-07-15 02:06:31 +00:00
|
|
|
"ui/widgets/selectmenu"
|
2016-04-06 13:16:23 +00:00
|
|
|
], function( QUnit, $ ) {
|
2011-10-19 17:47:02 +00:00
|
|
|
|
2016-04-06 13:16:23 +00:00
|
|
|
QUnit.module( "selectmenu: core" );
|
2011-10-19 17:47:02 +00:00
|
|
|
|
2016-04-06 13:16:23 +00:00
|
|
|
QUnit.test( "markup structure", function( assert ) {
|
|
|
|
assert.expect( 7 );
|
2014-12-03 16:26:46 +00:00
|
|
|
|
|
|
|
var element = $( "#files" ).selectmenu(),
|
|
|
|
button = element.selectmenu( "widget" ),
|
2016-02-10 16:31:03 +00:00
|
|
|
icon = button.find( ".ui-icon" ),
|
2014-12-03 16:26:46 +00:00
|
|
|
menu = element.selectmenu( "menuWidget" ),
|
|
|
|
menuWrap = menu.parent();
|
|
|
|
|
2016-02-10 16:31:03 +00:00
|
|
|
assert.strictEqual( icon.length, 1, "Exactly one icon exists" );
|
|
|
|
assert.hasClasses( icon, "ui-selectmenu-icon" );
|
2014-12-03 16:26:46 +00:00
|
|
|
assert.hasClasses( button,
|
|
|
|
"ui-selectmenu-button ui-selectmenu-button-closed ui-widget" );
|
2015-09-16 05:50:13 +00:00
|
|
|
assert.lacksClasses( button, "ui-selectmenu-button-open ui-selectmenu-open" );
|
2014-12-03 16:26:46 +00:00
|
|
|
assert.hasClasses( menuWrap, "ui-selectmenu-menu" );
|
|
|
|
assert.lacksClasses( menuWrap, "ui-selectmenu-menu-open" );
|
2016-03-30 15:38:34 +00:00
|
|
|
assert.strictEqual( icon[ 0 ], button.children()[ 0 ], "Icon is first child of button" );
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
2014-12-03 16:26:46 +00:00
|
|
|
|
2016-04-06 13:16:23 +00:00
|
|
|
QUnit.test( "accessibility", function( assert ) {
|
|
|
|
var ready = assert.async();
|
2014-07-31 10:35:42 +00:00
|
|
|
var wrappers, button, menu,
|
|
|
|
element = $( "#speed" ).attr( "title", "A demo title" );
|
|
|
|
|
2015-08-24 12:50:24 +00:00
|
|
|
element.find( "option" ).each( function( index ) {
|
2014-07-31 10:35:42 +00:00
|
|
|
$( this ).attr( "title", "A demo title #" + index );
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
2014-07-31 10:35:42 +00:00
|
|
|
|
|
|
|
element.selectmenu();
|
|
|
|
button = element.selectmenu( "widget" );
|
|
|
|
menu = element.selectmenu( "menuWidget" );
|
2012-02-21 22:41:00 +00:00
|
|
|
|
2012-02-21 23:09:44 +00:00
|
|
|
button.simulate( "focus" );
|
2014-09-26 21:34:22 +00:00
|
|
|
wrappers = menu.find( "li.ui-menu-item .ui-menu-item-wrapper" );
|
2012-02-21 17:08:14 +00:00
|
|
|
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.expect( 13 + wrappers.length * 3 );
|
2012-02-21 17:08:14 +00:00
|
|
|
|
2015-08-24 12:50:24 +00:00
|
|
|
setTimeout( function() {
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( button.attr( "role" ), "combobox", "button role" );
|
|
|
|
assert.equal( button.attr( "aria-haspopup" ), "true", "button aria-haspopup" );
|
|
|
|
assert.equal( button.attr( "aria-expanded" ), "false", "button aria-expanded" );
|
|
|
|
assert.equal( button.attr( "aria-autocomplete" ), "list", "button aria-autocomplete" );
|
|
|
|
assert.equal( button.attr( "aria-owns" ), menu.attr( "id" ), "button aria-owns" );
|
|
|
|
assert.equal(
|
2013-04-30 22:33:37 +00:00
|
|
|
button.attr( "aria-labelledby" ),
|
2014-09-26 21:34:22 +00:00
|
|
|
wrappers.eq( element[ 0 ].selectedIndex ).attr( "id" ),
|
2013-04-30 22:33:37 +00:00
|
|
|
"button link aria-labelledby"
|
|
|
|
);
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( button.attr( "tabindex" ), 0, "button link tabindex" );
|
|
|
|
assert.equal( button.attr( "title" ), "A demo title", "button title" );
|
|
|
|
|
|
|
|
assert.equal( menu.attr( "role" ), "listbox", "menu role" );
|
|
|
|
assert.equal( menu.attr( "aria-labelledby" ), button.attr( "id" ), "menu aria-labelledby" );
|
|
|
|
assert.equal( menu.attr( "aria-hidden" ), "true", "menu aria-hidden" );
|
|
|
|
assert.equal( menu.attr( "tabindex" ), 0, "menu tabindex" );
|
|
|
|
assert.equal(
|
2013-04-30 22:33:37 +00:00
|
|
|
menu.attr( "aria-activedescendant" ),
|
2014-09-26 21:34:22 +00:00
|
|
|
wrappers.eq( element[ 0 ].selectedIndex ).attr( "id" ),
|
2013-04-30 22:33:37 +00:00
|
|
|
"menu aria-activedescendant"
|
|
|
|
);
|
2014-09-26 21:34:22 +00:00
|
|
|
$.each( wrappers, function( index ) {
|
2014-07-31 10:35:42 +00:00
|
|
|
var item = $( this );
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( item.attr( "role" ), "option", "menu item #" + index + " role" );
|
|
|
|
assert.equal( item.attr( "tabindex" ), -1, "menu item #" + index + " tabindex" );
|
|
|
|
assert.equal( item.attr( "title" ), "A demo title #" + index, "menu item #" + index + " title" );
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
2016-04-06 13:16:23 +00:00
|
|
|
ready();
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
|
|
|
} );
|
2011-11-21 20:54:04 +00:00
|
|
|
|
2016-04-06 13:16:23 +00:00
|
|
|
QUnit.test( "_renderButtonItem()", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2014-07-28 17:09:41 +00:00
|
|
|
|
|
|
|
var option,
|
|
|
|
element = $( "#speed" ).selectmenu(),
|
|
|
|
instance = element.selectmenu( "instance" ),
|
|
|
|
button = element.selectmenu( "widget" ),
|
|
|
|
menu = element.selectmenu( "menuWidget" );
|
|
|
|
|
|
|
|
instance._renderButtonItem = function( item ) {
|
|
|
|
var buttonItem = $( "<span>" );
|
|
|
|
this._setText( buttonItem, item.label + item.index );
|
|
|
|
|
|
|
|
return buttonItem;
|
|
|
|
};
|
|
|
|
|
|
|
|
element.selectmenu( "refresh" );
|
|
|
|
option = element.find( "option:selected" );
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal(
|
2015-10-17 19:31:02 +00:00
|
|
|
$.trim( button.text() ),
|
|
|
|
option.text() + element[ 0 ].selectedIndex,
|
2014-07-28 17:09:41 +00:00
|
|
|
"refresh: button item text"
|
|
|
|
);
|
|
|
|
|
|
|
|
button.trigger( "click" );
|
|
|
|
menu.find( "li" ).last().simulate( "mouseover" ).trigger( "click" );
|
|
|
|
option = element.find( "option" ).last();
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal(
|
2015-10-17 19:31:02 +00:00
|
|
|
$.trim( button.text() ),
|
|
|
|
option.text() + element[ 0 ].selectedIndex,
|
2014-07-28 17:09:41 +00:00
|
|
|
"click: button item text"
|
|
|
|
);
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
2014-07-28 17:09:41 +00:00
|
|
|
|
2015-08-24 12:50:24 +00:00
|
|
|
$.each( [
|
2011-11-21 20:54:04 +00:00
|
|
|
{
|
|
|
|
type: "default",
|
2011-11-21 23:35:27 +00:00
|
|
|
selector: "#speed"
|
2011-11-21 20:54:04 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "optgroups",
|
2011-11-21 23:35:27 +00:00
|
|
|
selector: "#files"
|
2011-11-21 20:54:04 +00:00
|
|
|
}
|
|
|
|
], function( i, settings ) {
|
2016-04-06 13:16:23 +00:00
|
|
|
QUnit.test( "state synchronization - after keydown on button - " + settings.type, function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 4 );
|
2012-02-21 17:08:14 +00:00
|
|
|
|
2014-09-26 21:34:22 +00:00
|
|
|
var wrappers,
|
2013-02-13 22:58:14 +00:00
|
|
|
element = $( settings.selector ).selectmenu(),
|
|
|
|
button = element.selectmenu( "widget" ),
|
|
|
|
menu = element.selectmenu( "menuWidget" ),
|
2014-04-22 00:15:36 +00:00
|
|
|
|
|
|
|
// Get the option after the currently selected option because
|
|
|
|
// we simulate pressing DOWN.
|
|
|
|
selected = element.find( "option:selected" ).next();
|
2012-02-21 17:08:14 +00:00
|
|
|
|
2012-05-24 16:54:47 +00:00
|
|
|
button.simulate( "focus" );
|
2015-08-24 12:50:24 +00:00
|
|
|
setTimeout( function() {
|
2014-09-26 21:34:22 +00:00
|
|
|
wrappers = menu.find( "li.ui-menu-item .ui-menu-item-wrapper" );
|
2013-04-30 22:33:37 +00:00
|
|
|
|
|
|
|
button.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal(
|
2013-04-30 22:33:37 +00:00
|
|
|
menu.attr( "aria-activedescendant" ),
|
2014-09-26 21:34:22 +00:00
|
|
|
wrappers.eq( element[ 0 ].selectedIndex ).attr( "id" ),
|
2013-04-30 22:33:37 +00:00
|
|
|
"menu aria-activedescendant"
|
|
|
|
);
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal(
|
2013-04-30 22:33:37 +00:00
|
|
|
button.attr( "aria-activedescendant" ),
|
2014-09-26 21:34:22 +00:00
|
|
|
wrappers.eq( element[ 0 ].selectedIndex ).attr( "id" ),
|
2013-04-30 22:33:37 +00:00
|
|
|
"button aria-activedescendant"
|
|
|
|
);
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal(
|
2013-04-30 22:33:37 +00:00
|
|
|
element.find( "option:selected" ).val(),
|
2015-08-24 12:50:24 +00:00
|
|
|
selected.val(),
|
2013-04-30 22:33:37 +00:00
|
|
|
"original select state"
|
|
|
|
);
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( $.trim( button.text() ), selected.text(), "button text" );
|
|
|
|
ready();
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
|
|
|
} );
|
2012-07-16 19:31:18 +00:00
|
|
|
|
2016-04-06 13:16:23 +00:00
|
|
|
QUnit.test( "state synchronization - after click on item - " + settings.type, function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 4 );
|
2012-07-16 19:31:18 +00:00
|
|
|
|
2014-09-26 21:34:22 +00:00
|
|
|
var wrappers,
|
2013-02-13 22:58:14 +00:00
|
|
|
element = $( settings.selector ).selectmenu(),
|
|
|
|
button = element.selectmenu( "widget" ),
|
2014-04-22 00:15:36 +00:00
|
|
|
menu = element.selectmenu( "menuWidget" ),
|
|
|
|
selected = element.find( "option" ).last();
|
2012-07-16 19:31:18 +00:00
|
|
|
|
|
|
|
button.simulate( "focus" );
|
2015-08-24 12:50:24 +00:00
|
|
|
setTimeout( function() {
|
2014-09-26 21:34:22 +00:00
|
|
|
wrappers = menu.find( "li.ui-menu-item .ui-menu-item-wrapper" );
|
2013-04-30 22:33:37 +00:00
|
|
|
|
2013-07-01 20:04:30 +00:00
|
|
|
button.trigger( "click" );
|
2013-10-09 23:01:41 +00:00
|
|
|
menu.find( "li" ).last().simulate( "mouseover" ).trigger( "click" );
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal(
|
2013-04-30 22:33:37 +00:00
|
|
|
menu.attr( "aria-activedescendant" ),
|
2014-09-26 21:34:22 +00:00
|
|
|
wrappers.eq( element[ 0 ].selectedIndex ).attr( "id" ),
|
2013-04-30 22:33:37 +00:00
|
|
|
"menu aria-activedescendant"
|
|
|
|
);
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal(
|
2013-04-30 22:33:37 +00:00
|
|
|
button.attr( "aria-activedescendant" ),
|
2014-09-26 21:34:22 +00:00
|
|
|
wrappers.eq( element[ 0 ].selectedIndex ).attr( "id" ),
|
2013-04-30 22:33:37 +00:00
|
|
|
"button aria-activedescendant"
|
|
|
|
);
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal(
|
2013-04-30 22:33:37 +00:00
|
|
|
element.find( "option:selected" ).val(),
|
2014-04-22 00:15:36 +00:00
|
|
|
selected.val(),
|
2013-04-30 22:33:37 +00:00
|
|
|
"original select state"
|
|
|
|
);
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( $.trim( button.text() ), selected.text(), "button text" );
|
|
|
|
ready();
|
2013-04-30 22:33:37 +00:00
|
|
|
}, 1 );
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
2013-02-13 22:58:14 +00:00
|
|
|
|
2016-04-06 13:16:23 +00:00
|
|
|
QUnit.test( "state synchronization - " +
|
|
|
|
"after focus item and keydown on button - " + settings.type, function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 4 );
|
2013-02-13 21:18:12 +00:00
|
|
|
|
2014-09-26 21:34:22 +00:00
|
|
|
var wrappers,
|
2013-02-13 22:58:14 +00:00
|
|
|
element = $( settings.selector ).selectmenu(),
|
|
|
|
button = element.selectmenu( "widget" ),
|
|
|
|
menu = element.selectmenu( "menuWidget" ),
|
|
|
|
options = element.find( "option" );
|
2013-02-13 21:18:12 +00:00
|
|
|
|
2014-04-22 00:15:36 +00:00
|
|
|
// Init menu
|
2013-02-13 22:58:14 +00:00
|
|
|
button.simulate( "focus" );
|
|
|
|
|
2015-08-24 12:50:24 +00:00
|
|
|
setTimeout( function() {
|
2014-09-26 21:34:22 +00:00
|
|
|
wrappers = menu.find( "li.ui-menu-item .ui-menu-item-wrapper" );
|
2014-04-22 00:15:36 +00:00
|
|
|
|
|
|
|
// Open menu and click first item
|
2013-07-01 20:04:30 +00:00
|
|
|
button.trigger( "click" );
|
2014-09-26 21:34:22 +00:00
|
|
|
wrappers.first().simulate( "mouseover" ).trigger( "click" );
|
2014-04-22 00:15:36 +00:00
|
|
|
|
|
|
|
// Open menu again and hover item
|
2013-07-01 20:04:30 +00:00
|
|
|
button.trigger( "click" );
|
2014-09-26 21:34:22 +00:00
|
|
|
wrappers.eq( 3 ).simulate( "mouseover" );
|
2014-04-22 00:15:36 +00:00
|
|
|
|
|
|
|
// Close and use keyboard control on button
|
2013-04-30 22:33:37 +00:00
|
|
|
button.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
|
|
|
|
button.simulate( "focus" );
|
2015-08-24 12:50:24 +00:00
|
|
|
setTimeout( function() {
|
2013-04-30 22:33:37 +00:00
|
|
|
button.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
|
|
|
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( menu.attr( "aria-activedescendant" ), wrappers.eq( 1 ).attr( "id" ),
|
2014-04-22 00:15:36 +00:00
|
|
|
"menu aria-activedescendant" );
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( button.attr( "aria-activedescendant" ), wrappers.eq( 1 ).attr( "id" ),
|
2014-04-22 00:15:36 +00:00
|
|
|
"button aria-activedescendant" );
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( element.find( "option:selected" ).val(), options.eq( 1 ).val(),
|
2014-04-22 00:15:36 +00:00
|
|
|
"original select state" );
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( $.trim( button.text() ), options.eq( 1 ).text(), "button text" );
|
|
|
|
ready();
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|
2013-07-01 20:59:43 +00:00
|
|
|
|
2016-04-06 13:16:23 +00:00
|
|
|
QUnit.test( "item looping - " + settings.type, function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 4 );
|
2013-07-01 20:59:43 +00:00
|
|
|
|
2014-09-26 21:34:22 +00:00
|
|
|
var wrappers,
|
2013-07-01 20:59:43 +00:00
|
|
|
element = $( settings.selector ).selectmenu(),
|
|
|
|
button = element.selectmenu( "widget" ),
|
2013-07-01 21:08:55 +00:00
|
|
|
menu = element.selectmenu( "menuWidget" );
|
2013-07-01 20:59:43 +00:00
|
|
|
|
|
|
|
button.simulate( "focus" );
|
2015-08-24 12:50:24 +00:00
|
|
|
setTimeout( function() {
|
2014-09-26 21:34:22 +00:00
|
|
|
wrappers = menu.find( "li.ui-menu-item .ui-menu-item-wrapper" );
|
2013-07-01 20:59:43 +00:00
|
|
|
|
|
|
|
button.trigger( "click" );
|
2014-09-26 21:34:22 +00:00
|
|
|
wrappers.first().simulate( "mouseover" ).trigger( "click" );
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( element[ 0 ].selectedIndex, 0, "First item is selected" );
|
2013-07-01 20:59:43 +00:00
|
|
|
button.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( element[ 0 ].selectedIndex, 0, "No looping beyond first item" );
|
2013-07-01 20:59:43 +00:00
|
|
|
|
|
|
|
button.trigger( "click" );
|
2014-09-26 21:34:22 +00:00
|
|
|
wrappers.last().simulate( "mouseover" ).trigger( "click" );
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( element[ 0 ].selectedIndex, wrappers.length - 1, "Last item is selected" );
|
2013-07-01 20:59:43 +00:00
|
|
|
button.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( element[ 0 ].selectedIndex, wrappers.length - 1, "No looping behind last item" );
|
|
|
|
ready();
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
|
|
|
} );
|
2013-08-02 23:16:42 +00:00
|
|
|
|
2016-04-06 13:16:23 +00:00
|
|
|
QUnit.test( "item focus and active state - " + settings.type, function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 4 );
|
2013-08-02 23:16:42 +00:00
|
|
|
|
2014-09-26 21:34:22 +00:00
|
|
|
var wrappers, focusedItem,
|
2014-04-08 15:19:26 +00:00
|
|
|
element = $( settings.selector ).selectmenu(),
|
2013-08-02 23:16:42 +00:00
|
|
|
button = element.selectmenu( "widget" ),
|
2014-04-08 15:19:26 +00:00
|
|
|
menu = element.selectmenu( "menuWidget" );
|
2013-08-02 23:16:42 +00:00
|
|
|
|
|
|
|
button.simulate( "focus" );
|
2015-08-24 12:50:24 +00:00
|
|
|
setTimeout( function() {
|
2014-09-26 21:34:22 +00:00
|
|
|
wrappers = menu.find( "li.ui-menu-item .ui-menu-item-wrapper" );
|
2013-08-02 23:16:42 +00:00
|
|
|
|
|
|
|
button.trigger( "click" );
|
2015-08-24 12:50:24 +00:00
|
|
|
setTimeout( function() {
|
2013-09-04 19:34:20 +00:00
|
|
|
checkItemClasses();
|
2013-08-02 23:16:42 +00:00
|
|
|
|
2014-09-26 21:34:22 +00:00
|
|
|
wrappers.eq( 3 ).simulate( "mouseover" ).trigger( "click" );
|
2013-08-02 23:16:42 +00:00
|
|
|
|
2013-09-04 19:34:20 +00:00
|
|
|
button.trigger( "click" );
|
2014-09-26 21:34:22 +00:00
|
|
|
wrappers.eq( 2 ).simulate( "mouseover" );
|
2013-09-04 19:34:20 +00:00
|
|
|
$( document ).trigger( "click" );
|
2013-08-02 23:16:42 +00:00
|
|
|
|
2013-09-04 19:34:20 +00:00
|
|
|
button.trigger( "click" );
|
2014-09-26 21:34:22 +00:00
|
|
|
wrappers.eq( 1 ).simulate( "mouseover" );
|
2013-09-04 19:34:20 +00:00
|
|
|
$( document ).trigger( "click" );
|
2013-08-02 23:16:42 +00:00
|
|
|
|
2013-09-04 19:34:20 +00:00
|
|
|
button.trigger( "click" );
|
2015-08-24 12:50:24 +00:00
|
|
|
setTimeout( function() {
|
2014-04-08 15:19:26 +00:00
|
|
|
checkItemClasses();
|
2016-04-06 13:16:23 +00:00
|
|
|
ready();
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|
2013-09-04 19:34:20 +00:00
|
|
|
|
|
|
|
function checkItemClasses() {
|
2015-01-19 16:00:57 +00:00
|
|
|
focusedItem = menu.find( ".ui-menu-item-wrapper.ui-state-active" );
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( focusedItem.length, 1, "only one item has ui-state-focus class" );
|
|
|
|
assert.equal( focusedItem.attr( "id" ), wrappers.eq( element[ 0 ].selectedIndex ).attr( "id" ),
|
2014-04-22 00:15:36 +00:00
|
|
|
"selected item has ui-state-focus class" );
|
2013-09-04 19:34:20 +00:00
|
|
|
}
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
2013-12-18 18:00:32 +00:00
|
|
|
|
2016-04-06 13:16:23 +00:00
|
|
|
QUnit.test( "empty option - " + settings.type, function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 7 );
|
2013-12-18 18:00:32 +00:00
|
|
|
|
2014-09-26 21:34:22 +00:00
|
|
|
var button, menu, wrappers, wrapper,
|
2014-04-22 00:15:36 +00:00
|
|
|
element = $( settings.selector );
|
2013-12-18 18:00:32 +00:00
|
|
|
|
|
|
|
element.find( "option" ).first().text( "" );
|
|
|
|
element.selectmenu();
|
|
|
|
button = element.selectmenu( "widget" );
|
|
|
|
menu = element.selectmenu( "menuWidget" );
|
|
|
|
|
|
|
|
button.simulate( "focus" );
|
2015-08-24 12:50:24 +00:00
|
|
|
setTimeout( function() {
|
2014-09-26 21:34:22 +00:00
|
|
|
wrappers = menu.find( "li:not(.ui-selectmenu-optgroup) .ui-menu-item-wrapper" );
|
|
|
|
wrapper = wrappers.first();
|
2013-12-18 18:00:32 +00:00
|
|
|
|
|
|
|
button.trigger( "click" );
|
|
|
|
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( wrappers.length, element.find( "option" ).length,
|
2014-04-22 00:15:36 +00:00
|
|
|
"correct amount of list elements" );
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.ok( wrapper.outerHeight() > 10, "empty item seems to have reasonable height" );
|
|
|
|
assert.ok( wrapper.attr( "id" ), "empty item has id attribute" );
|
2015-01-30 15:00:56 +00:00
|
|
|
assert.hasClasses( wrapper.parent(), "ui-menu-item" );
|
|
|
|
assert.lacksClasses( wrapper, "ui-menu-divider" );
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( wrapper.attr( "tabindex" ), -1, "empty item has tabindex" );
|
|
|
|
assert.equal( wrapper.attr( "role" ), "option", "empty item has role option" );
|
2013-12-18 18:00:32 +00:00
|
|
|
|
2016-04-06 13:16:23 +00:00
|
|
|
ready();
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|
2011-11-02 20:56:37 +00:00
|
|
|
|
2016-04-06 13:16:23 +00:00
|
|
|
QUnit.test( "Selectmenu should reset when its parent form resets", function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 2 );
|
2015-10-26 17:13:42 +00:00
|
|
|
|
|
|
|
var element = $( "#speed" ).selectmenu(),
|
|
|
|
widget = element.selectmenu( "widget" ),
|
|
|
|
initialValue = element.val(),
|
|
|
|
form = element.closest( "form" );
|
|
|
|
|
|
|
|
element.val( "Slower" );
|
|
|
|
element.selectmenu( "refresh" );
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( $.trim( widget.text() ), "Slower" );
|
2015-10-26 17:13:42 +00:00
|
|
|
form[ 0 ].reset();
|
|
|
|
setTimeout( function() {
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( $.trim( widget.text() ), initialValue );
|
|
|
|
ready();
|
2015-10-26 17:13:42 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2015-04-06 18:40:47 +00:00
|
|
|
} );
|