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

module( "selectmenu: events", {
	setup: function () {
		this.element = $( "#speed" );
	}
});

test( "change", function () {
	expect( 5 );

	var that = this,
		optionIndex = 1;

	this.element.selectmenu({
		change: function ( event, ui ) {
			ok( event, "change event fired on change" );
			equal( event.type, "selectmenuchange", "event type set to selectmenuchange" );
			equal( ui.item.index, optionIndex, "ui.item.index contains correct option index" );
			equal( ui.item.element[ 0 ], options.eq( optionIndex )[ 0 ], "ui.item.element contains original option element" );
			equal( ui.item.value, options.eq( optionIndex ).text(), "ui.item.value property updated correctly" );
		}
	});

	var button = this.element.selectmenu( "widget" ),
		menu = this.element.selectmenu( "menuWidget" ).parent(),
		options = this.element.find( "option" );

	button.simulate( "focus" ).simulate( "click" );
	menu.find( "a" ).eq( optionIndex ).simulate( "mouseover" ).simulate( "click" );
});


test( "close", function () {
	expect( 4 );

	this.element.selectmenu({
		close: function ( event, ui ) {
			ok( event, "close event fired on close" );
			equal( event.type, "selectmenuclose", "event type set to selectmenuclose" );
		}
	});
	
	this.element.selectmenu( "open" ).selectmenu( "close" );
	
	this.element.selectmenu( "open" );
	$( "body" ).simulate( "click" );
});


test( "focus", function () {
	expect( 12 );

	var button, menu, links,
		optionIndex = this.element[ 0 ].selectedIndex + 1,
		options = this.element.find( "option" );

	this.element.selectmenu({
		focus: function ( event, ui ) {
			ok( event, "focus event fired on element #" + optionIndex + " mouseover" );
			equal( event.type, "selectmenufocus", "event type set to selectmenufocus" );
			equal( ui.item.index, optionIndex, "ui.item.index contains correct option index" );
			equal( ui.item.element[ 0 ], options.eq( optionIndex )[ 0 ], "ui.item.element contains original option element" );
		}
	});

	button = this.element.selectmenu( "widget" ),
	menu = this.element.selectmenu( "menuWidget" );

	button
		.simulate( "focus" )
		.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );

	button.simulate( "click" );
	links = menu.find( "li.ui-menu-item a" );
	optionIndex = 0;
	links.eq( optionIndex ).simulate( "mouseover" );
	optionIndex += 1;
	links.eq( optionIndex ).simulate( "mouseover" );

	// this tests for unwanted, additional focus event on close
	this.element.selectmenu( "close" );
});


test( "open", function () {
	expect( 2 );

	this.element.selectmenu({
		open: function ( event, ui ) {
			ok( event, "open event fired on open" );
			equal( event.type, "selectmenuopen", "event type set to selectmenuopen" );
		}
	});

	this.element.selectmenu( "open" );
});


test( "select", function () {
	expect( 4 );

	this.element.selectmenu({
		select: function ( event, ui ) {
			ok( event, "select event fired on item select" );
			equal( event.type, "selectmenuselect", "event type set to selectmenuselect" );
			equal( ui.item.index, optionIndex, "ui.item.index contains correct option index" );
			equal( ui.item.element[ 0 ], options.eq( optionIndex )[ 0 ], "ui.item.element contains original option element" );
		}
	});

	var button = this.element.selectmenu( "widget" ),
		menu = this.element.selectmenu( "menuWidget" ).parent(),
		options = this.element.find( "option" ),
		optionIndex = 1;

	button.simulate( "focus" ).simulate( "click" );
	menu.find( "a" ).eq( optionIndex ).simulate( "mouseover" ).simulate( "click" );
});

})(jQuery);