jquery-ui/tests/unit/menu/menu_options.js

113 lines
3.7 KiB
JavaScript
Raw Normal View History

2012-06-18 17:26:46 +00:00
(function( $ ) {
var log = TestHelpers.menu.log,
2012-06-18 17:26:46 +00:00
logOutput = TestHelpers.menu.logOutput,
click = TestHelpers.menu.click;
2012-06-18 17:26:46 +00:00
module( "menu: options", {
setup: function() {
TestHelpers.menu.clearLog();
}
});
test( "{ disabled: true }", function() {
expect( 2 );
2012-06-27 13:49:56 +00:00
var element = $( "#menu1" ).menu({
disabled: true,
select: function(event, ui) {
log();
}
});
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" );
equal( logOutput(), "click,afterclick", "Click order not valid." );
});
test( "{ disabled: false }", function() {
expect( 2 );
2012-06-27 13:49:56 +00:00
var element = $( "#menu1" ).menu({
disabled: false,
2012-06-18 17:26:46 +00:00
select: function( event, ui ) {
log();
}
});
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" );
equal( logOutput(), "click,1,afterclick", "Click order not valid." );
});
test( "{ icons: default }", function() {
expect( 1 );
var element = $( "#menu2" ).menu();
equal( element.find( ".ui-menu-icon" ).attr( "class" ), "ui-menu-icon ui-icon ui-icon-carat-1-e" );
});
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" );
});
// 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" );
2012-06-18 17:26:46 +00:00
expect( 2 + 5 * 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" );
equal( $( this ).attr( "role" ), "presentation", "menu item ("+ item + ") role" );
equal( $( "a", this ).attr( "role" ), "menuitem", "menu item ("+ item + ") role" );
2012-06-27 13:49:56 +00:00
ok( $( "a", this ).hasClass( "ui-corner-all" ), "a element class for menu item ("+ item + ")" );
equal( $( "a", this ).attr( "tabindex" ), "-1", "a element tabindex for menu item ("+ item + ")" );
2012-05-18 14:04:54 +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" );
expect( 2 + 5 * 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 ) {
ok( $( this ).hasClass( "ui-menu-item" ), "menu item ("+ item + ") class for item" );
equal( $( this ).attr( "role" ), "presentation", "menu item ("+ item + ") role" );
2012-06-18 17:26:46 +00:00
equal( $( "a", this ).attr( "role" ), "option", "menu item ("+ item + ") role" );
ok( $( "a", this ).hasClass( "ui-corner-all" ), "a element class for menu item ("+ item + ")" );
equal( $( "a", this ).attr( "tabindex" ), "-1", "a element tabindex for menu item ("+ item + ")" );
});
});
test( "{ role: null }", function() {
var element = $( "#menu1" ).menu({
role: null
}),
items = element.find( "li" );
expect( 2 + 5 * items.length );
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" );
equal( $( this ).attr( "role" ), "presentation", "menu item ("+ item + ") role" );
equal( $( "a", this ).attr( "role" ), undefined, "menu item ("+ item + ") role" );
ok( $( "a", this ).hasClass( "ui-corner-all" ), "a element class for menu item ("+ item + ")" );
equal( $( "a", this ).attr( "tabindex" ), "-1", "a element tabindex for menu item ("+ item + ")" );
2012-05-18 14:04:54 +00:00
});
});
2012-06-18 17:26:46 +00:00
})( jQuery );