2012-06-18 17:26:46 +00:00
|
|
|
(function( $ ) {
|
2010-05-06 15:10:52 +00:00
|
|
|
|
2012-04-19 16:19:52 +00:00
|
|
|
var log = TestHelpers.menu.log,
|
2012-06-18 17:26:46 +00:00
|
|
|
logOutput = TestHelpers.menu.logOutput,
|
2012-04-19 16:19:52 +00:00
|
|
|
click = TestHelpers.menu.click;
|
|
|
|
|
2012-06-18 17:26:46 +00:00
|
|
|
module( "menu: options", {
|
|
|
|
setup: function() {
|
|
|
|
TestHelpers.menu.clearLog();
|
|
|
|
}
|
|
|
|
});
|
2010-05-06 15:10:52 +00:00
|
|
|
|
2012-01-22 17:26:41 +00:00
|
|
|
test( "{ disabled: true }", function() {
|
|
|
|
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
|
|
|
}
|
|
|
|
});
|
2012-07-10 18:01:23 +00:00
|
|
|
ok( element.hasClass( "ui-state-disabled" ), "Missing ui-state-disabled class" );
|
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
|
|
|
|
2012-01-22 17:26:41 +00:00
|
|
|
test( "{ disabled: false }", function() {
|
|
|
|
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
|
|
|
}
|
|
|
|
});
|
2012-07-10 18:01:23 +00:00
|
|
|
ok( !element.hasClass( "ui-state-disabled" ), "Has ui-state-disabled class" );
|
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
|
|
|
|
2012-07-12 15:23:33 +00:00
|
|
|
test( "{ icons: default }", function() {
|
2012-12-27 16:23:25 +00:00
|
|
|
expect( 2 );
|
2012-07-12 15:23:33 +00:00
|
|
|
var element = $( "#menu2" ).menu();
|
|
|
|
equal( element.find( ".ui-menu-icon" ).attr( "class" ), "ui-menu-icon ui-icon ui-icon-carat-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" );
|
2012-12-27 16:23:25 +00:00
|
|
|
equal( element.find( ".ui-menu-icon" ).attr( "class" ), "ui-menu-icon ui-icon ui-icon-triangle-1-e" );
|
2012-07-12 15:23:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test( "{ icons: { submenu: 'custom' } }", function() {
|
|
|
|
expect( 1 );
|
|
|
|
var element = $( "#menu2" ).menu({
|
|
|
|
icons: {
|
|
|
|
submenu: "custom-class"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
equal( element.find( ".ui-menu-icon" ).attr( "class" ), "ui-menu-icon ui-icon custom-class" );
|
|
|
|
});
|
2012-07-10 17:58:20 +00:00
|
|
|
|
|
|
|
// TODO: test menus option
|
|
|
|
|
|
|
|
// TODO: test position option
|
|
|
|
|
|
|
|
test( "{ role: 'menu' } ", function() {
|
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 ) {
|
|
|
|
ok( $( this ).hasClass( "ui-menu-item" ), "menu item ("+ item + ") class for item" );
|
2013-09-18 04:22:33 +00:00
|
|
|
equal( $( this ).attr( "role" ), "menuitem", "menu item ("+ item + ") role" );
|
|
|
|
equal( $( this ).attr( "tabindex" ), "-1", "tabindex for menu item ("+ item + ")" );
|
2012-05-18 14:04:54 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2012-07-10 17:58:20 +00:00
|
|
|
test( "{ role: 'listbox' } ", function() {
|
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 ) {
|
2012-07-10 17:58:20 +00:00
|
|
|
ok( $( this ).hasClass( "ui-menu-item" ), "menu item ("+ item + ") class for item" );
|
2013-09-18 04:22:33 +00:00
|
|
|
equal( $( this ).attr( "role" ), "option", "menu item ("+ item + ") role" );
|
|
|
|
equal( $( this ).attr( "tabindex" ), "-1", "tabindex for menu item ("+ item + ")" );
|
2012-07-10 17:58:20 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test( "{ role: null }", function() {
|
|
|
|
var element = $( "#menu1" ).menu({
|
|
|
|
role: null
|
|
|
|
}),
|
|
|
|
items = element.find( "li" );
|
2013-11-15 11:51:10 +00:00
|
|
|
expect( 2 + 3 * items.length );
|
2012-07-10 17:58:20 +00:00
|
|
|
strictEqual( element.attr( "role" ), undefined );
|
|
|
|
ok( items.length > 0, "number of menu items" );
|
|
|
|
items.each(function( item ) {
|
|
|
|
ok( $( this ).hasClass( "ui-menu-item" ), "menu item ("+ item + ") class for item" );
|
2013-09-18 04:22:33 +00:00
|
|
|
equal( $( this ).attr( "role" ), undefined, "menu item ("+ item + ") role" );
|
|
|
|
equal( $( this ).attr( "tabindex" ), "-1", "tabindex for menu item ("+ item + ")" );
|
2012-05-18 14:04:54 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2012-06-18 17:26:46 +00:00
|
|
|
})( jQuery );
|