aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/selectmenu/selectmenu_core.js
blob: dea3f5d8a491764aa74e48c81f5c916ee122ab97 (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
(function( $ ) {

module( "selectmenu: core" );

test("accessibility", function () {
	var element = $('#speed').selectmenu();
	var widget = element.selectmenu("widget");
	var button = widget.filter(".ui-selectmenu-button");
	var menu = widget.filter(".ui-selectmenu-menu");
	var link = button.children("a");
	var ul = menu.children("ul")
	var links = ul.find("li.ui-menu-item a");
	expect(12 + links.length * 2);
				
	equals( button.attr("aria-disabled"), "false", "button aria-disabled" );
	equals( link.attr("aria-disabled"), "false", "button link aria-disabled" );
	equals( link.attr("aria-haspopup"), "true", "button link aria-haspopup" );
	equals( link.attr("role"), "button", "button link role" );
	equals( link.attr("aria-owns"), ul.attr("id"), "button link aria-owns" );
	equals( link.attr("tabindex"), 0, "button link tabindex" );		
	
	equals( ul.attr("aria-hidden"), "true", "menu aria-hidden" );
	equals( ul.attr("aria-disabled"), "false", "menu aria-disabled" );
	equals( ul.attr("aria-labelledby"), link.attr("id"), "menu aria-labelledby" );
	equals( ul.attr("role"), "menubox", "menu role" );
	equals( ul.attr("tabindex"), 0, "menu tabindex" );
	equals( ul.attr("aria-activedescendant"), links.eq(element[0].selectedIndex).attr("id"), "menu aria-activedescendant" );
	$.each( links, function(index){
		equals( $(this).attr("role"), "option", "menu link #" + index +" role" );
		equals( $(this).attr("tabindex"), -1, "menu link #" + index +" tabindex" );
	});
});


$.each([
	{
		type: "default",
		selector: "#speed"
	},
	{
		type: "optgroups",
		selector: "#files"
	}
], function( i, settings ) {
	test("state synchronization - " + settings.type, function () {
		expect(6);
		var element = $(settings.selector).selectmenu();
		var widget = element.selectmenu("widget");
		var button = widget.filter(".ui-selectmenu-button");
		var menu = widget.filter(".ui-selectmenu-menu");
		
		equals( element[0].value, element.selectmenu("option", "value"), "inital value" );	
		equals( element.find("option:selected").text(), button.text(), "inital button text" );		
		
		button.find("a").simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
		equals( element[0].value, element.selectmenu("option", "value"), "after keydown value" );	
		equals( element.find("option:selected").text(), button.text(), "after keydown button text" );
		
		button.find("a").simulate( "click" );
		menu.find("a").last().simulate( "click" );
		equals( element[0].value, element.selectmenu("option", "value"), "after click value" );	
		equals( element.find("option:selected").text(), button.text(), "after click button text" );		
	});
});

})( jQuery );