aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/menu/options.js
blob: edbfec44789b2c0e9611c421a117aeee0eafd1a3 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
define( [
	"qunit",
	"jquery",
	"lib/helper",
	"./helper",
	"ui/widgets/menu"
], function( QUnit, $, helper, testHelper ) {
"use strict";

var log = testHelper.log,
	logOutput = testHelper.logOutput,
	click = testHelper.click;

QUnit.module( "menu: options", {
	beforeEach: function() {
		testHelper.clearLog();
	},
	afterEach: helper.moduleAfterEach
} );

QUnit.test( "{ disabled: true }", function( assert ) {
	assert.expect( 2 );
	var element = $( "#menu1" ).menu( {
		disabled: true,
		select: function() {
			log();
		}
	} );
	assert.hasClasses( element, "ui-state-disabled" );
	log( "click", true );
	click( element, "1" );
	log( "afterclick" );
	assert.equal( logOutput(), "click,afterclick", "Click order not valid." );
} );

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

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" );
	} );

	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" );
	} );
} );

QUnit.test( "{ icons: { submenu: 'custom' } }", function( assert ) {
	assert.expect( 4 );
	var element = $( "#menu2" ).menu( {
		icons: {
			submenu: "custom-class"
		}
	} );
	element.find( ".ui-menu-icon" ).each( function() {
		assert.hasClasses( this, "ui-menu-icon ui-icon custom-class" );
	} );
} );

// TODO: test menus option

// TODO: test position option

QUnit.test( "{ role: 'menu' } ", function( assert ) {
	var element = $( "#menu1" ).menu(),
		items = element.find( "li" );
	assert.expect( 2 + 3 * items.length );
	assert.equal( element.attr( "role" ), "menu" );
	assert.ok( items.length > 0, "number of menu items" );
	items.each( function( item ) {
		assert.hasClasses( $( this ), "ui-menu-item" );
		assert.equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "role" ),
			"menuitem", "menu item (" + item + ") role" );
		assert.equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "tabindex" ), "-1",
			"tabindex for menu item (" + item + ")" );
	} );
} );

QUnit.test( "{ role: 'listbox' } ", function( assert ) {
	var element = $( "#menu1" ).menu( {
			role: "listbox"
		} ),
		items = element.find( "li" );
	assert.expect( 2 + 3 * items.length );
	assert.equal( element.attr( "role" ), "listbox" );
	assert.ok( items.length > 0, "number of menu items" );
	items.each( function( item ) {
		assert.hasClasses( $( this ), "ui-menu-item" );
		assert.equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "role" ), "option",
			"menu item (" + item + ") role" );
		assert.equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "tabindex" ), "-1",
			"tabindex for menu item (" + item + ")" );
	} );
} );

QUnit.test( "{ role: null }", function( assert ) {
	var element = $( "#menu1" ).menu( {
			role: null
		} ),
		items = element.find( "li" );
	assert.expect( 2 + 3 * items.length );
	assert.equal( element.attr( "role" ), null );
	assert.ok( items.length > 0, "number of menu items" );
	items.each( function( item ) {
		assert.hasClasses( $( this ), "ui-menu-item" );
		assert.equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "role" ), null,
			"menu item (" + item + ") role" );
		assert.equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "tabindex" ), "-1",
			"tabindex for menu item (" + item + ")" );
	} );
} );

} );