2015-04-06 18:40:47 +00:00
|
|
|
define( [
|
2016-04-06 13:16:23 +00:00
|
|
|
"qunit",
|
2015-04-06 18:40:47 +00:00
|
|
|
"jquery",
|
2015-07-15 02:06:31 +00:00
|
|
|
"ui/widgets/selectmenu"
|
2016-04-06 13:16:23 +00:00
|
|
|
], function( QUnit, $ ) {
|
2011-10-19 17:47:02 +00:00
|
|
|
|
2016-04-06 13:16:23 +00:00
|
|
|
QUnit.module( "selectmenu: events", {
|
|
|
|
beforeEach: function() {
|
2013-02-13 22:58:14 +00:00
|
|
|
this.element = $( "#speed" );
|
2012-01-13 18:49:42 +00:00
|
|
|
}
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2016-04-06 13:16:23 +00:00
|
|
|
QUnit.test( "change", function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 3 );
|
2013-05-30 19:11:08 +00:00
|
|
|
|
2014-04-22 16:19:12 +00:00
|
|
|
var button, menu, options,
|
|
|
|
optionIndex = 1;
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2015-08-24 12:50:24 +00:00
|
|
|
this.element.selectmenu( {
|
|
|
|
change: function( event, ui ) {
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( ui.item.index, optionIndex, "ui.item.index contains correct option index" );
|
|
|
|
assert.equal( ui.item.element[ 0 ], options.eq( optionIndex )[ 0 ],
|
2014-04-22 16:19:12 +00:00
|
|
|
"ui.item.element contains original option element" );
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( ui.item.value, options.eq( optionIndex ).text(),
|
2014-04-22 16:19:12 +00:00
|
|
|
"ui.item.value property updated correctly" );
|
2012-01-13 18:49:42 +00:00
|
|
|
}
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2013-05-30 20:30:56 +00:00
|
|
|
button = this.element.selectmenu( "widget" );
|
2014-04-22 16:19:12 +00:00
|
|
|
menu = this.element.selectmenu( "menuWidget" );
|
2013-05-30 20:30:56 +00:00
|
|
|
options = this.element.find( "option" );
|
2012-01-22 13:12:52 +00:00
|
|
|
|
2013-05-30 20:30:56 +00:00
|
|
|
button.simulate( "focus" );
|
|
|
|
|
2015-08-24 12:50:24 +00:00
|
|
|
setTimeout( function() {
|
2013-07-01 20:04:30 +00:00
|
|
|
button.trigger( "click" );
|
2013-10-09 23:01:41 +00:00
|
|
|
menu.find( "li" ).eq( optionIndex ).simulate( "mouseover" ).trigger( "click" );
|
2016-04-06 13:16:23 +00:00
|
|
|
ready();
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
|
|
|
} );
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2016-04-06 13:16:23 +00:00
|
|
|
QUnit.test( "close", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2014-04-22 16:19:12 +00:00
|
|
|
|
|
|
|
var shouldFire;
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2015-08-24 12:50:24 +00:00
|
|
|
this.element.selectmenu( {
|
2014-04-22 16:19:12 +00:00
|
|
|
close: function() {
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.ok( shouldFire, "close event fired on close" );
|
2012-01-13 18:49:42 +00:00
|
|
|
}
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
2013-05-30 20:30:56 +00:00
|
|
|
|
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;
|
2013-05-30 19:21:44 +00:00
|
|
|
this.element.selectmenu( "open" );
|
2014-04-22 16:19:12 +00:00
|
|
|
shouldFire = true;
|
2013-10-29 19:54:16 +00:00
|
|
|
$( "body" ).trigger( "mousedown" );
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2016-04-06 13:16:23 +00:00
|
|
|
QUnit.test( "focus", function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 9 );
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2014-04-22 16:19:12 +00:00
|
|
|
var button, menu, links,
|
|
|
|
that = this,
|
2013-05-30 19:02:38 +00:00
|
|
|
optionIndex = this.element[ 0 ].selectedIndex + 1,
|
2014-04-22 16:19:12 +00:00
|
|
|
options = this.element.find( "option" );
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2015-08-24 12:50:24 +00:00
|
|
|
this.element.selectmenu( {
|
2014-04-22 16:19:12 +00:00
|
|
|
focus: function( event, ui ) {
|
2016-04-06 13:16:23 +00:00
|
|
|
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 ],
|
2014-04-22 16:19:12 +00:00
|
|
|
"ui.item.element contains original option element" );
|
2012-01-13 18:49:42 +00:00
|
|
|
}
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
2013-02-13 22:58:14 +00:00
|
|
|
|
2013-06-04 19:16:13 +00:00
|
|
|
button = this.element.selectmenu( "widget" );
|
2013-02-13 22:58:14 +00:00
|
|
|
menu = this.element.selectmenu( "menuWidget" );
|
2012-12-12 17:37:57 +00:00
|
|
|
|
2013-06-04 19:16:13 +00:00
|
|
|
button.simulate( "focus" );
|
2015-08-24 12:50:24 +00:00
|
|
|
setTimeout( function() {
|
2013-05-30 20:30:56 +00:00
|
|
|
button.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
2013-02-13 22:58:14 +00:00
|
|
|
|
2013-07-01 20:04:30 +00:00
|
|
|
button.trigger( "click" );
|
2013-10-09 23:01:41 +00:00
|
|
|
links = menu.find( "li.ui-menu-item" );
|
2013-05-30 20:30:56 +00:00
|
|
|
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
|
2013-05-30 20:30:56 +00:00
|
|
|
that.element.selectmenu( "close" );
|
2016-04-06 13:16:23 +00:00
|
|
|
ready();
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
|
|
|
} );
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2016-04-06 13:16:23 +00:00
|
|
|
QUnit.test( "open", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2015-08-24 12:50:24 +00:00
|
|
|
this.element.selectmenu( {
|
2014-04-22 16:19:12 +00:00
|
|
|
open: function() {
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.ok( true, "open event fired on open" );
|
2012-01-13 18:49:42 +00:00
|
|
|
}
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2013-02-13 22:58:14 +00:00
|
|
|
this.element.selectmenu( "open" );
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2016-04-06 13:16:23 +00:00
|
|
|
QUnit.test( "select", function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 3 );
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2015-08-24 12:50:24 +00:00
|
|
|
this.element.selectmenu( {
|
2014-04-22 16:19:12 +00:00
|
|
|
select: function( event, ui ) {
|
2016-04-06 13:16:23 +00:00
|
|
|
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 ],
|
2014-04-22 16:19:12 +00:00
|
|
|
"ui.item.element contains original option element" );
|
2012-01-13 18:49:42 +00:00
|
|
|
}
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2013-03-07 18:15:46 +00:00
|
|
|
var button = this.element.selectmenu( "widget" ),
|
2014-04-22 16:19:12 +00:00
|
|
|
menu = this.element.selectmenu( "menuWidget" ),
|
2013-05-30 19:11:08 +00:00
|
|
|
options = this.element.find( "option" ),
|
|
|
|
optionIndex = 1;
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2013-05-30 20:30:56 +00:00
|
|
|
button.simulate( "focus" );
|
2015-08-24 12:50:24 +00:00
|
|
|
setTimeout( function() {
|
2013-07-01 20:04:30 +00:00
|
|
|
button.trigger( "click" );
|
2013-10-09 23:01:41 +00:00
|
|
|
menu.find( "li" ).eq( optionIndex ).simulate( "mouseover" ).trigger( "click" );
|
2016-04-06 13:16:23 +00:00
|
|
|
ready();
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
|
|
|
} );
|
2011-11-24 15:50:20 +00:00
|
|
|
|
2015-04-06 18:40:47 +00:00
|
|
|
} );
|