6
// Resizable Test Helper Functions
9
var drag = function(el, dx, dy, complete) {
11
// speed = sync -> Drag syncrhonously.
12
// speed = fast|slow -> Drag asyncrhonously - animated.
14
//this mouseover is to work around a limitation in resizable
15
//TODO: fix resizable so handle doesn't require mouseover in order to be used
16
$(el).simulate("mouseover");
18
return $(el).simulate("drag", {
19
dx: dx||0, dy: dy||0, speed: 'sync', complete: complete
36
proportionallyResize: null
42
test("init", function() {
45
$("#resizable1").resizable().remove();
46
ok(true, '.resizable() called on element');
48
$([]).resizable().remove();
49
ok(true, '.resizable() called on empty collection');
51
$('<div/>').resizable().remove();
52
ok(true, '.resizable() called on disconnected DOMElement');
54
$('<div/>').resizable().resizable("foo").remove();
55
ok(true, 'arbitrary method called after init');
57
el = $('<div/>').resizable()
58
var foo = el.data("foo.resizable");
60
ok(true, 'arbitrary option getter after init');
62
$('<div/>').resizable().data("foo.resizable", "bar").remove();
63
ok(true, 'arbitrary option setter after init');
66
test("destroy", function() {
69
$("#dialog1").resizable().resizable("destroy").remove();
70
ok(true, '.resizable("destroy") called on element');
72
$([]).resizable().resizable("destroy").remove();
73
ok(true, '.resizable("destroy") called on empty collection');
75
$('<div/>').resizable().resizable("destroy").remove();
76
ok(true, '.resizable("destroy") called on disconnected DOMElement');
78
$('<div/>').resizable().resizable("destroy").resizable("foo").remove();
79
ok(true, 'arbitrary method called after destroy');
81
el = $('<div/>').resizable();
82
var foo = el.resizable("destroy").data("foo.resizable");
84
ok(true, 'arbitrary option getter after destroy');
86
$('<div/>').resizable().resizable("destroy").data("foo.resizable", "bar").remove();
87
ok(true, 'arbitrary option setter after destroy');
90
test("element types", function() {
91
var typeNames = ('p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form'
92
+ ',table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr'
93
+ ',acronym,code,samp,kbd,var,img,object,hr'
94
+ ',input,button,label,select,iframe').split(',');
96
$.each(typeNames, function(i) {
97
var typeName = typeNames[i];
98
el = $(document.createElement(typeName)).appendTo('body');
99
(typeName == 'table' && el.append("<tr><td>content</td></tr>"));
101
ok(true, '$("<' + typeName + '/>").resizable()');
102
el.resizable("destroy");
107
test("defaults", function() {
108
el = $('<div/>').resizable();
109
$.each(defaults, function(key, val) {
110
var actual = el.data(key + ".resizable"), expected = val,
111
method = (expected && expected.constructor == Object) ?
113
method(actual, expected, key);
118
test("n", function() {
121
var handle = '.ui-resizable-n', target = $('#resizable1').resizable({ handles: 'all' });
123
drag(handle, 0, -50);
124
equals( target.height(), 150, "compare height" );
127
equals( target.height(), 100, "compare height" );
130
test("s", function() {
133
var handle = '.ui-resizable-s', target = $('#resizable1').resizable({ handles: 'all' });
136
equals( target.height(), 150, "compare height" );
138
drag(handle, 0, -50);
139
equals( target.height(), 100, "compare height" );
142
test("e", function() {
145
var handle = '.ui-resizable-e', target = $('#resizable1').resizable({ handles: 'all' });
148
equals( target.width(), 150, "compare width");
151
equals( target.width(), 100, "compare width" );
154
test("w", function() {
157
var handle = '.ui-resizable-w', target = $('#resizable1').resizable({ handles: 'all' });
160
equals( target.width(), 150, "compare width" );
163
equals( target.width(), 100, "compare width" );
166
test("ne", function() {
169
var handle = '.ui-resizable-ne', target = $('#resizable1').css({ overflow: 'hidden' }).resizable({ handles: 'all' });
171
drag(handle, -50, -50);
172
equals( target.width(), 50, "compare width" );
173
equals( target.height(), 150, "compare height" );
175
drag(handle, 50, 50);
176
equals( target.width(), 100, "compare width" );
177
equals( target.height(), 100, "compare height" );
180
test("se", function() {
183
var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ handles: 'all' });
185
drag(handle, 50, 50);
186
equals( target.width(), 150, "compare width" );
187
equals( target.height(), 150, "compare height" );
189
drag(handle, -50, -50);
190
equals( target.width(), 100, "compare width" );
191
equals( target.height(), 100, "compare height" );
194
test("sw", function() {
197
var handle = '.ui-resizable-sw', target = $('#resizable1').resizable({ handles: 'all' });
199
drag(handle, -50, -50);
200
equals( target.width(), 150, "compare width" );
201
equals( target.height(), 50, "compare height" );
203
drag(handle, 50, 50);
204
equals( target.width(), 100, "compare width" );
205
equals( target.height(), 100, "compare height" );
208
test("nw", function() {
211
var handle = '.ui-resizable-nw', target = $('#resizable1').resizable({ handles: 'all' });
213
drag(handle, -50, -50);
214
equals( target.width(), 150, "compare width" );
215
equals( target.height(), 150, "compare height" );
217
drag(handle, 50, 50);
218
equals( target.width(), 100, "compare width" );
219
equals( target.height(), 100, "compare height" );
222
module("resizable: Options");
224
test("aspectRatio: 'preserve' (e)", function() {
227
var handle = '.ui-resizable-e', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 });
230
equals( target.width(), 130, "compare maxWidth");
231
equals( target.height(), 130, "compare maxHeight");
234
equals( target.width(), 70, "compare minWidth");
235
equals( target.height(), 70, "compare minHeight");
238
test("aspectRatio: 'preserve' (w)", function() {
241
var handle = '.ui-resizable-w', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 });
244
equals( target.width(), 130, "compare maxWidth");
245
equals( target.height(), 130, "compare maxHeight");
248
equals( target.width(), 70, "compare minWidth");
249
equals( target.height(), 70, "compare minHeight");
252
test("aspectRatio: 'preserve' (n)", function() {
255
var handle = '.ui-resizable-n', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 });
257
drag(handle, 0, -80);
258
equals( target.width(), 130, "compare maxWidth");
259
equals( target.height(), 130, "compare maxHeight");
262
equals( target.width(), 70, "compare minWidth");
263
equals( target.height(), 70, "compare minHeight");
266
test("aspectRatio: 'preserve' (s)", function() {
269
var handle = '.ui-resizable-s', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 });
272
equals( target.width(), 130, "compare maxWidth");
273
equals( target.height(), 130, "compare maxHeight");
275
drag(handle, 0, -80);
276
equals( target.width(), 70, "compare minWidth");
277
equals( target.height(), 70, "compare minHeight");
280
test("aspectRatio: 'preserve' (se)", function() {
283
var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 });
285
drag(handle, 80, 80);
286
equals( target.width(), 130, "compare maxWidth");
287
equals( target.height(), 130, "compare maxHeight");
289
drag(handle, -80, -80);
290
equals( target.width(), 70, "compare minWidth");
291
equals( target.height(), 70, "compare minHeight");
294
test("aspectRatio: 'preserve' (sw)", function() {
297
var handle = '.ui-resizable-sw', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 });
299
drag(handle, -80, 80);
300
equals( target.width(), 130, "compare maxWidth");
301
equals( target.height(), 130, "compare maxHeight");
303
drag(handle, 80, -80);
304
equals( target.width(), 70, "compare minWidth");
305
equals( target.height(), 70, "compare minHeight");
308
test("aspectRatio: 'preserve' (ne)", function() {
311
var handle = '.ui-resizable-ne', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 });
313
drag(handle, 80, -80);
314
equals( target.width(), 130, "compare maxWidth");
315
equals( target.height(), 130, "compare maxHeight");
317
drag(handle, -80, 80);
318
equals( target.width(), 70, "compare minWidth");
319
equals( target.height(), 70, "compare minHeight");
322
test("grid", function() {
325
var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ handles: 'all', grid: [0, 20] });
328
equals( target.width(), 103, "compare width");
329
equals( target.height(), 100, "compare height");
331
drag(handle, 15, 11);
332
equals( target.width(), 118, "compare width");
333
equals( target.height(), 120, "compare height");
336
test("grid (wrapped)", function() {
339
var handle = '.ui-resizable-se', target = $('#resizable2').resizable({ handles: 'all', grid: [0, 20] });
342
equals( target.width(), 103, "compare width");
343
equals( target.height(), 100, "compare height");
345
drag(handle, 15, 11);
346
equals( target.width(), 118, "compare width");
347
equals( target.height(), 120, "compare height");
350
test("ui-resizable-se { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }", function() {
353
var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 });
355
drag(handle, -50, -50);
356
equals( target.width(), 60, "compare minWidth" );
357
equals( target.height(), 60, "compare minHeight" );
359
drag(handle, 70, 70);
360
equals( target.width(), 100, "compare maxWidth" );
361
equals( target.height(), 100, "compare maxHeight" );
364
test("ui-resizable-sw { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }", function() {
367
var handle = '.ui-resizable-sw', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 });
369
drag(handle, 50, -50);
370
equals( target.width(), 60, "compare minWidth" );
371
equals( target.height(), 60, "compare minHeight" );
373
drag(handle, -70, 70);
374
equals( target.width(), 100, "compare maxWidth" );
375
equals( target.height(), 100, "compare maxHeight" );
378
test("ui-resizable-ne { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }", function() {
381
var handle = '.ui-resizable-ne', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 });
383
drag(handle, -50, 50);
384
equals( target.width(), 60, "compare minWidth" );
385
equals( target.height(), 60, "compare minHeight" );
387
drag(handle, 70, -70);
388
equals( target.width(), 100, "compare maxWidth" );
389
equals( target.height(), 100, "compare maxHeight" );
392
test("ui-resizable-nw { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }", function() {
395
var handle = '.ui-resizable-nw', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 });
397
drag(handle, 70, 70);
398
equals( target.width(), 60, "compare minWidth" );
399
equals( target.height(), 60, "compare minHeight" );
401
drag(handle, -70, -70);
402
equals( target.width(), 100, "compare maxWidth" );
403
equals( target.height(), 100, "compare maxHeight" );