Selectmenu: Test cleanup

This commit is contained in:
Scott González 2014-04-22 12:19:12 -04:00
parent d8062dc4cf
commit 56f6f92314

View File

@ -1,29 +1,29 @@
(function ( $ ) { (function ( $ ) {
module( "selectmenu: events", { module( "selectmenu: events", {
setup: function () { setup: function() {
this.element = $( "#speed" ); this.element = $( "#speed" );
} }
}); });
asyncTest( "change", function () { asyncTest( "change", function() {
expect( 5 ); expect( 3 );
var optionIndex = 1, var button, menu, options,
button, menu, options; optionIndex = 1;
this.element.selectmenu({ this.element.selectmenu({
change: function ( event, ui ) { change: function ( event, ui ) {
ok( event, "change event fired on change" );
equal( event.type, "selectmenuchange", "event type set to selectmenuchange" );
equal( ui.item.index, optionIndex, "ui.item.index contains correct option index" ); equal( ui.item.index, optionIndex, "ui.item.index contains correct option index" );
equal( ui.item.element[ 0 ], options.eq( optionIndex )[ 0 ], "ui.item.element contains original option element" ); equal( ui.item.element[ 0 ], options.eq( optionIndex )[ 0 ],
equal( ui.item.value, options.eq( optionIndex ).text(), "ui.item.value property updated correctly" ); "ui.item.element contains original option element" );
equal( ui.item.value, options.eq( optionIndex ).text(),
"ui.item.value property updated correctly" );
} }
}); });
button = this.element.selectmenu( "widget" ); button = this.element.selectmenu( "widget" );
menu = this.element.selectmenu( "menuWidget" ).parent(); menu = this.element.selectmenu( "menuWidget" );
options = this.element.find( "option" ); options = this.element.find( "option" );
button.simulate( "focus" ); button.simulate( "focus" );
@ -32,41 +32,46 @@ asyncTest( "change", function () {
button.trigger( "click" ); button.trigger( "click" );
menu.find( "li" ).eq( optionIndex ).simulate( "mouseover" ).trigger( "click" ); menu.find( "li" ).eq( optionIndex ).simulate( "mouseover" ).trigger( "click" );
start(); start();
}, 1 ); });
}); });
test( "close", function () { test( "close", function() {
expect( 4 ); expect( 2 );
var shouldFire;
this.element.selectmenu({ this.element.selectmenu({
close: function ( event ) { close: function() {
ok( event, "close event fired on close" ); ok( shouldFire, "close event fired on close" );
equal( event.type, "selectmenuclose", "event type set to selectmenuclose" );
} }
}); });
this.element.selectmenu( "open" ).selectmenu( "close" ); shouldFire = false;
this.element.selectmenu( "open" )
shouldFire = true;
this.element.selectmenu( "close" );
shouldFire = false;
this.element.selectmenu( "open" ); this.element.selectmenu( "open" );
shouldFire = true;
$( "body" ).trigger( "mousedown" ); $( "body" ).trigger( "mousedown" );
}); });
asyncTest( "focus", function () { asyncTest( "focus", function() {
expect( 12 ); expect( 9 );
var that = this, var button, menu, links,
that = this,
optionIndex = this.element[ 0 ].selectedIndex + 1, optionIndex = this.element[ 0 ].selectedIndex + 1,
options = this.element.find( "option" ), options = this.element.find( "option" );
button, menu, links;
this.element.selectmenu({ this.element.selectmenu({
focus: function ( event, ui ) { focus: function( event, ui ) {
ok( event, "focus event fired on element #" + optionIndex + " mouseover" ); ok( true, "focus event fired on element #" + optionIndex + " mouseover" );
equal( event.type, "selectmenufocus", "event type set to selectmenufocus" );
equal( ui.item.index, optionIndex, "ui.item.index contains correct option index" ); equal( ui.item.index, optionIndex, "ui.item.index contains correct option index" );
equal( ui.item.element[ 0 ], options.eq( optionIndex )[ 0 ], "ui.item.element contains original option element" ); equal( ui.item.element[ 0 ], options.eq( optionIndex )[ 0 ],
"ui.item.element contains original option element" );
} }
}); });
@ -74,7 +79,6 @@ asyncTest( "focus", function () {
menu = this.element.selectmenu( "menuWidget" ); menu = this.element.selectmenu( "menuWidget" );
button.simulate( "focus" ); button.simulate( "focus" );
setTimeout(function() { setTimeout(function() {
button.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); button.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
@ -85,20 +89,19 @@ asyncTest( "focus", function () {
optionIndex += 1; optionIndex += 1;
links.eq( optionIndex ).simulate( "mouseover" ); links.eq( optionIndex ).simulate( "mouseover" );
// this tests for unwanted, additional focus event on close // This tests for unwanted, additional focus event on close
that.element.selectmenu( "close" ); that.element.selectmenu( "close" );
start(); start();
}, 1 ); });
}); });
test( "open", function () { test( "open", function() {
expect( 2 ); expect( 1 );
this.element.selectmenu({ this.element.selectmenu({
open: function ( event ) { open: function() {
ok( event, "open event fired on open" ); ok( true, "open event fired on open" );
equal( event.type, "selectmenuopen", "event type set to selectmenuopen" );
} }
}); });
@ -106,30 +109,29 @@ test( "open", function () {
}); });
asyncTest( "select", function () { asyncTest( "select", function() {
expect( 4 ); expect( 3 );
this.element.selectmenu({ this.element.selectmenu({
select: function ( event, ui ) { select: function( event, ui ) {
ok( event, "select event fired on item select" ); ok( true, "select event fired on item select" );
equal( event.type, "selectmenuselect", "event type set to selectmenuselect" );
equal( ui.item.index, optionIndex, "ui.item.index contains correct option index" ); equal( ui.item.index, optionIndex, "ui.item.index contains correct option index" );
equal( ui.item.element[ 0 ], options.eq( optionIndex )[ 0 ], "ui.item.element contains original option element" ); equal( ui.item.element[ 0 ], options.eq( optionIndex )[ 0 ],
"ui.item.element contains original option element" );
} }
}); });
var button = this.element.selectmenu( "widget" ), var button = this.element.selectmenu( "widget" ),
menu = this.element.selectmenu( "menuWidget" ).parent(), menu = this.element.selectmenu( "menuWidget" ),
options = this.element.find( "option" ), options = this.element.find( "option" ),
optionIndex = 1; optionIndex = 1;
button.simulate( "focus" ); button.simulate( "focus" );
setTimeout(function() { setTimeout(function() {
button.trigger( "click" ); button.trigger( "click" );
menu.find( "li" ).eq( optionIndex ).simulate( "mouseover" ).trigger( "click" ); menu.find( "li" ).eq( optionIndex ).simulate( "mouseover" ).trigger( "click" );
start(); start();
}, 1 ); });
}); });
})(jQuery); })( jQuery );