aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/dialog/dialog_events.js
blob: c60e47f22281074cec746532d23d52ff3da8f4ce (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*
 * dialog_events.js
 */
(function($) {

module("dialog: events");

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

	el = $("<div></div>");
	el.dialog({
		open: function(ev, ui) {
			ok(true, 'autoOpen: true fires open callback');
			equals(this, el[0], "context of callback");
			equals(ev.type, 'dialogopen', 'event type in callback');
			same(ui, {}, 'ui hash in callback');
		}
	});
	el.remove();

	el = $("<div></div>");
	el.dialog({
		autoOpen: false,
		open: function(ev, ui) {
			ok(true, '.dialog("open") fires open callback');
			equals(this, el[0], "context of callback");
			equals(ev.type, 'dialogopen', 'event type in callback');
			same(ui, {}, 'ui hash in callback');
		}
	}).bind('dialogopen', function(ev, ui) {
		ok(true, 'dialog("open") fires open event');
		equals(this, el[0], 'context of event');
		same(ui, {}, 'ui hash in event');
	});
	el.dialog("open");
	el.remove();
});

test("dragStart", function() {
	expect(7);

	el = $('<div></div>').dialog({
		dragStart: function(ev, ui) {
			ok(true, 'dragging fires dragStart callback');
			equals(this, el[0], "context of callback");
			equals(ev.type, 'dialogdragstart', 'event type in callback');
			same(ui, {}, 'ui hash in callback');
		}
	}).bind('dialogdragstart', function(ev, ui) {
		ok(true, 'dragging fires dialogdragstart event');
		equals(this, el[0], 'context of event');
		same(ui, {}, 'ui hash in event');
	});
	var handle = $(".ui-dialog-titlebar", dlg());
	drag(handle, 50, 50);
	el.remove();
});

test("drag", function() {
	expect(7);
	var hasDragged = false;
	
	el = $('<div></div>').dialog({
		drag: function(ev, ui) {
			if (!hasDragged) {
				ok(true, 'dragging fires drag callback');
				equals(this, el[0], "context of callback");
				equals(ev.type, 'dialogdrag', 'event type in callback');
				same(ui, {}, 'ui hash in callback');
				
				hasDragged = true;
			}
		}
	}).one('dialogdrag', function(ev, ui) {
		ok(true, 'dragging fires dialogdrag event');
		equals(this, el[0], 'context of event');
		same(ui, {}, 'ui hash in event');
	});
	var handle = $(".ui-dialog-titlebar", dlg());
	drag(handle, 50, 50);
	el.remove();
});

test("dragStop", function() {
	expect(7);

	el = $('<div></div>').dialog({
		dragStop: function(ev, ui) {
			ok(true, 'dragging fires dragStop callback');
			equals(this, el[0], "context of callback");
			equals(ev.type, 'dialogdragstop', 'event type in callback');
			same(ui, {}, 'ui hash in callback');
		}
	}).bind('dialogdragstop', function(ev, ui) {
		ok(true, 'dragging fires dialogdragstop event');
		equals(this, el[0], 'context of event');
		same(ui, {}, 'ui hash in event');
	});
	var handle = $(".ui-dialog-titlebar", dlg());
	drag(handle, 50, 50);
	el.remove();
});

test("resizeStart", function() {
	expect(7);

	el = $('<div></div>').dialog({
		resizeStart: function(ev, ui) {
			ok(true, 'resizing fires resizeStart callback');
			equals(this, el[0], "context of callback");
			equals(ev.type, 'dialogresizestart', 'event type in callback');
			same(ui, {}, 'ui hash in callback');
		}
	}).bind('dialogresizestart', function(ev, ui) {
		ok(true, 'resizing fires dialogresizestart event');
		equals(this, el[0], 'context of event');
		same(ui, {}, 'ui hash in event');
	});
	var handle = $(".ui-resizable-se", dlg());
	drag(handle, 50, 50);
	el.remove();
});

test("resize", function() {
	expect(7);
	var hasResized = false;

	el = $('<div></div>').dialog({
		resize: function(ev, ui) {
			if (!hasResized) {
				ok(true, 'resizing fires resize callback');
				equals(this, el[0], "context of callback");
				equals(ev.type, 'dialogresize', 'event type in callback');
				same(ui, {}, 'ui hash in callback');
				
				hasResized = true;
			}
		}
	}).one('dialogresize', function(ev, ui) {
		ok(true, 'resizing fires dialogresize event');
		equals(this, el[0], 'context of event');
		same(ui, {}, 'ui hash in event');
	});
	var handle = $(".ui-resizable-se", dlg());
	drag(handle, 50, 50);
	el.remove();
});

test("resizeStop", function() {
	expect(7);

	el = $('<div></div>').dialog({
		resizeStop: function(ev, ui) {
			ok(true, 'resizing fires resizeStop callback');
			equals(this, el[0], "context of callback");
			equals(ev.type, 'dialogresizestop', 'event type in callback');
			same(ui, {}, 'ui hash in callback');
		}
	}).bind('dialogresizestop', function(ev, ui) {
		ok(true, 'resizing fires dialogresizestop event');
		equals(this, el[0], 'context of event');
		same(ui, {}, 'ui hash in event');
	});
	var handle = $(".ui-resizable-se", dlg());
	drag(handle, 50, 50);
	el.remove();
});

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

	el = $('<div></div>').dialog({
		close: function(ev, ui) {
			ok(true, '.dialog("close") fires close callback');
			equals(this, el[0], "context of callback");
			equals(ev.type, 'dialogclose', 'event type in callback');
			same(ui, {}, 'ui hash in callback');
		}
	}).bind('dialogclose', function(ev, ui) {
		ok(true, '.dialog("close") fires dialogclose event');
		equals(this, el[0], 'context of event');
		same(ui, {}, 'ui hash in event');
	});
	el.dialog('close');
	el.remove();
});

test("beforeClose", function() {
	expect(9);

	el = $('<div></div>').dialog({
		beforeClose: function(ev, ui) {
			ok(true, '.dialog("close") fires beforeClose callback');
			equals(this, el[0], "context of callback");
			equals(ev.type, 'dialogbeforeclose', 'event type in callback');
			same(ui, {}, 'ui hash in callback');
			return false;
		}
	});
	el.dialog('close');
	isOpen('beforeClose callback should prevent dialog from closing');
	el.remove();

	el = $('<div></div>').dialog().bind('dialogbeforeclose', function(ev, ui) {
		ok(true, '.dialog("close") triggers dialogbeforeclose event');
		equals(this, el[0], "context of event");
		same(ui, {}, 'ui hash in event');
		return false;
	});
	el.dialog('close');
	isOpen('dialogbeforeclose event should prevent dialog from closing');
	el.remove();
});

})(jQuery);