Selectmenu Tests: use asyncTest when working with focus events

This commit is contained in:
Felix Nagel 2013-05-30 22:30:56 +02:00
parent 33317c9372
commit 1821517d81
2 changed files with 50 additions and 32 deletions

View File

@ -6,11 +6,12 @@ module( "selectmenu: events", {
}
});
test( "change", function () {
asyncTest( "change", function () {
expect( 5 );
var that = this,
optionIndex = 1;
optionIndex = 1,
button, menu, options;
this.element.selectmenu({
change: function ( event, ui ) {
@ -22,12 +23,17 @@ test( "change", function () {
}
});
var button = this.element.selectmenu( "widget" ),
menu = this.element.selectmenu( "menuWidget" ).parent(),
button = this.element.selectmenu( "widget" );
menu = this.element.selectmenu( "menuWidget" ).parent();
options = this.element.find( "option" );
button.simulate( "focus" ).simulate( "click" );
button.simulate( "focus" );
setTimeout(function() {
button.simulate( "click" );
menu.find( "a" ).eq( optionIndex ).simulate( "mouseover" ).simulate( "click" );
start();
}, 1 );
});
@ -48,12 +54,13 @@ test( "close", function () {
});
test( "focus", function () {
asyncTest( "focus", function () {
expect( 12 );
var button, menu, links,
var that = this,
optionIndex = this.element[ 0 ].selectedIndex + 1,
options = this.element.find( "option" );
options = this.element.find( "option" ),
button, menu, links;
this.element.selectmenu({
focus: function ( event, ui ) {
@ -67,9 +74,10 @@ test( "focus", function () {
button = this.element.selectmenu( "widget" ),
menu = this.element.selectmenu( "menuWidget" );
button
.simulate( "focus" )
.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
button.simulate( "focus" )
setTimeout(function() {
button.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
button.simulate( "click" );
links = menu.find( "li.ui-menu-item a" );
@ -79,7 +87,9 @@ test( "focus", function () {
links.eq( optionIndex ).simulate( "mouseover" );
// this tests for unwanted, additional focus event on close
this.element.selectmenu( "close" );
that.element.selectmenu( "close" );
start();
}, 1 );
});
@ -97,7 +107,7 @@ test( "open", function () {
});
test( "select", function () {
asyncTest( "select", function () {
expect( 4 );
this.element.selectmenu({
@ -114,8 +124,13 @@ test( "select", function () {
options = this.element.find( "option" ),
optionIndex = 1;
button.simulate( "focus" ).simulate( "click" );
button.simulate( "focus" );
setTimeout(function() {
button.simulate( "click" );
menu.find( "a" ).eq( optionIndex ).simulate( "mouseover" ).simulate( "click" );
start();
}, 1 );
});
})(jQuery);

View File

@ -68,7 +68,7 @@ test( "refresh - structure", function () {
equal( element.find( "option" ).first().text(), menu.find( "li" ).not( ".ui-selectmenu-optgroup" ).first().text(), "changed item" );
});
test( "refresh - change selected option", function () {
asyncTest( "refresh - change selected option", function () {
expect( 3 );
var element = $( "#speed" ).selectmenu(),
@ -78,13 +78,16 @@ test( "refresh - change selected option", function () {
button.simulate( "focus" );
setTimeout(function() {
equal( element.find( "option:selected" ).text(), button.text(), "button text after focus" );
element.find( "option" ).eq( 2 ).removeAttr( "selected" );
element.find( "option" ).eq( 0 ).attr( "selected", "selected" );
element[ 0 ].selectedIndex = 0
element.selectmenu( "refresh" );
equal( element.find( "option:selected" ).text(), button.text(), "button text after changing selected option" );
start();
}, 1 );
});