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

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

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

	this.element.selectmenu({
		change: function (event, ui) {
			ok(event, "change event fired on change");
			equals(event.type, "selectmenuchange", "event type set to selectmenuchange");
			ok(ui, "ui object is passed as second argument to event handler");
			equals(ui.item.element[0].nodeName, "OPTION", "ui.item.element[0] points to original option element");
			equals(ui.item.value, value, "ui.item.value property updated correctly");                
		}
	});

	var widget = this.element.selectmenu("widget"),
		menu = widget.filter(".ui-selectmenu-menu"),
		button = widget.filter(".ui-selectmenu-button"),
		value = this.element.find("option").first().text();

	button.find("a").simulate( "click" );
	menu.find("a").first().simulate( "mouseover" ).trigger( "click" );
});


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

	this.element.selectmenu({
		close: function (event, ui) {
			ok(event, "close event fired on close");
			equals(event.type, "selectmenuclose", "event type set to selectmenuclose");
			ok(ui, "ui object is passed as second argument to event handler");
		}
	});

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


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

	var counter = 0;

	this.element.selectmenu({
		focus: function (event, ui) {
			counter++;
			if (counter === 1) {
				ok(event, "focus event fired on mouseover");
				equals(event.type, "selectmenufocus", "event type set to selectmenufocus");
				ok(ui, "ui object is passed as second argument to event handler");
				equals(ui.item.element[0].nodeName, "OPTION", "ui points to original option element");
			}
		}
	});

	var widget = this.element.selectmenu("widget"),
		button = widget.filter(".ui-selectmenu-button"),
		menu = widget.filter(".ui-selectmenu-menu");

	button.find("a").simulate( "click" );
	menu.find(".ui-menu-item").simulate("mouseover");
});


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

	this.element.selectmenu({
		open: function (event, ui) {
			ok(event, "open event fired on open");
			equals(event.type, "selectmenuopen", "event type set to selectmenuopen");
			ok(ui, "ui object is passed as second argument to event handler");
		}
	});

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


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

	this.element.selectmenu({
		select: function (event, ui) {
			ok(event, "select event fired on item select");
			equals(event.type, "selectmenuselect", "event type set to selectmenuselect");
			ok(ui, "ui object is passed as second argument to event handler");
			equals(ui.item.element[0].nodeName, "OPTION", "ui points to original option element");
		}
	});

	var widget = this.element.selectmenu("widget"),
		button = widget.filter(".ui-selectmenu-button"),
		menu = widget.filter(".ui-selectmenu-menu");

	button.find("a").simulate( "click" );
	menu.find("a").first().simulate( "mouseover" ).trigger("click");
});

})(jQuery);