2015-04-06 17:04:04 +00:00
|
|
|
define( [
|
|
|
|
"jquery",
|
|
|
|
"./menu_test_helpers",
|
|
|
|
"ui/menu"
|
|
|
|
], function( $, menuTestHelpers ) {
|
2010-05-06 15:10:52 +00:00
|
|
|
|
2015-04-06 17:04:04 +00:00
|
|
|
var log = menuTestHelpers.log,
|
|
|
|
logOutput = menuTestHelpers.logOutput,
|
|
|
|
click = menuTestHelpers.click;
|
2012-04-19 16:19:52 +00:00
|
|
|
|
2012-06-18 17:26:46 +00:00
|
|
|
module( "menu: options", {
|
|
|
|
setup: function() {
|
2015-04-06 17:04:04 +00:00
|
|
|
menuTestHelpers.clearLog();
|
2012-06-18 17:26:46 +00:00
|
|
|
}
|
|
|
|
});
|
2010-05-06 15:10:52 +00:00
|
|
|
|
2015-01-30 14:58:21 +00:00
|
|
|
test( "{ disabled: true }", function( assert ) {
|
2012-01-22 17:26:41 +00:00
|
|
|
expect( 2 );
|
2012-06-27 13:49:56 +00:00
|
|
|
var element = $( "#menu1" ).menu({
|
2012-01-22 17:26:41 +00:00
|
|
|
disabled: true,
|
2012-10-23 14:36:42 +00:00
|
|
|
select: function() {
|
2012-04-19 16:19:52 +00:00
|
|
|
log();
|
2012-01-22 17:26:41 +00:00
|
|
|
}
|
|
|
|
});
|
2015-01-30 14:58:21 +00:00
|
|
|
assert.hasClasses( element, "ui-state-disabled" );
|
2012-06-18 17:26:46 +00:00
|
|
|
log( "click", true );
|
2012-06-27 13:49:56 +00:00
|
|
|
click( element, "1" );
|
2012-06-18 17:26:46 +00:00
|
|
|
log( "afterclick" );
|
2012-06-18 17:38:16 +00:00
|
|
|
equal( logOutput(), "click,afterclick", "Click order not valid." );
|
2012-01-22 17:26:41 +00:00
|
|
|
});
|
2010-05-06 15:10:52 +00:00
|
|
|
|
2015-01-30 14:58:21 +00:00
|
|
|
test( "{ disabled: false }", function( assert ) {
|
2012-01-22 17:26:41 +00:00
|
|
|
expect( 2 );
|
2012-06-27 13:49:56 +00:00
|
|
|
var element = $( "#menu1" ).menu({
|
2012-01-22 17:26:41 +00:00
|
|
|
disabled: false,
|
2012-10-23 14:36:42 +00:00
|
|
|
select: function() {
|
2012-04-19 16:19:52 +00:00
|
|
|
log();
|
2012-01-22 17:26:41 +00:00
|
|
|
}
|
|
|
|
});
|
2015-01-30 14:58:21 +00:00
|
|
|
assert.lacksClasses( element, "ui-state-disabled" );
|
2012-06-18 17:26:46 +00:00
|
|
|
log( "click", true );
|
2012-06-27 13:49:56 +00:00
|
|
|
click( element, "1" );
|
2012-06-18 17:26:46 +00:00
|
|
|
log( "afterclick" );
|
2012-06-18 17:38:16 +00:00
|
|
|
equal( logOutput(), "click,1,afterclick", "Click order not valid." );
|
2012-01-22 17:26:41 +00:00
|
|
|
});
|
2010-05-06 15:10:52 +00:00
|
|
|
|
2015-01-30 14:58:21 +00:00
|
|
|
test( "{ icons: default }", function( assert ) {
|
|
|
|
expect( 8 );
|
2012-07-12 15:23:33 +00:00
|
|
|
var element = $( "#menu2" ).menu();
|
2015-01-30 14:58:21 +00:00
|
|
|
element.find( ".ui-menu-icon" ).each( function() {
|
|
|
|
assert.hasClasses( this, "ui-menu-icon ui-icon ui-icon-caret-1-e" );
|
|
|
|
});
|
2012-12-27 16:23:25 +00:00
|
|
|
|
2013-07-16 02:54:44 +00:00
|
|
|
element.menu( "option", "icons.submenu", "ui-icon-triangle-1-e" );
|
2015-01-30 14:58:21 +00:00
|
|
|
element.find( ".ui-menu-icon" ).each( function() {
|
|
|
|
assert.hasClasses( this, "ui-menu-icon ui-icon ui-icon-triangle-1-e" );
|
|
|
|
});
|
2012-07-12 15:23:33 +00:00
|
|
|
});
|
|
|
|
|
2015-01-30 14:58:21 +00:00
|
|
|
test( "{ icons: { submenu: 'custom' } }", function( assert ) {
|
|
|
|
expect( 4 );
|
2012-07-12 15:23:33 +00:00
|
|
|
var element = $( "#menu2" ).menu({
|
|
|
|
icons: {
|
|
|
|
submenu: "custom-class"
|
|
|
|
}
|
|
|
|
});
|
2015-01-30 14:58:21 +00:00
|
|
|
element.find( ".ui-menu-icon" ).each( function() {
|
|
|
|
assert.hasClasses( this, "ui-menu-icon ui-icon custom-class" );
|
|
|
|
});
|
2012-07-12 15:23:33 +00:00
|
|
|
});
|
2012-07-10 17:58:20 +00:00
|
|
|
|
|
|
|
// TODO: test menus option
|
|
|
|
|
|
|
|
// TODO: test position option
|
|
|
|
|
2015-01-30 14:58:21 +00:00
|
|
|
test( "{ role: 'menu' } ", function( assert ) {
|
2012-06-27 13:49:56 +00:00
|
|
|
var element = $( "#menu1" ).menu(),
|
|
|
|
items = element.find( "li" );
|
2013-11-15 11:51:10 +00:00
|
|
|
expect( 2 + 3 * items.length );
|
2012-06-27 13:49:56 +00:00
|
|
|
equal( element.attr( "role" ), "menu" );
|
2012-06-18 17:26:46 +00:00
|
|
|
ok( items.length > 0, "number of menu items" );
|
|
|
|
items.each(function( item ) {
|
2015-01-30 14:58:21 +00:00
|
|
|
assert.hasClasses( $( this ), "ui-menu-item" );
|
2014-10-25 16:18:17 +00:00
|
|
|
equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "role" ),
|
|
|
|
"menuitem", "menu item ("+ item + ") role" );
|
|
|
|
equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "tabindex" ), "-1",
|
|
|
|
"tabindex for menu item ("+ item + ")" );
|
2012-05-18 14:04:54 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-01-30 14:58:21 +00:00
|
|
|
test( "{ role: 'listbox' } ", function( assert ) {
|
2012-06-27 13:49:56 +00:00
|
|
|
var element = $( "#menu1" ).menu({
|
2012-06-18 17:26:46 +00:00
|
|
|
role: "listbox"
|
|
|
|
}),
|
2012-06-27 13:49:56 +00:00
|
|
|
items = element.find( "li" );
|
2013-11-15 11:51:10 +00:00
|
|
|
expect( 2 + 3 * items.length );
|
2012-06-27 13:49:56 +00:00
|
|
|
equal( element.attr( "role" ), "listbox" );
|
2012-06-18 17:26:46 +00:00
|
|
|
ok( items.length > 0, "number of menu items" );
|
|
|
|
items.each(function( item ) {
|
2015-01-30 14:58:21 +00:00
|
|
|
assert.hasClasses( $( this ), "ui-menu-item" );
|
2014-10-25 16:18:17 +00:00
|
|
|
equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "role" ), "option",
|
|
|
|
"menu item ("+ item + ") role" );
|
|
|
|
equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "tabindex" ), "-1",
|
|
|
|
"tabindex for menu item ("+ item + ")" );
|
2012-07-10 17:58:20 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-01-30 14:58:21 +00:00
|
|
|
test( "{ role: null }", function( assert ) {
|
2012-07-10 17:58:20 +00:00
|
|
|
var element = $( "#menu1" ).menu({
|
|
|
|
role: null
|
|
|
|
}),
|
|
|
|
items = element.find( "li" );
|
2013-11-15 11:51:10 +00:00
|
|
|
expect( 2 + 3 * items.length );
|
2015-03-23 22:42:23 +00:00
|
|
|
equal( element.attr( "role" ), null );
|
2012-07-10 17:58:20 +00:00
|
|
|
ok( items.length > 0, "number of menu items" );
|
|
|
|
items.each(function( item ) {
|
2015-01-30 14:58:21 +00:00
|
|
|
assert.hasClasses( $( this ), "ui-menu-item" );
|
2015-03-23 22:42:23 +00:00
|
|
|
equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "role" ), null,
|
2014-10-25 16:18:17 +00:00
|
|
|
"menu item ("+ item + ") role" );
|
|
|
|
equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "tabindex" ), "-1",
|
|
|
|
"tabindex for menu item ("+ item + ")" );
|
2012-05-18 14:04:54 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-04-06 17:04:04 +00:00
|
|
|
} );
|