aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/menu/menu_options.js
blob: a25b59a2cfa86bac03b1f4afaca01db32214fb54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
(function( $ ) {

var log = TestHelpers.menu.log,
	logOutput = TestHelpers.menu.logOutput,
	click = TestHelpers.menu.click;

module( "menu: options", {
	setup: function() {
		TestHelpers.menu.clearLog();
	}
});

test( "{ disabled: true }", function() {
	expect( 2 );
	var menu = $( "#menu1" ).menu({
		disabled: true,
		select: function(event, ui) {
			log();
		}
	});
	ok( menu.is( ".ui-state-disabled" ), "Missing ui-state-disabled class" );
	log( "click", true );
	click( menu, "1" );
	log( "afterclick" );
	equal( logOutput(), "click,afterclick", "Click order not valid." );
});

test( "{ disabled: false }", function() {
	expect( 2 );
	var menu = $( "#menu1" ).menu({
		disabled: false,
		select: function( event, ui ) {
			log();
		}
	});
	ok( menu.not( ".ui-state-disabled" ), "Has ui-state-disabled class" );
	log( "click", true );
	click( menu, "1" );
	log( "afterclick" );
	equal( logOutput(), "click,1,afterclick", "Click order not valid." );
});

test( "{ role: 'menu' } ", function () {
	var menu = $( "#menu1" ).menu(),
		items = menu.find( "li" );
	expect( 2 + 5 * items.length );
	equal( menu.attr( "role" ), "menu" );
	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" );
		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: 'listbox' } ", function () {
	var menu = $( "#menu1" ).menu({
			role: "listbox"
		}),
		items = menu.find( "li" );
	expect(2 + items.length);
	equal( menu.attr( "role" ), "listbox" );
	ok( items.length > 0, "number of menu items" );
	items.each(function( item ) {
		equal( $( "a", this ).attr( "role" ), "option", "menu item ("+ item + ") role" );
	});
});

})( jQuery );