mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Selectmenu: Shift to use no globals
This commit is contained in:
parent
b6392d6a6d
commit
d00c5641b9
@ -1,12 +1,13 @@
|
||||
define( [
|
||||
"qunit",
|
||||
"jquery",
|
||||
"ui/widgets/selectmenu"
|
||||
], function( $ ) {
|
||||
], function( QUnit, $ ) {
|
||||
|
||||
module( "selectmenu: core" );
|
||||
QUnit.module( "selectmenu: core" );
|
||||
|
||||
test( "markup structure", function( assert ) {
|
||||
expect( 7 );
|
||||
QUnit.test( "markup structure", function( assert ) {
|
||||
assert.expect( 7 );
|
||||
|
||||
var element = $( "#files" ).selectmenu(),
|
||||
button = element.selectmenu( "widget" ),
|
||||
@ -24,7 +25,8 @@ test( "markup structure", function( assert ) {
|
||||
assert.strictEqual( icon[ 0 ], button.children()[ 0 ], "Icon is first child of button" );
|
||||
} );
|
||||
|
||||
asyncTest( "accessibility", function() {
|
||||
QUnit.test( "accessibility", function( assert ) {
|
||||
var ready = assert.async();
|
||||
var wrappers, button, menu,
|
||||
element = $( "#speed" ).attr( "title", "A demo title" );
|
||||
|
||||
@ -39,43 +41,43 @@ asyncTest( "accessibility", function() {
|
||||
button.simulate( "focus" );
|
||||
wrappers = menu.find( "li.ui-menu-item .ui-menu-item-wrapper" );
|
||||
|
||||
expect( 13 + wrappers.length * 3 );
|
||||
assert.expect( 13 + wrappers.length * 3 );
|
||||
|
||||
setTimeout( function() {
|
||||
equal( button.attr( "role" ), "combobox", "button role" );
|
||||
equal( button.attr( "aria-haspopup" ), "true", "button aria-haspopup" );
|
||||
equal( button.attr( "aria-expanded" ), "false", "button aria-expanded" );
|
||||
equal( button.attr( "aria-autocomplete" ), "list", "button aria-autocomplete" );
|
||||
equal( button.attr( "aria-owns" ), menu.attr( "id" ), "button aria-owns" );
|
||||
equal(
|
||||
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(
|
||||
button.attr( "aria-labelledby" ),
|
||||
wrappers.eq( element[ 0 ].selectedIndex ).attr( "id" ),
|
||||
"button link aria-labelledby"
|
||||
);
|
||||
equal( button.attr( "tabindex" ), 0, "button link tabindex" );
|
||||
equal( button.attr( "title" ), "A demo title", "button title" );
|
||||
assert.equal( button.attr( "tabindex" ), 0, "button link tabindex" );
|
||||
assert.equal( button.attr( "title" ), "A demo title", "button title" );
|
||||
|
||||
equal( menu.attr( "role" ), "listbox", "menu role" );
|
||||
equal( menu.attr( "aria-labelledby" ), button.attr( "id" ), "menu aria-labelledby" );
|
||||
equal( menu.attr( "aria-hidden" ), "true", "menu aria-hidden" );
|
||||
equal( menu.attr( "tabindex" ), 0, "menu tabindex" );
|
||||
equal(
|
||||
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(
|
||||
menu.attr( "aria-activedescendant" ),
|
||||
wrappers.eq( element[ 0 ].selectedIndex ).attr( "id" ),
|
||||
"menu aria-activedescendant"
|
||||
);
|
||||
$.each( wrappers, function( index ) {
|
||||
var item = $( this );
|
||||
equal( item.attr( "role" ), "option", "menu item #" + index + " role" );
|
||||
equal( item.attr( "tabindex" ), -1, "menu item #" + index + " tabindex" );
|
||||
equal( item.attr( "title" ), "A demo title #" + index, "menu item #" + index + " title" );
|
||||
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" );
|
||||
} );
|
||||
start();
|
||||
ready();
|
||||
} );
|
||||
} );
|
||||
|
||||
test( "_renderButtonItem()", function() {
|
||||
expect( 2 );
|
||||
QUnit.test( "_renderButtonItem()", function( assert ) {
|
||||
assert.expect( 2 );
|
||||
|
||||
var option,
|
||||
element = $( "#speed" ).selectmenu(),
|
||||
@ -92,7 +94,7 @@ test( "_renderButtonItem()", function() {
|
||||
|
||||
element.selectmenu( "refresh" );
|
||||
option = element.find( "option:selected" );
|
||||
equal(
|
||||
assert.equal(
|
||||
$.trim( button.text() ),
|
||||
option.text() + element[ 0 ].selectedIndex,
|
||||
"refresh: button item text"
|
||||
@ -101,7 +103,7 @@ test( "_renderButtonItem()", function() {
|
||||
button.trigger( "click" );
|
||||
menu.find( "li" ).last().simulate( "mouseover" ).trigger( "click" );
|
||||
option = element.find( "option" ).last();
|
||||
equal(
|
||||
assert.equal(
|
||||
$.trim( button.text() ),
|
||||
option.text() + element[ 0 ].selectedIndex,
|
||||
"click: button item text"
|
||||
@ -118,8 +120,9 @@ $.each( [
|
||||
selector: "#files"
|
||||
}
|
||||
], function( i, settings ) {
|
||||
asyncTest( "state synchronization - after keydown on button - " + settings.type, function() {
|
||||
expect( 4 );
|
||||
QUnit.test( "state synchronization - after keydown on button - " + settings.type, function( assert ) {
|
||||
var ready = assert.async();
|
||||
assert.expect( 4 );
|
||||
|
||||
var wrappers,
|
||||
element = $( settings.selector ).selectmenu(),
|
||||
@ -135,28 +138,29 @@ $.each( [
|
||||
wrappers = menu.find( "li.ui-menu-item .ui-menu-item-wrapper" );
|
||||
|
||||
button.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
||||
equal(
|
||||
assert.equal(
|
||||
menu.attr( "aria-activedescendant" ),
|
||||
wrappers.eq( element[ 0 ].selectedIndex ).attr( "id" ),
|
||||
"menu aria-activedescendant"
|
||||
);
|
||||
equal(
|
||||
assert.equal(
|
||||
button.attr( "aria-activedescendant" ),
|
||||
wrappers.eq( element[ 0 ].selectedIndex ).attr( "id" ),
|
||||
"button aria-activedescendant"
|
||||
);
|
||||
equal(
|
||||
assert.equal(
|
||||
element.find( "option:selected" ).val(),
|
||||
selected.val(),
|
||||
"original select state"
|
||||
);
|
||||
equal( $.trim( button.text() ), selected.text(), "button text" );
|
||||
start();
|
||||
assert.equal( $.trim( button.text() ), selected.text(), "button text" );
|
||||
ready();
|
||||
} );
|
||||
} );
|
||||
|
||||
asyncTest( "state synchronization - after click on item - " + settings.type, function() {
|
||||
expect( 4 );
|
||||
QUnit.test( "state synchronization - after click on item - " + settings.type, function( assert ) {
|
||||
var ready = assert.async();
|
||||
assert.expect( 4 );
|
||||
|
||||
var wrappers,
|
||||
element = $( settings.selector ).selectmenu(),
|
||||
@ -170,29 +174,30 @@ $.each( [
|
||||
|
||||
button.trigger( "click" );
|
||||
menu.find( "li" ).last().simulate( "mouseover" ).trigger( "click" );
|
||||
equal(
|
||||
assert.equal(
|
||||
menu.attr( "aria-activedescendant" ),
|
||||
wrappers.eq( element[ 0 ].selectedIndex ).attr( "id" ),
|
||||
"menu aria-activedescendant"
|
||||
);
|
||||
equal(
|
||||
assert.equal(
|
||||
button.attr( "aria-activedescendant" ),
|
||||
wrappers.eq( element[ 0 ].selectedIndex ).attr( "id" ),
|
||||
"button aria-activedescendant"
|
||||
);
|
||||
equal(
|
||||
assert.equal(
|
||||
element.find( "option:selected" ).val(),
|
||||
selected.val(),
|
||||
"original select state"
|
||||
);
|
||||
equal( $.trim( button.text() ), selected.text(), "button text" );
|
||||
start();
|
||||
assert.equal( $.trim( button.text() ), selected.text(), "button text" );
|
||||
ready();
|
||||
}, 1 );
|
||||
} );
|
||||
|
||||
asyncTest( "state synchronization - " +
|
||||
"after focus item and keydown on button - " + settings.type, function() {
|
||||
expect( 4 );
|
||||
QUnit.test( "state synchronization - " +
|
||||
"after focus item and keydown on button - " + settings.type, function( assert ) {
|
||||
var ready = assert.async();
|
||||
assert.expect( 4 );
|
||||
|
||||
var wrappers,
|
||||
element = $( settings.selector ).selectmenu(),
|
||||
@ -220,20 +225,21 @@ $.each( [
|
||||
setTimeout( function() {
|
||||
button.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
||||
|
||||
equal( menu.attr( "aria-activedescendant" ), wrappers.eq( 1 ).attr( "id" ),
|
||||
assert.equal( menu.attr( "aria-activedescendant" ), wrappers.eq( 1 ).attr( "id" ),
|
||||
"menu aria-activedescendant" );
|
||||
equal( button.attr( "aria-activedescendant" ), wrappers.eq( 1 ).attr( "id" ),
|
||||
assert.equal( button.attr( "aria-activedescendant" ), wrappers.eq( 1 ).attr( "id" ),
|
||||
"button aria-activedescendant" );
|
||||
equal( element.find( "option:selected" ).val(), options.eq( 1 ).val(),
|
||||
assert.equal( element.find( "option:selected" ).val(), options.eq( 1 ).val(),
|
||||
"original select state" );
|
||||
equal( $.trim( button.text() ), options.eq( 1 ).text(), "button text" );
|
||||
start();
|
||||
assert.equal( $.trim( button.text() ), options.eq( 1 ).text(), "button text" );
|
||||
ready();
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
|
||||
asyncTest( "item looping - " + settings.type, function() {
|
||||
expect( 4 );
|
||||
QUnit.test( "item looping - " + settings.type, function( assert ) {
|
||||
var ready = assert.async();
|
||||
assert.expect( 4 );
|
||||
|
||||
var wrappers,
|
||||
element = $( settings.selector ).selectmenu(),
|
||||
@ -246,21 +252,22 @@ $.each( [
|
||||
|
||||
button.trigger( "click" );
|
||||
wrappers.first().simulate( "mouseover" ).trigger( "click" );
|
||||
equal( element[ 0 ].selectedIndex, 0, "First item is selected" );
|
||||
assert.equal( element[ 0 ].selectedIndex, 0, "First item is selected" );
|
||||
button.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
|
||||
equal( element[ 0 ].selectedIndex, 0, "No looping beyond first item" );
|
||||
assert.equal( element[ 0 ].selectedIndex, 0, "No looping beyond first item" );
|
||||
|
||||
button.trigger( "click" );
|
||||
wrappers.last().simulate( "mouseover" ).trigger( "click" );
|
||||
equal( element[ 0 ].selectedIndex, wrappers.length - 1, "Last item is selected" );
|
||||
assert.equal( element[ 0 ].selectedIndex, wrappers.length - 1, "Last item is selected" );
|
||||
button.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
||||
equal( element[ 0 ].selectedIndex, wrappers.length - 1, "No looping behind last item" );
|
||||
start();
|
||||
assert.equal( element[ 0 ].selectedIndex, wrappers.length - 1, "No looping behind last item" );
|
||||
ready();
|
||||
} );
|
||||
} );
|
||||
|
||||
asyncTest( "item focus and active state - " + settings.type, function() {
|
||||
expect( 4 );
|
||||
QUnit.test( "item focus and active state - " + settings.type, function( assert ) {
|
||||
var ready = assert.async();
|
||||
assert.expect( 4 );
|
||||
|
||||
var wrappers, focusedItem,
|
||||
element = $( settings.selector ).selectmenu(),
|
||||
@ -288,21 +295,22 @@ $.each( [
|
||||
button.trigger( "click" );
|
||||
setTimeout( function() {
|
||||
checkItemClasses();
|
||||
start();
|
||||
ready();
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
|
||||
function checkItemClasses() {
|
||||
focusedItem = menu.find( ".ui-menu-item-wrapper.ui-state-active" );
|
||||
equal( focusedItem.length, 1, "only one item has ui-state-focus class" );
|
||||
equal( focusedItem.attr( "id" ), wrappers.eq( element[ 0 ].selectedIndex ).attr( "id" ),
|
||||
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" ),
|
||||
"selected item has ui-state-focus class" );
|
||||
}
|
||||
} );
|
||||
|
||||
asyncTest( "empty option - " + settings.type, function( assert ) {
|
||||
expect( 7 );
|
||||
QUnit.test( "empty option - " + settings.type, function( assert ) {
|
||||
var ready = assert.async();
|
||||
assert.expect( 7 );
|
||||
|
||||
var button, menu, wrappers, wrapper,
|
||||
element = $( settings.selector );
|
||||
@ -319,22 +327,23 @@ $.each( [
|
||||
|
||||
button.trigger( "click" );
|
||||
|
||||
equal( wrappers.length, element.find( "option" ).length,
|
||||
assert.equal( wrappers.length, element.find( "option" ).length,
|
||||
"correct amount of list elements" );
|
||||
ok( wrapper.outerHeight() > 10, "empty item seems to have reasonable height" );
|
||||
ok( wrapper.attr( "id" ), "empty item has id attribute" );
|
||||
assert.ok( wrapper.outerHeight() > 10, "empty item seems to have reasonable height" );
|
||||
assert.ok( wrapper.attr( "id" ), "empty item has id attribute" );
|
||||
assert.hasClasses( wrapper.parent(), "ui-menu-item" );
|
||||
assert.lacksClasses( wrapper, "ui-menu-divider" );
|
||||
equal( wrapper.attr( "tabindex" ), -1, "empty item has tabindex" );
|
||||
equal( wrapper.attr( "role" ), "option", "empty item has role option" );
|
||||
assert.equal( wrapper.attr( "tabindex" ), -1, "empty item has tabindex" );
|
||||
assert.equal( wrapper.attr( "role" ), "option", "empty item has role option" );
|
||||
|
||||
start();
|
||||
ready();
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
|
||||
asyncTest( "Selectmenu should reset when its parent form resets", function() {
|
||||
expect( 2 );
|
||||
QUnit.test( "Selectmenu should reset when its parent form resets", function( assert ) {
|
||||
var ready = assert.async();
|
||||
assert.expect( 2 );
|
||||
|
||||
var element = $( "#speed" ).selectmenu(),
|
||||
widget = element.selectmenu( "widget" ),
|
||||
@ -343,11 +352,11 @@ $.each( [
|
||||
|
||||
element.val( "Slower" );
|
||||
element.selectmenu( "refresh" );
|
||||
equal( $.trim( widget.text() ), "Slower" );
|
||||
assert.equal( $.trim( widget.text() ), "Slower" );
|
||||
form[ 0 ].reset();
|
||||
setTimeout( function() {
|
||||
equal( $.trim( widget.text() ), initialValue );
|
||||
start();
|
||||
assert.equal( $.trim( widget.text() ), initialValue );
|
||||
ready();
|
||||
} );
|
||||
} );
|
||||
|
||||
|
@ -1,26 +1,28 @@
|
||||
define( [
|
||||
"qunit",
|
||||
"jquery",
|
||||
"ui/widgets/selectmenu"
|
||||
], function( $ ) {
|
||||
], function( QUnit, $ ) {
|
||||
|
||||
module( "selectmenu: events", {
|
||||
setup: function() {
|
||||
QUnit.module( "selectmenu: events", {
|
||||
beforeEach: function() {
|
||||
this.element = $( "#speed" );
|
||||
}
|
||||
} );
|
||||
|
||||
asyncTest( "change", function() {
|
||||
expect( 3 );
|
||||
QUnit.test( "change", function( assert ) {
|
||||
var ready = assert.async();
|
||||
assert.expect( 3 );
|
||||
|
||||
var button, menu, options,
|
||||
optionIndex = 1;
|
||||
|
||||
this.element.selectmenu( {
|
||||
change: function( event, ui ) {
|
||||
equal( ui.item.index, optionIndex, "ui.item.index contains correct option index" );
|
||||
equal( ui.item.element[ 0 ], options.eq( optionIndex )[ 0 ],
|
||||
assert.equal( ui.item.index, optionIndex, "ui.item.index contains correct option index" );
|
||||
assert.equal( ui.item.element[ 0 ], options.eq( optionIndex )[ 0 ],
|
||||
"ui.item.element contains original option element" );
|
||||
equal( ui.item.value, options.eq( optionIndex ).text(),
|
||||
assert.equal( ui.item.value, options.eq( optionIndex ).text(),
|
||||
"ui.item.value property updated correctly" );
|
||||
}
|
||||
} );
|
||||
@ -34,18 +36,18 @@ asyncTest( "change", function() {
|
||||
setTimeout( function() {
|
||||
button.trigger( "click" );
|
||||
menu.find( "li" ).eq( optionIndex ).simulate( "mouseover" ).trigger( "click" );
|
||||
start();
|
||||
ready();
|
||||
} );
|
||||
} );
|
||||
|
||||
test( "close", function() {
|
||||
expect( 2 );
|
||||
QUnit.test( "close", function( assert ) {
|
||||
assert.expect( 2 );
|
||||
|
||||
var shouldFire;
|
||||
|
||||
this.element.selectmenu( {
|
||||
close: function() {
|
||||
ok( shouldFire, "close event fired on close" );
|
||||
assert.ok( shouldFire, "close event fired on close" );
|
||||
}
|
||||
} );
|
||||
|
||||
@ -59,8 +61,9 @@ test( "close", function() {
|
||||
$( "body" ).trigger( "mousedown" );
|
||||
} );
|
||||
|
||||
asyncTest( "focus", function() {
|
||||
expect( 9 );
|
||||
QUnit.test( "focus", function( assert ) {
|
||||
var ready = assert.async();
|
||||
assert.expect( 9 );
|
||||
|
||||
var button, menu, links,
|
||||
that = this,
|
||||
@ -69,9 +72,9 @@ asyncTest( "focus", function() {
|
||||
|
||||
this.element.selectmenu( {
|
||||
focus: function( event, ui ) {
|
||||
ok( true, "focus event fired on element #" + optionIndex + " mouseover" );
|
||||
equal( ui.item.index, optionIndex, "ui.item.index contains correct option index" );
|
||||
equal( ui.item.element[ 0 ], options.eq( optionIndex )[ 0 ],
|
||||
assert.ok( true, "focus event fired on element #" + optionIndex + " mouseover" );
|
||||
assert.equal( ui.item.index, optionIndex, "ui.item.index contains correct option index" );
|
||||
assert.equal( ui.item.element[ 0 ], options.eq( optionIndex )[ 0 ],
|
||||
"ui.item.element contains original option element" );
|
||||
}
|
||||
} );
|
||||
@ -92,30 +95,31 @@ asyncTest( "focus", function() {
|
||||
|
||||
// This tests for unwanted, additional focus event on close
|
||||
that.element.selectmenu( "close" );
|
||||
start();
|
||||
ready();
|
||||
} );
|
||||
} );
|
||||
|
||||
test( "open", function() {
|
||||
expect( 1 );
|
||||
QUnit.test( "open", function( assert ) {
|
||||
assert.expect( 1 );
|
||||
|
||||
this.element.selectmenu( {
|
||||
open: function() {
|
||||
ok( true, "open event fired on open" );
|
||||
assert.ok( true, "open event fired on open" );
|
||||
}
|
||||
} );
|
||||
|
||||
this.element.selectmenu( "open" );
|
||||
} );
|
||||
|
||||
asyncTest( "select", function() {
|
||||
expect( 3 );
|
||||
QUnit.test( "select", function( assert ) {
|
||||
var ready = assert.async();
|
||||
assert.expect( 3 );
|
||||
|
||||
this.element.selectmenu( {
|
||||
select: function( event, ui ) {
|
||||
ok( true, "select event fired on item select" );
|
||||
equal( ui.item.index, optionIndex, "ui.item.index contains correct option index" );
|
||||
equal( ui.item.element[ 0 ], options.eq( optionIndex )[ 0 ],
|
||||
assert.ok( true, "select event fired on item select" );
|
||||
assert.equal( ui.item.index, optionIndex, "ui.item.index contains correct option index" );
|
||||
assert.equal( ui.item.element[ 0 ], options.eq( optionIndex )[ 0 ],
|
||||
"ui.item.element contains original option element" );
|
||||
}
|
||||
} );
|
||||
@ -129,7 +133,7 @@ asyncTest( "select", function() {
|
||||
setTimeout( function() {
|
||||
button.trigger( "click" );
|
||||
menu.find( "li" ).eq( optionIndex ).simulate( "mouseover" ).trigger( "click" );
|
||||
start();
|
||||
ready();
|
||||
} );
|
||||
} );
|
||||
|
||||
|
@ -1,58 +1,59 @@
|
||||
define( [
|
||||
"qunit",
|
||||
"jquery",
|
||||
"ui/widgets/selectmenu"
|
||||
], function( $ ) {
|
||||
], function( QUnit, $ ) {
|
||||
|
||||
module( "selectmenu: methods" );
|
||||
QUnit.module( "selectmenu: methods" );
|
||||
|
||||
test( "destroy", function( assert ) {
|
||||
expect( 1 );
|
||||
QUnit.test( "destroy", function( assert ) {
|
||||
assert.expect( 1 );
|
||||
assert.domEqual( "#speed", function() {
|
||||
$( "#speed" ).selectmenu().selectmenu( "destroy" );
|
||||
} );
|
||||
} );
|
||||
|
||||
test( "open / close", function() {
|
||||
expect( 5 );
|
||||
QUnit.test( "open / close", function( assert ) {
|
||||
assert.expect( 5 );
|
||||
|
||||
var element = $( "#speed" ).selectmenu(),
|
||||
menu = element.selectmenu( "menuWidget" );
|
||||
|
||||
ok( menu.is( ":hidden" ), "menu hidden on init" );
|
||||
assert.ok( menu.is( ":hidden" ), "menu hidden on init" );
|
||||
|
||||
element.selectmenu( "open" );
|
||||
ok( menu.is( ":visible" ), "open: menu visible" );
|
||||
equal( menu.attr( "aria-hidden" ), "false", "open: menu aria-disabled" );
|
||||
assert.ok( menu.is( ":visible" ), "open: menu visible" );
|
||||
assert.equal( menu.attr( "aria-hidden" ), "false", "open: menu aria-disabled" );
|
||||
|
||||
element.selectmenu( "close" );
|
||||
ok( menu.is( ":hidden" ), "close: menu hidden" );
|
||||
equal( menu.attr( "aria-hidden" ), "true", "close: menu aria-disabled" );
|
||||
assert.ok( menu.is( ":hidden" ), "close: menu hidden" );
|
||||
assert.equal( menu.attr( "aria-hidden" ), "true", "close: menu aria-disabled" );
|
||||
} );
|
||||
|
||||
test( "enable / disable", function() {
|
||||
expect( 10 );
|
||||
QUnit.test( "enable / disable", function( assert ) {
|
||||
assert.expect( 10 );
|
||||
|
||||
var element = $( "#speed" ).selectmenu(),
|
||||
button = element.selectmenu( "widget" ),
|
||||
menu = element.selectmenu( "menuWidget" );
|
||||
|
||||
element.selectmenu( "disable" );
|
||||
ok( element.selectmenu( "option", "disabled" ), "disable: widget option" );
|
||||
equal( element.attr( "disabled" ), "disabled", "disable: native select disabled" );
|
||||
equal( button.attr( "aria-disabled" ), "true", "disable: button ARIA" );
|
||||
equal( button.attr( "tabindex" ), -1, "disable: button tabindex" );
|
||||
equal( menu.attr( "aria-disabled" ), "true", "disable: menu ARIA" );
|
||||
assert.ok( element.selectmenu( "option", "disabled" ), "disable: widget option" );
|
||||
assert.equal( element.attr( "disabled" ), "disabled", "disable: native select disabled" );
|
||||
assert.equal( button.attr( "aria-disabled" ), "true", "disable: button ARIA" );
|
||||
assert.equal( button.attr( "tabindex" ), -1, "disable: button tabindex" );
|
||||
assert.equal( menu.attr( "aria-disabled" ), "true", "disable: menu ARIA" );
|
||||
|
||||
element.selectmenu( "enable" );
|
||||
ok( !element.selectmenu( "option", "disabled" ), "enable: widget option" );
|
||||
equal( element.attr( "disabled" ), undefined, "enable: native select disabled" );
|
||||
equal( button.attr( "aria-disabled" ), "false", "enable: button ARIA" );
|
||||
equal( button.attr( "tabindex" ), 0, "enable: button tabindex" );
|
||||
equal( menu.attr( "aria-disabled" ), "false", "enable: menu ARIA" );
|
||||
assert.ok( !element.selectmenu( "option", "disabled" ), "enable: widget option" );
|
||||
assert.equal( element.attr( "disabled" ), undefined, "enable: native select disabled" );
|
||||
assert.equal( button.attr( "aria-disabled" ), "false", "enable: button ARIA" );
|
||||
assert.equal( button.attr( "tabindex" ), 0, "enable: button tabindex" );
|
||||
assert.equal( menu.attr( "aria-disabled" ), "false", "enable: menu ARIA" );
|
||||
} );
|
||||
|
||||
test( "refresh - structure", function() {
|
||||
expect( 3 );
|
||||
QUnit.test( "refresh - structure", function( assert ) {
|
||||
assert.expect( 3 );
|
||||
|
||||
var menuItems,
|
||||
element = $( "#speed" ).selectmenu(),
|
||||
@ -70,39 +71,40 @@ test( "refresh - structure", function() {
|
||||
options = element.find( "option" );
|
||||
menuItems = menu.find( "li" ).not( ".ui-selectmenu-optgroup" );
|
||||
|
||||
equal( options.length, menuItems.length, "menu item length" );
|
||||
equal( "Added option", menuItems.last().text(), "added item" );
|
||||
equal( "Changed value", menuItems.eq( 0 ).text(), "changed item" );
|
||||
assert.equal( options.length, menuItems.length, "menu item length" );
|
||||
assert.equal( "Added option", menuItems.last().text(), "added item" );
|
||||
assert.equal( "Changed value", menuItems.eq( 0 ).text(), "changed item" );
|
||||
} );
|
||||
|
||||
asyncTest( "refresh - change selected option", function() {
|
||||
expect( 4 );
|
||||
QUnit.test( "refresh - change selected option", function( assert ) {
|
||||
var ready = assert.async();
|
||||
assert.expect( 4 );
|
||||
|
||||
var element = $( "#speed" ).selectmenu(),
|
||||
button = element.selectmenu( "widget" );
|
||||
|
||||
equal( $.trim( button.text() ), "Medium", "button text after init" );
|
||||
assert.equal( $.trim( button.text() ), "Medium", "button text after init" );
|
||||
|
||||
button.simulate( "focus" );
|
||||
|
||||
setTimeout( function() {
|
||||
equal( $.trim( button.text() ), "Medium", "button text after focus" );
|
||||
assert.equal( $.trim( button.text() ), "Medium", "button text after focus" );
|
||||
|
||||
element[ 0 ].selectedIndex = 0;
|
||||
element.selectmenu( "refresh" );
|
||||
equal( $.trim( button.text() ), "Slower", "button text after changing selected option" );
|
||||
assert.equal( $.trim( button.text() ), "Slower", "button text after changing selected option" );
|
||||
|
||||
element.find( "option" ).prop( "selected", false );
|
||||
element.append( "<option selected value=\"selected_option\">Selected option</option>" );
|
||||
element.selectmenu( "refresh" );
|
||||
equal( $.trim( button.text() ), "Selected option", "button text after adding selected option" );
|
||||
assert.equal( $.trim( button.text() ), "Selected option", "button text after adding selected option" );
|
||||
|
||||
start();
|
||||
ready();
|
||||
} );
|
||||
} );
|
||||
|
||||
test( "refresh - disabled select", function() {
|
||||
expect( 4 );
|
||||
QUnit.test( "refresh - disabled select", function( assert ) {
|
||||
assert.expect( 4 );
|
||||
|
||||
var element = $( "#speed" ).selectmenu(),
|
||||
button = element.selectmenu( "widget" ),
|
||||
@ -111,14 +113,14 @@ test( "refresh - disabled select", function() {
|
||||
element.prop( "disabled", true );
|
||||
element.selectmenu( "refresh" );
|
||||
|
||||
ok( element.selectmenu( "option", "disabled" ), "widget option" );
|
||||
equal( button.attr( "aria-disabled" ), "true", "button ARIA" );
|
||||
equal( button.attr( "tabindex" ), -1, "button tabindex" );
|
||||
equal( menu.attr( "aria-disabled" ), "true", "menu ARIA" );
|
||||
assert.ok( element.selectmenu( "option", "disabled" ), "widget option" );
|
||||
assert.equal( button.attr( "aria-disabled" ), "true", "button ARIA" );
|
||||
assert.equal( button.attr( "tabindex" ), -1, "button tabindex" );
|
||||
assert.equal( menu.attr( "aria-disabled" ), "true", "menu ARIA" );
|
||||
} );
|
||||
|
||||
test( "refresh - disabled option", function( assert ) {
|
||||
expect( 1 );
|
||||
QUnit.test( "refresh - disabled option", function( assert ) {
|
||||
assert.expect( 1 );
|
||||
|
||||
var disabledItem,
|
||||
element = $( "#speed" ).selectmenu(),
|
||||
@ -131,14 +133,14 @@ test( "refresh - disabled option", function( assert ) {
|
||||
assert.hasClasses( disabledItem, "ui-state-disabled" );
|
||||
} );
|
||||
|
||||
test( "refresh - disabled optgroup", function( assert ) {
|
||||
QUnit.test( "refresh - disabled optgroup", function( assert ) {
|
||||
var i, item,
|
||||
element = $( "#files" ).selectmenu(),
|
||||
menu = element.selectmenu( "menuWidget" ).parent(),
|
||||
originalDisabledOptgroup = element.find( "optgroup" ).first(),
|
||||
originalDisabledOptions = originalDisabledOptgroup.find( "option" );
|
||||
|
||||
expect( 2 + originalDisabledOptions.length );
|
||||
assert.expect( 2 + originalDisabledOptions.length );
|
||||
|
||||
originalDisabledOptgroup.prop( "disabled", true );
|
||||
element.selectmenu( "refresh" );
|
||||
@ -147,7 +149,7 @@ test( "refresh - disabled optgroup", function( assert ) {
|
||||
|
||||
assert.hasClasses( item, "ui-state-disabled" );
|
||||
|
||||
equal(
|
||||
assert.equal(
|
||||
menu.find( "li" ).not( ".ui-selectmenu-optgroup" ).filter( ".ui-state-disabled" ).length,
|
||||
originalDisabledOptions.length,
|
||||
"disabled options"
|
||||
@ -158,8 +160,8 @@ test( "refresh - disabled optgroup", function( assert ) {
|
||||
}
|
||||
} );
|
||||
|
||||
test( "refresh - remove all options", function() {
|
||||
expect( 2 );
|
||||
QUnit.test( "refresh - remove all options", function( assert ) {
|
||||
assert.expect( 2 );
|
||||
|
||||
var element = $( "#speed" ).selectmenu(),
|
||||
button = element.selectmenu( "widget" ),
|
||||
@ -167,23 +169,23 @@ test( "refresh - remove all options", function() {
|
||||
|
||||
element.children().remove();
|
||||
element.selectmenu( "refresh" );
|
||||
equal( button.find( ".ui-selectmenu-text" ).html(), $( "<span> </span>" ).html(),
|
||||
assert.equal( button.find( ".ui-selectmenu-text" ).html(), $( "<span> </span>" ).html(),
|
||||
"Empty button text" );
|
||||
equal( menu.children().length, 0, "Empty menu" );
|
||||
assert.equal( menu.children().length, 0, "Empty menu" );
|
||||
} );
|
||||
|
||||
test( "widget and menuWidget", function( assert ) {
|
||||
expect( 4 );
|
||||
QUnit.test( "widget and menuWidget", function( assert ) {
|
||||
assert.expect( 4 );
|
||||
|
||||
var element = $( "#speed" ).selectmenu(),
|
||||
button = element.selectmenu( "widget" ),
|
||||
menu = element.selectmenu( "menuWidget" );
|
||||
|
||||
equal( button.length, 1, "button: one element" );
|
||||
assert.equal( button.length, 1, "button: one element" );
|
||||
assert.hasClasses( button, "ui-button" );
|
||||
|
||||
equal( menu.length, 1, "Menu Widget: one element" );
|
||||
ok( menu.is( "ul.ui-menu" ), "Menu Widget: element and class" );
|
||||
assert.equal( menu.length, 1, "Menu Widget: one element" );
|
||||
assert.ok( menu.is( "ul.ui-menu" ), "Menu Widget: element and class" );
|
||||
} );
|
||||
|
||||
} );
|
||||
|
@ -1,20 +1,21 @@
|
||||
define( [
|
||||
"qunit",
|
||||
"jquery",
|
||||
"ui/widgets/selectmenu"
|
||||
], function( $ ) {
|
||||
], function( QUnit, $ ) {
|
||||
|
||||
module( "selectmenu: options" );
|
||||
QUnit.module( "selectmenu: options" );
|
||||
|
||||
test( "appendTo: null", function() {
|
||||
expect( 1 );
|
||||
QUnit.test( "appendTo: null", function( assert ) {
|
||||
assert.expect( 1 );
|
||||
|
||||
var element = $( "#speed" ).selectmenu();
|
||||
equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ], document.body,
|
||||
assert.equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ], document.body,
|
||||
"defaults to body" );
|
||||
} );
|
||||
|
||||
test( "appendTo: explicit", function() {
|
||||
expect( 6 );
|
||||
QUnit.test( "appendTo: explicit", function( assert ) {
|
||||
assert.expect( 6 );
|
||||
|
||||
var detached = $( "<div>" ),
|
||||
element = $( "#speed" );
|
||||
@ -22,56 +23,56 @@ test( "appendTo: explicit", function() {
|
||||
element.selectmenu( {
|
||||
appendTo: ".selectmenu-wrap"
|
||||
} );
|
||||
equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ],
|
||||
assert.equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ],
|
||||
$( "#selectmenu-wrap1" )[ 0 ], "first found element" );
|
||||
equal( $( "#selectmenu-wrap2 .ui-selectmenu" ).length, 0, "only appends to one element" );
|
||||
assert.equal( $( "#selectmenu-wrap2 .ui-selectmenu" ).length, 0, "only appends to one element" );
|
||||
element.selectmenu( "destroy" );
|
||||
|
||||
element.selectmenu().selectmenu( "option", "appendTo", "#selectmenu-wrap1" );
|
||||
equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ],
|
||||
assert.equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ],
|
||||
$( "#selectmenu-wrap1" )[ 0 ], "modified after init" );
|
||||
element.selectmenu( "destroy" );
|
||||
|
||||
element.selectmenu( {
|
||||
appendTo: detached
|
||||
} );
|
||||
equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ], detached[ 0 ],
|
||||
assert.equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ], detached[ 0 ],
|
||||
"detached jQuery object" );
|
||||
element.selectmenu( "destroy" );
|
||||
|
||||
element.selectmenu( {
|
||||
appendTo: detached[ 0 ]
|
||||
} );
|
||||
equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ], detached[ 0 ],
|
||||
assert.equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ], detached[ 0 ],
|
||||
"detached DOM element" );
|
||||
element.selectmenu( "destroy" );
|
||||
|
||||
element.selectmenu().selectmenu( "option", "appendTo", detached );
|
||||
equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ], detached[ 0 ],
|
||||
assert.equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ], detached[ 0 ],
|
||||
"detached DOM element via option()" );
|
||||
element.selectmenu( "destroy" );
|
||||
} );
|
||||
|
||||
test( "appendTo: ui-front", function() {
|
||||
expect( 2 );
|
||||
QUnit.test( "appendTo: ui-front", function( assert ) {
|
||||
assert.expect( 2 );
|
||||
|
||||
var element = $( "#speed" );
|
||||
|
||||
$( "#selectmenu-wrap2" ).addClass( "ui-front" );
|
||||
element.selectmenu();
|
||||
equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ],
|
||||
assert.equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ],
|
||||
$( "#selectmenu-wrap2" )[ 0 ], "null, inside .ui-front" );
|
||||
element.selectmenu( "destroy" );
|
||||
|
||||
element.selectmenu( {
|
||||
appendTo: $()
|
||||
} );
|
||||
equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ],
|
||||
assert.equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ],
|
||||
$( "#selectmenu-wrap2" )[ 0 ], "empty jQuery object, inside .ui-front" );
|
||||
} );
|
||||
|
||||
test( "CSS styles", function( assert ) {
|
||||
expect( 5 );
|
||||
QUnit.test( "CSS styles", function( assert ) {
|
||||
assert.expect( 5 );
|
||||
|
||||
var element = $( "#speed" ).selectmenu(),
|
||||
button = element.selectmenu( "widget" ),
|
||||
@ -86,8 +87,8 @@ test( "CSS styles", function( assert ) {
|
||||
assert.lacksClasses( button, "ui-corner-all" );
|
||||
} );
|
||||
|
||||
test( "width", function() {
|
||||
expect( 6 );
|
||||
QUnit.test( "width", function( assert ) {
|
||||
assert.expect( 6 );
|
||||
|
||||
var button,
|
||||
element = $( "#speed" );
|
||||
@ -95,26 +96,26 @@ test( "width", function() {
|
||||
element.selectmenu();
|
||||
button = element.selectmenu( "widget" );
|
||||
|
||||
equal( button[ 0 ].style.width, "", "no inline style" );
|
||||
assert.equal( button[ 0 ].style.width, "", "no inline style" );
|
||||
|
||||
element.selectmenu( "option", "width", null );
|
||||
equal( button.outerWidth(), element.outerWidth(), "button width auto" );
|
||||
assert.equal( button.outerWidth(), element.outerWidth(), "button width auto" );
|
||||
|
||||
element.outerWidth( 100 );
|
||||
element.selectmenu( "refresh" );
|
||||
equal( button.outerWidth(), 100, "button width set by CSS" );
|
||||
assert.equal( button.outerWidth(), 100, "button width set by CSS" );
|
||||
|
||||
element
|
||||
.width( "" )
|
||||
.selectmenu( "option", "width", 100 )
|
||||
.selectmenu( "refresh" );
|
||||
equal( button.outerWidth(), 100, "button width set by JS option" );
|
||||
assert.equal( button.outerWidth(), 100, "button width set by JS option" );
|
||||
|
||||
element
|
||||
.append( $( "<option>", { text: "Option with a little longer text" } ) )
|
||||
.selectmenu( "option", "width", null )
|
||||
.selectmenu( "refresh" );
|
||||
equal( button.outerWidth(), element.outerWidth(), "button width with long option" );
|
||||
assert.equal( button.outerWidth(), element.outerWidth(), "button width with long option" );
|
||||
|
||||
element.parent().outerWidth( 300 );
|
||||
element
|
||||
@ -122,7 +123,7 @@ test( "width", function() {
|
||||
.css( "width", "100%" )
|
||||
.selectmenu( { width: null } );
|
||||
button = element.selectmenu( "widget" );
|
||||
equal( button.outerWidth(), 300, "button width fills container" );
|
||||
assert.equal( button.outerWidth(), 300, "button width fills container" );
|
||||
} );
|
||||
|
||||
} );
|
||||
|
Loading…
Reference in New Issue
Block a user