mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Selectmenu Tests: use asyncTest when working with focus events
This commit is contained in:
parent
33317c9372
commit
1821517d81
@ -6,11 +6,12 @@ module( "selectmenu: events", {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test( "change", function () {
|
asyncTest( "change", function () {
|
||||||
expect( 5 );
|
expect( 5 );
|
||||||
|
|
||||||
var that = this,
|
var that = this,
|
||||||
optionIndex = 1;
|
optionIndex = 1,
|
||||||
|
button, menu, options;
|
||||||
|
|
||||||
this.element.selectmenu({
|
this.element.selectmenu({
|
||||||
change: function ( event, ui ) {
|
change: function ( event, ui ) {
|
||||||
@ -22,12 +23,17 @@ test( "change", function () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var button = this.element.selectmenu( "widget" ),
|
button = this.element.selectmenu( "widget" );
|
||||||
menu = this.element.selectmenu( "menuWidget" ).parent(),
|
menu = this.element.selectmenu( "menuWidget" ).parent();
|
||||||
options = this.element.find( "option" );
|
options = this.element.find( "option" );
|
||||||
|
|
||||||
button.simulate( "focus" ).simulate( "click" );
|
button.simulate( "focus" );
|
||||||
menu.find( "a" ).eq( optionIndex ).simulate( "mouseover" ).simulate( "click" );
|
|
||||||
|
setTimeout(function() {
|
||||||
|
button.simulate( "click" );
|
||||||
|
menu.find( "a" ).eq( optionIndex ).simulate( "mouseover" ).simulate( "click" );
|
||||||
|
start();
|
||||||
|
}, 1 );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@ -40,20 +46,21 @@ test( "close", function () {
|
|||||||
equal( event.type, "selectmenuclose", "event type set to selectmenuclose" );
|
equal( event.type, "selectmenuclose", "event type set to selectmenuclose" );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.element.selectmenu( "open" ).selectmenu( "close" );
|
this.element.selectmenu( "open" ).selectmenu( "close" );
|
||||||
|
|
||||||
this.element.selectmenu( "open" );
|
this.element.selectmenu( "open" );
|
||||||
$( "body" ).simulate( "click" );
|
$( "body" ).simulate( "click" );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
test( "focus", function () {
|
asyncTest( "focus", function () {
|
||||||
expect( 12 );
|
expect( 12 );
|
||||||
|
|
||||||
var button, menu, links,
|
var 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 ) {
|
||||||
@ -67,19 +74,22 @@ test( "focus", function () {
|
|||||||
button = this.element.selectmenu( "widget" ),
|
button = this.element.selectmenu( "widget" ),
|
||||||
menu = this.element.selectmenu( "menuWidget" );
|
menu = this.element.selectmenu( "menuWidget" );
|
||||||
|
|
||||||
button
|
button.simulate( "focus" )
|
||||||
.simulate( "focus" )
|
|
||||||
.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
|
||||||
|
|
||||||
button.simulate( "click" );
|
setTimeout(function() {
|
||||||
links = menu.find( "li.ui-menu-item a" );
|
button.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
||||||
optionIndex = 0;
|
|
||||||
links.eq( optionIndex ).simulate( "mouseover" );
|
|
||||||
optionIndex += 1;
|
|
||||||
links.eq( optionIndex ).simulate( "mouseover" );
|
|
||||||
|
|
||||||
// this tests for unwanted, additional focus event on close
|
button.simulate( "click" );
|
||||||
this.element.selectmenu( "close" );
|
links = menu.find( "li.ui-menu-item a" );
|
||||||
|
optionIndex = 0;
|
||||||
|
links.eq( optionIndex ).simulate( "mouseover" );
|
||||||
|
optionIndex += 1;
|
||||||
|
links.eq( optionIndex ).simulate( "mouseover" );
|
||||||
|
|
||||||
|
// this tests for unwanted, additional focus event on close
|
||||||
|
that.element.selectmenu( "close" );
|
||||||
|
start();
|
||||||
|
}, 1 );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@ -97,7 +107,7 @@ test( "open", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
test( "select", function () {
|
asyncTest( "select", function () {
|
||||||
expect( 4 );
|
expect( 4 );
|
||||||
|
|
||||||
this.element.selectmenu({
|
this.element.selectmenu({
|
||||||
@ -114,8 +124,13 @@ test( "select", function () {
|
|||||||
options = this.element.find( "option" ),
|
options = this.element.find( "option" ),
|
||||||
optionIndex = 1;
|
optionIndex = 1;
|
||||||
|
|
||||||
button.simulate( "focus" ).simulate( "click" );
|
button.simulate( "focus" );
|
||||||
menu.find( "a" ).eq( optionIndex ).simulate( "mouseover" ).simulate( "click" );
|
|
||||||
|
setTimeout(function() {
|
||||||
|
button.simulate( "click" );
|
||||||
|
menu.find( "a" ).eq( optionIndex ).simulate( "mouseover" ).simulate( "click" );
|
||||||
|
start();
|
||||||
|
}, 1 );
|
||||||
});
|
});
|
||||||
|
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
|
@ -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" );
|
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 );
|
expect( 3 );
|
||||||
|
|
||||||
var element = $( "#speed" ).selectmenu(),
|
var element = $( "#speed" ).selectmenu(),
|
||||||
@ -78,13 +78,16 @@ test( "refresh - change selected option", function () {
|
|||||||
|
|
||||||
button.simulate( "focus" );
|
button.simulate( "focus" );
|
||||||
|
|
||||||
equal( element.find( "option:selected" ).text(), button.text(), "button text after focus" );
|
setTimeout(function() {
|
||||||
|
equal( element.find( "option:selected" ).text(), button.text(), "button text after focus" );
|
||||||
|
|
||||||
element.find( "option" ).eq( 2 ).removeAttr( "selected" );
|
element[ 0 ].selectedIndex = 0
|
||||||
element.find( "option" ).eq( 0 ).attr( "selected", "selected" );
|
element.selectmenu( "refresh" );
|
||||||
element.selectmenu( "refresh" );
|
|
||||||
|
|
||||||
equal( element.find( "option:selected" ).text(), button.text(), "button text after changing selected option" );
|
equal( element.find( "option:selected" ).text(), button.text(), "button text after changing selected option" );
|
||||||
|
|
||||||
|
start();
|
||||||
|
}, 1 );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user