2015-04-06 17:04:04 +00:00
|
|
|
define( [
|
2016-04-06 13:02:55 +00:00
|
|
|
"qunit",
|
2015-04-06 17:04:04 +00:00
|
|
|
"jquery",
|
2020-05-16 07:16:24 +00:00
|
|
|
"lib/helper",
|
2015-04-07 14:55:52 +00:00
|
|
|
"./helper",
|
2015-07-15 02:03:37 +00:00
|
|
|
"ui/widgets/menu"
|
2020-05-16 07:16:24 +00:00
|
|
|
], function( QUnit, $, helper, testHelper ) {
|
2010-05-06 15:10:52 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
var log = testHelper.log,
|
|
|
|
logOutput = testHelper.logOutput,
|
|
|
|
click = testHelper.click;
|
2012-04-19 16:19:52 +00:00
|
|
|
|
2016-04-06 13:02:55 +00:00
|
|
|
QUnit.module( "menu: options", {
|
|
|
|
beforeEach: function() {
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.clearLog();
|
2020-05-16 07:16:24 +00:00
|
|
|
},
|
|
|
|
afterEach: helper.moduleAfterEach
|
2015-08-24 12:59:13 +00:00
|
|
|
} );
|
2010-05-06 15:10:52 +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( {
|
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-08-24 12:59:13 +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" );
|
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
|
|
|
} );
|
2010-05-06 15:10:52 +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( {
|
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-08-24 12:59:13 +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" );
|
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
|
|
|
} );
|
2010-05-06 15:10:52 +00:00
|
|
|
|
2016-04-06 13:02:55 +00:00
|
|
|
QUnit.test( "{ icons: default }", function( assert ) {
|
|
|
|
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" );
|
2015-08-24 12:59:13 +00:00
|
|
|
} );
|
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" );
|
2015-08-24 12:59:13 +00:00
|
|
|
} );
|
|
|
|
} );
|
2012-07-12 15:23:33 +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( {
|
2012-07-12 15:23:33 +00:00
|
|
|
icons: {
|
|
|
|
submenu: "custom-class"
|
|
|
|
}
|
2015-08-24 12:59:13 +00:00
|
|
|
} );
|
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" );
|
2015-08-24 12:59:13 +00:00
|
|
|
} );
|
|
|
|
} );
|
2012-07-10 17:58:20 +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 ) {
|
2015-01-30 14:58:21 +00:00
|
|
|
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 ) {
|
2015-01-30 14:58:21 +00:00
|
|
|
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 + ")" );
|
|
|
|
} );
|
|
|
|
} );
|
2012-07-10 17:58:20 +00:00
|
|
|
|
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( {
|
2012-07-10 17:58:20 +00:00
|
|
|
role: null
|
2015-08-24 12:59:13 +00:00
|
|
|
} ),
|
2012-07-10 17:58:20 +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 ) {
|
2015-01-30 14:58:21 +00:00
|
|
|
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
|
|
|
|
2015-04-06 17:04:04 +00:00
|
|
|
} );
|