1 | /*
|
---|
2 | * dialog_options.js
|
---|
3 | */
|
---|
4 | (function($) {
|
---|
5 |
|
---|
6 | module("dialog: options");
|
---|
7 |
|
---|
8 | test("autoOpen", function() {
|
---|
9 | expect(2);
|
---|
10 |
|
---|
11 | el = $('<div></div>').dialog({ autoOpen: false });
|
---|
12 | isNotOpen('.dialog({ autoOpen: false })');
|
---|
13 | el.remove();
|
---|
14 |
|
---|
15 | el = $('<div></div>').dialog({ autoOpen: true });
|
---|
16 | isOpen('.dialog({ autoOpen: true })');
|
---|
17 | el.remove();
|
---|
18 | });
|
---|
19 |
|
---|
20 | test("buttons", function() {
|
---|
21 | expect(17);
|
---|
22 |
|
---|
23 | var buttons = {
|
---|
24 | "Ok": function(ev, ui) {
|
---|
25 | ok(true, "button click fires callback");
|
---|
26 | equals(this, el[0], "context of callback");
|
---|
27 | equals(ev.target, btn[0], "event target");
|
---|
28 | },
|
---|
29 | "Cancel": function(ev, ui) {
|
---|
30 | ok(true, "button click fires callback");
|
---|
31 | equals(this, el[0], "context of callback");
|
---|
32 | equals(ev.target, btn[1], "event target");
|
---|
33 | }
|
---|
34 | };
|
---|
35 |
|
---|
36 | el = $('<div></div>').dialog({ buttons: buttons });
|
---|
37 | var btn = $("button", dlg());
|
---|
38 | equals(btn.length, 2, "number of buttons");
|
---|
39 |
|
---|
40 | var i = 0;
|
---|
41 | $.each(buttons, function(key, val) {
|
---|
42 | equals(btn.eq(i).text(), key, "text of button " + (i+1));
|
---|
43 | i++;
|
---|
44 | });
|
---|
45 |
|
---|
46 | ok(btn.parent().hasClass('ui-dialog-buttonpane'), "buttons in container");
|
---|
47 | btn.trigger("click");
|
---|
48 |
|
---|
49 | var newButtons = {
|
---|
50 | "Close": function(ev, ui) {
|
---|
51 | ok(true, "button click fires callback");
|
---|
52 | equals(this, el[0], "context of callback");
|
---|
53 | equals(ev.target, btn[0], "event target");
|
---|
54 | }
|
---|
55 | };
|
---|
56 |
|
---|
57 | same(el.dialog("option", "buttons"), buttons, '.dialog("option", "buttons") getter');
|
---|
58 | el.dialog("option", "buttons", newButtons);
|
---|
59 | same(el.dialog("option", "buttons"), newButtons, '.dialog("option", "buttons", ...) setter');
|
---|
60 |
|
---|
61 | btn = $("button", dlg());
|
---|
62 | equals(btn.length, 1, "number of buttons after setter");
|
---|
63 | btn.trigger('click');
|
---|
64 |
|
---|
65 | i = 0;
|
---|
66 | $.each(newButtons, function(key, val) {
|
---|
67 | equals(btn.eq(i).text(), key, "text of button " + (i+1));
|
---|
68 | i += 1;
|
---|
69 | });
|
---|
70 |
|
---|
71 | el.remove();
|
---|
72 | });
|
---|
73 |
|
---|
74 | test("closeOnEscape", function() {
|
---|
75 | el = $('<div></div>').dialog({ closeOnEscape: false });
|
---|
76 | ok(true, 'closeOnEscape: false');
|
---|
77 | ok(dlg().is(':visible') && !dlg().is(':hidden'), 'dialog is open before ESC');
|
---|
78 | el.simulate('keydown', { keyCode: $.ui.keyCode.ESCAPE })
|
---|
79 | .simulate('keypress', { keyCode: $.ui.keyCode.ESCAPE })
|
---|
80 | .simulate('keyup', { keyCode: $.ui.keyCode.ESCAPE });
|
---|
81 | ok(dlg().is(':visible') && !dlg().is(':hidden'), 'dialog is open after ESC');
|
---|
82 |
|
---|
83 | el.remove();
|
---|
84 |
|
---|
85 | el = $('<div></div>').dialog({ closeOnEscape: true });
|
---|
86 | ok(true, 'closeOnEscape: true');
|
---|
87 | ok(dlg().is(':visible') && !dlg().is(':hidden'), 'dialog is open before ESC');
|
---|
88 | el.simulate('keydown', { keyCode: $.ui.keyCode.ESCAPE })
|
---|
89 | .simulate('keypress', { keyCode: $.ui.keyCode.ESCAPE })
|
---|
90 | .simulate('keyup', { keyCode: $.ui.keyCode.ESCAPE });
|
---|
91 | ok(dlg().is(':hidden') && !dlg().is(':visible'), 'dialog is closed after ESC');
|
---|
92 | });
|
---|
93 |
|
---|
94 | test("closeText", function() {
|
---|
95 | expect(3);
|
---|
96 |
|
---|
97 | el = $('<div></div>').dialog();
|
---|
98 | equals(dlg().find('.ui-dialog-titlebar-close span').text(), 'close',
|
---|
99 | 'default close text');
|
---|
100 | el.remove();
|
---|
101 |
|
---|
102 | el = $('<div></div>').dialog({ closeText: "foo" });
|
---|
103 | equals(dlg().find('.ui-dialog-titlebar-close span').text(), 'foo',
|
---|
104 | 'closeText on init');
|
---|
105 | el.remove();
|
---|
106 |
|
---|
107 | el = $('<div></div>').dialog().dialog('option', 'closeText', 'bar');
|
---|
108 | equals(dlg().find('.ui-dialog-titlebar-close span').text(), 'bar',
|
---|
109 | 'closeText via option method');
|
---|
110 | el.remove();
|
---|
111 | });
|
---|
112 |
|
---|
113 | test("dialogClass", function() {
|
---|
114 | expect(4);
|
---|
115 |
|
---|
116 | el = $('<div></div>').dialog();
|
---|
117 | equals(dlg().is(".foo"), false, 'dialogClass not specified. foo class added');
|
---|
118 | el.remove();
|
---|
119 |
|
---|
120 | el = $('<div></div>').dialog({ dialogClass: "foo" });
|
---|
121 | equals(dlg().is(".foo"), true, 'dialogClass in init. foo class added');
|
---|
122 | el.remove();
|
---|
123 |
|
---|
124 | el = $('<div></div>').dialog({ dialogClass: "foo bar" });
|
---|
125 | equals(dlg().is(".foo"), true, 'dialogClass in init, two classes. foo class added');
|
---|
126 | equals(dlg().is(".bar"), true, 'dialogClass in init, two classes. bar class added');
|
---|
127 | el.remove();
|
---|
128 | });
|
---|
129 |
|
---|
130 | test("draggable", function() {
|
---|
131 | expect(4);
|
---|
132 |
|
---|
133 | el = $('<div></div>').dialog({ draggable: false });
|
---|
134 | shouldnotmove();
|
---|
135 | el.dialog('option', 'draggable', true);
|
---|
136 | shouldmove();
|
---|
137 | el.remove();
|
---|
138 |
|
---|
139 | el = $('<div></div>').dialog({ draggable: true });
|
---|
140 | shouldmove();
|
---|
141 | el.dialog('option', 'draggable', false);
|
---|
142 | shouldnotmove();
|
---|
143 | el.remove();
|
---|
144 | });
|
---|
145 |
|
---|
146 | test("height", function() {
|
---|
147 | expect(3);
|
---|
148 |
|
---|
149 | el = $('<div></div>').dialog();
|
---|
150 | equals(dlg().height(), dialog_defaults.minHeight, "default height");
|
---|
151 | el.remove();
|
---|
152 |
|
---|
153 | el = $('<div></div>').dialog({ height: 437 });
|
---|
154 | equals(dlg().height(), 437, "explicit height");
|
---|
155 | el.remove();
|
---|
156 |
|
---|
157 | el = $('<div></div>').dialog();
|
---|
158 | el.dialog('option', 'height', 438);
|
---|
159 | equals(dlg().height(), 438, "explicit height set after init");
|
---|
160 | el.remove();
|
---|
161 | });
|
---|
162 |
|
---|
163 | test("maxHeight", function() {
|
---|
164 | expect(3);
|
---|
165 |
|
---|
166 | el = $('<div></div>').dialog({ maxHeight: 400 });
|
---|
167 | drag('.ui-resizable-s', 1000, 1000);
|
---|
168 | equals(heightAfter, 400, "maxHeight");
|
---|
169 | el.remove();
|
---|
170 |
|
---|
171 | el = $('<div></div>').dialog({ maxHeight: 400 });
|
---|
172 | drag('.ui-resizable-n', -1000, -1000);
|
---|
173 | equals(heightAfter, 400, "maxHeight");
|
---|
174 | el.remove();
|
---|
175 |
|
---|
176 | el = $('<div></div>').dialog({ maxHeight: 400 }).dialog('option', 'maxHeight', 600);
|
---|
177 | drag('.ui-resizable-n', -1000, -1000);
|
---|
178 | equals(heightAfter, 600, "maxHeight");
|
---|
179 | el.remove();
|
---|
180 | });
|
---|
181 |
|
---|
182 | test("maxWidth", function() {
|
---|
183 | expect(3);
|
---|
184 |
|
---|
185 | el = $('<div></div>').dialog({ maxWidth: 400 });
|
---|
186 | drag('.ui-resizable-e', 1000, 1000);
|
---|
187 | equals(widthAfter, 400, "maxWidth");
|
---|
188 | el.remove();
|
---|
189 |
|
---|
190 | el = $('<div></div>').dialog({ maxWidth: 400 });
|
---|
191 | drag('.ui-resizable-w', -1000, -1000);
|
---|
192 | equals(widthAfter, 400, "maxWidth");
|
---|
193 | el.remove();
|
---|
194 |
|
---|
195 | el = $('<div></div>').dialog({ maxWidth: 400 }).dialog('option', 'maxWidth', 600);
|
---|
196 | drag('.ui-resizable-w', -1000, -1000);
|
---|
197 | equals(widthAfter, 600, "maxWidth");
|
---|
198 | el.remove();
|
---|
199 | });
|
---|
200 |
|
---|
201 | test("minHeight", function() {
|
---|
202 | expect(3);
|
---|
203 |
|
---|
204 | el = $('<div></div>').dialog({ minHeight: 10 });
|
---|
205 | drag('.ui-resizable-s', -1000, -1000);
|
---|
206 | equals(heightAfter, 10, "minHeight");
|
---|
207 | el.remove();
|
---|
208 |
|
---|
209 | el = $('<div></div>').dialog({ minHeight: 10 });
|
---|
210 | drag('.ui-resizable-n', 1000, 1000);
|
---|
211 | equals(heightAfter, 10, "minHeight");
|
---|
212 | el.remove();
|
---|
213 |
|
---|
214 | el = $('<div></div>').dialog({ minHeight: 10 }).dialog('option', 'minHeight', 30);
|
---|
215 | drag('.ui-resizable-n', 1000, 1000);
|
---|
216 | equals(heightAfter, 30, "minHeight");
|
---|
217 | el.remove();
|
---|
218 | });
|
---|
219 |
|
---|
220 | test("minWidth", function() {
|
---|
221 | expect(3);
|
---|
222 |
|
---|
223 | el = $('<div></div>').dialog({ minWidth: 10 });
|
---|
224 | drag('.ui-resizable-e', -1000, -1000);
|
---|
225 | equals(widthAfter, 10, "minWidth");
|
---|
226 | el.remove();
|
---|
227 |
|
---|
228 | el = $('<div></div>').dialog({ minWidth: 10 });
|
---|
229 | drag('.ui-resizable-w', 1000, 1000);
|
---|
230 | equals(widthAfter, 10, "minWidth");
|
---|
231 | el.remove();
|
---|
232 |
|
---|
233 | el = $('<div></div>').dialog({ minWidth: 30 }).dialog('option', 'minWidth', 30);
|
---|
234 | drag('.ui-resizable-w', 1000, 1000);
|
---|
235 | equals(widthAfter, 30, "minWidth");
|
---|
236 | el.remove();
|
---|
237 | });
|
---|
238 |
|
---|
239 | test("modal", function() {
|
---|
240 | ok(false, 'missing test - untested code is broken code');
|
---|
241 | });
|
---|
242 |
|
---|
243 | test("position, default center on window", function() {
|
---|
244 | var el = $('<div></div>').dialog();
|
---|
245 | var offset = el.parent().offset();
|
---|
246 | // use .position() instead to avoid replicating center-logic?
|
---|
247 | same(offset.left, Math.floor($(window).width() / 2 - el.parent().width() / 2));
|
---|
248 | same(offset.top, Math.floor($(window).height() / 2 - el.parent().height() / 2));
|
---|
249 | el.remove();
|
---|
250 | });
|
---|
251 |
|
---|
252 | test("position, others", function() {
|
---|
253 | ok(false, 'missing test - untested code is broken code');
|
---|
254 | });
|
---|
255 |
|
---|
256 | test("resizable", function() {
|
---|
257 | expect(4);
|
---|
258 |
|
---|
259 | el = $('<div></div>').dialog();
|
---|
260 | shouldresize("[default]");
|
---|
261 | el.dialog('option', 'resizable', false);
|
---|
262 | shouldnotresize('disabled after init');
|
---|
263 | el.remove();
|
---|
264 |
|
---|
265 | el = $('<div></div>').dialog({ resizable: false });
|
---|
266 | shouldnotresize("disabled in init options");
|
---|
267 | el.dialog('option', 'resizable', true);
|
---|
268 | shouldresize('enabled after init');
|
---|
269 | el.remove();
|
---|
270 | });
|
---|
271 |
|
---|
272 | test("stack", function() {
|
---|
273 | ok(false, 'missing test - untested code is broken code');
|
---|
274 | });
|
---|
275 |
|
---|
276 | test("title", function() {
|
---|
277 | expect(5);
|
---|
278 |
|
---|
279 | function titleText() {
|
---|
280 | return dlg().find(".ui-dialog-title").html();
|
---|
281 | }
|
---|
282 |
|
---|
283 | el = $('<div></div>').dialog();
|
---|
284 | equals(titleText(), " ", "[default]");
|
---|
285 | el.remove();
|
---|
286 |
|
---|
287 | el = $('<div title="foo"/>').dialog();
|
---|
288 | equals(titleText(), "foo", "title in element attribute");
|
---|
289 | el.remove();
|
---|
290 |
|
---|
291 | el = $('<div></div>').dialog({ title: 'foo' });
|
---|
292 | equals(titleText(), "foo", "title in init options");
|
---|
293 | el.remove();
|
---|
294 |
|
---|
295 | el = $('<div title="foo"/>').dialog({ title: 'bar' });
|
---|
296 | equals(titleText(), "bar", "title in init options should override title in element attribute");
|
---|
297 | el.remove();
|
---|
298 |
|
---|
299 | el = $('<div></div>').dialog().dialog('option', 'title', 'foo');
|
---|
300 | equals(titleText(), 'foo', 'title after init');
|
---|
301 | el.remove();
|
---|
302 | });
|
---|
303 |
|
---|
304 | test("width", function() {
|
---|
305 | expect(3);
|
---|
306 |
|
---|
307 | el = $('<div></div>').dialog();
|
---|
308 | equals(dlg().width(), dialog_defaults.width, "default width");
|
---|
309 | el.remove();
|
---|
310 |
|
---|
311 | el = $('<div></div>').dialog({width: 437 });
|
---|
312 | equals(dlg().width(), 437, "explicit width");
|
---|
313 | el.dialog('option', 'width', 438);
|
---|
314 | equals(dlg().width(), 438, 'explicit width after init');
|
---|
315 | el.remove();
|
---|
316 | });
|
---|
317 |
|
---|
318 | })(jQuery);
|
---|