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

129 lines
3.7 KiB
JavaScript
Raw Normal View History

define( [
2016-04-06 13:02:55 +00:00
"qunit",
"jquery",
"lib/helper",
2015-04-07 14:55:52 +00:00
"./helper",
"ui/widgets/menu"
], function( QUnit, $, helper, testHelper ) {
var log = testHelper.log,
logOutput = testHelper.logOutput,
click = testHelper.click;
2016-04-06 13:02:55 +00:00
QUnit.module( "menu: options", {
beforeEach: function() {
testHelper.clearLog();
},
afterEach: helper.moduleAfterEach
2015-08-24 12:59:13 +00:00
} );
2016-04-06 13:02:55 +00:00
QUnit.test( "{ disabled: true }", function( assert ) {
assert.expect( 2 );
2015-08-24 12:59:13 +00:00
var element = $( "#menu1" ).menu( {
disabled: true,
select: function() {
log();
}
2015-08-24 12:59:13 +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" );
2016-04-06 13:02:55 +00:00
assert.equal( logOutput(), "click,afterclick", "Click order not valid." );
2015-08-24 12:59:13 +00:00
} );
2016-04-06 13:02:55 +00:00
QUnit.test( "{ disabled: false }", function( assert ) {
assert.expect( 2 );
2015-08-24 12:59:13 +00:00
var element = $( "#menu1" ).menu( {
disabled: false,
select: function() {
log();
}
2015-08-24 12:59:13 +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" );
2016-04-06 13:02:55 +00:00
assert.equal( logOutput(), "click,1,afterclick", "Click order not valid." );
2015-08-24 12:59:13 +00:00
} );
2016-04-06 13:02:55 +00:00
QUnit.test( "{ icons: default }", function( assert ) {
assert.expect( 8 );
var element = $( "#menu2" ).menu();
element.find( ".ui-menu-icon" ).each( function() {
assert.hasClasses( this, "ui-menu-icon ui-icon ui-icon-caret-1-e" );
2015-08-24 12:59:13 +00:00
} );
element.menu( "option", "icons.submenu", "ui-icon-triangle-1-e" );
element.find( ".ui-menu-icon" ).each( function() {
assert.hasClasses( this, "ui-menu-icon ui-icon ui-icon-triangle-1-e" );
2015-08-24 12:59:13 +00:00
} );
} );
2016-04-06 13:02:55 +00:00
QUnit.test( "{ icons: { submenu: 'custom' } }", function( assert ) {
assert.expect( 4 );
2015-08-24 12:59:13 +00:00
var element = $( "#menu2" ).menu( {
icons: {
submenu: "custom-class"
}
2015-08-24 12:59:13 +00:00
} );
element.find( ".ui-menu-icon" ).each( function() {
assert.hasClasses( this, "ui-menu-icon ui-icon custom-class" );
2015-08-24 12:59:13 +00:00
} );
} );
// TODO: test menus option
// TODO: test position option
2016-04-06 13:02:55 +00:00
QUnit.test( "{ role: 'menu' } ", function( assert ) {
2012-06-27 13:49:56 +00:00
var element = $( "#menu1" ).menu(),
items = element.find( "li" );
2016-04-06 13:02:55 +00:00
assert.expect( 2 + 3 * items.length );
assert.equal( element.attr( "role" ), "menu" );
assert.ok( items.length > 0, "number of menu items" );
2015-08-24 12:59:13 +00:00
items.each( function( item ) {
assert.hasClasses( $( this ), "ui-menu-item" );
2016-04-06 13:02:55 +00:00
assert.equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "role" ),
2015-08-24 12:59:13 +00:00
"menuitem", "menu item (" + item + ") role" );
2016-04-06 13:02:55 +00:00
assert.equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "tabindex" ), "-1",
2015-08-24 12:59:13 +00:00
"tabindex for menu item (" + item + ")" );
} );
} );
2012-05-18 14:04:54 +00:00
2016-04-06 13:02:55 +00:00
QUnit.test( "{ role: 'listbox' } ", function( assert ) {
2015-08-24 12:59:13 +00:00
var element = $( "#menu1" ).menu( {
2012-06-18 17:26:46 +00:00
role: "listbox"
2015-08-24 12:59:13 +00:00
} ),
2012-06-27 13:49:56 +00:00
items = element.find( "li" );
2016-04-06 13:02:55 +00:00
assert.expect( 2 + 3 * items.length );
assert.equal( element.attr( "role" ), "listbox" );
assert.ok( items.length > 0, "number of menu items" );
2015-08-24 12:59:13 +00:00
items.each( function( item ) {
assert.hasClasses( $( this ), "ui-menu-item" );
2016-04-06 13:02:55 +00:00
assert.equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "role" ), "option",
2015-08-24 12:59:13 +00:00
"menu item (" + item + ") role" );
2016-04-06 13:02:55 +00:00
assert.equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "tabindex" ), "-1",
2015-08-24 12:59:13 +00:00
"tabindex for menu item (" + item + ")" );
} );
} );
2016-04-06 13:02:55 +00:00
QUnit.test( "{ role: null }", function( assert ) {
2015-08-24 12:59:13 +00:00
var element = $( "#menu1" ).menu( {
role: null
2015-08-24 12:59:13 +00:00
} ),
items = element.find( "li" );
2016-04-06 13:02:55 +00:00
assert.expect( 2 + 3 * items.length );
assert.equal( element.attr( "role" ), null );
assert.ok( items.length > 0, "number of menu items" );
2015-08-24 12:59:13 +00:00
items.each( function( item ) {
assert.hasClasses( $( this ), "ui-menu-item" );
2016-04-06 13:02:55 +00:00
assert.equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "role" ), null,
2015-08-24 12:59:13 +00:00
"menu item (" + item + ") role" );
2016-04-06 13:02:55 +00:00
assert.equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "tabindex" ), "-1",
2015-08-24 12:59:13 +00:00
"tabindex for menu item (" + item + ")" );
} );
} );
2012-05-18 14:04:54 +00:00
} );