jquery-ui/tests/unit/selectmenu/selectmenu_events.js

134 lines
3.3 KiB
JavaScript
Raw Normal View History

2013-04-29 18:47:02 +00:00
(function ( $ ) {
module( "selectmenu: events", {
2014-04-22 16:19:12 +00:00
setup: function() {
this.element = $( "#speed" );
}
});
2014-04-22 16:19:12 +00:00
asyncTest( "change", function() {
expect( 3 );
2014-04-22 16:19:12 +00:00
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" );
2014-04-22 16:19:12 +00:00
equal( ui.item.element[ 0 ], options.eq( optionIndex )[ 0 ],
"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" );
2014-04-22 16:19:12 +00:00
menu = this.element.selectmenu( "menuWidget" );
options = this.element.find( "option" );
button.simulate( "focus" );
setTimeout(function() {
button.trigger( "click" );
2013-10-09 23:01:41 +00:00
menu.find( "li" ).eq( optionIndex ).simulate( "mouseover" ).trigger( "click" );
start();
2014-04-22 16:19:12 +00:00
});
});
2014-04-22 16:19:12 +00:00
test( "close", function() {
expect( 2 );
var shouldFire;
this.element.selectmenu({
2014-04-22 16:19:12 +00:00
close: function() {
ok( shouldFire, "close event fired on close" );
}
});
2014-04-22 16:19:12 +00:00
shouldFire = false;
2014-04-22 16:57:05 +00:00
this.element.selectmenu( "open" );
2014-04-22 16:19:12 +00:00
shouldFire = true;
this.element.selectmenu( "close" );
shouldFire = false;
this.element.selectmenu( "open" );
2014-04-22 16:19:12 +00:00
shouldFire = true;
$( "body" ).trigger( "mousedown" );
});
2014-04-22 16:19:12 +00:00
asyncTest( "focus", function() {
expect( 9 );
2014-04-22 16:19:12 +00:00
var button, menu, links,
that = this,
optionIndex = this.element[ 0 ].selectedIndex + 1,
2014-04-22 16:19:12 +00:00
options = this.element.find( "option" );
this.element.selectmenu({
2014-04-22 16:19:12 +00:00
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" );
2014-04-22 16:19:12 +00:00
equal( ui.item.element[ 0 ], options.eq( optionIndex )[ 0 ],
"ui.item.element contains original option element" );
}
});
2013-06-04 19:16:13 +00:00
button = this.element.selectmenu( "widget" );
menu = this.element.selectmenu( "menuWidget" );
2013-06-04 19:16:13 +00:00
button.simulate( "focus" );
setTimeout(function() {
button.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
button.trigger( "click" );
2013-10-09 23:01:41 +00:00
links = menu.find( "li.ui-menu-item" );
optionIndex = 0;
links.eq( optionIndex ).simulate( "mouseover" );
optionIndex += 1;
links.eq( optionIndex ).simulate( "mouseover" );
2014-04-22 16:19:12 +00:00
// This tests for unwanted, additional focus event on close
that.element.selectmenu( "close" );
start();
2014-04-22 16:19:12 +00:00
});
});
2014-04-22 16:19:12 +00:00
test( "open", function() {
expect( 1 );
this.element.selectmenu({
2014-04-22 16:19:12 +00:00
open: function() {
ok( true, "open event fired on open" );
}
});
this.element.selectmenu( "open" );
});
2014-04-22 16:19:12 +00:00
asyncTest( "select", function() {
expect( 3 );
this.element.selectmenu({
2014-04-22 16:19:12 +00:00
select: function( event, ui ) {
ok( true, "select event fired on item select" );
equal( ui.item.index, optionIndex, "ui.item.index contains correct option index" );
2014-04-22 16:19:12 +00:00
equal( ui.item.element[ 0 ], options.eq( optionIndex )[ 0 ],
"ui.item.element contains original option element" );
}
});
var button = this.element.selectmenu( "widget" ),
2014-04-22 16:19:12 +00:00
menu = this.element.selectmenu( "menuWidget" ),
options = this.element.find( "option" ),
optionIndex = 1;
button.simulate( "focus" );
setTimeout(function() {
button.trigger( "click" );
2013-10-09 23:01:41 +00:00
menu.find( "li" ).eq( optionIndex ).simulate( "mouseover" ).trigger( "click" );
start();
2014-04-22 16:19:12 +00:00
});
});
2011-11-24 15:50:20 +00:00
2014-04-22 16:19:12 +00:00
})( jQuery );