Debian Codegraph @

tests/unit/sortable/options.js

raw symbols SCIP
1 define( [
2 "qunit",
3 "jquery",
4 "lib/helper",
5 "ui/widgets/sortable"
6 ], function( QUnit, $, helper ) {
7 "use strict";
8
9 QUnit.module( "sortable: options", { afterEach: helper.moduleAfterEach } );
10
11 /*
12 Test("{ appendTo: 'parent' }, default", function() {
13 ok(false, "missing test - untested code is broken code.");
14 });
15
16 test("{ appendTo: Selector }", function() {
17 ok(false, "missing test - untested code is broken code.");
18 });
19 */
20
21 QUnit.test( "{ axis: false }, default", function( assert ) {
22 assert.expect( 2 );
23
24 var offsetAfter,
25 element = $( "#sortable" ).sortable( {
26 axis: false,
27 change: function() {
28 offsetAfter = item.offset();
29 assert.notEqual( offsetAfter.left, offsetBefore.left, "x axis not constrained when axis: false" );
30 assert.notEqual( offsetAfter.top, offsetBefore.top, "y axis not constrained when axis: false" );
31 }
32 } ),
33 item = element.find( "li" ).eq( 0 ),
34 offsetBefore = item.offset();
35
36 item.simulate( "drag", {
37 dx: 50,
38 dy: 25,
39 moves: 1
40 } );
41 } );
42
43 QUnit.test( "{ axis: 'x' }", function( assert ) {
44 assert.expect( 2 );
45
46 var offsetAfter,
47 element = $( "#sortable" ).sortable( {
48 axis: "x",
49 change: function() {
50 offsetAfter = item.offset();
51 assert.notEqual( offsetAfter.left, offsetBefore.left, "x axis not constrained when axis: x" );
52 assert.equal( offsetAfter.top, offsetBefore.top, "y axis constrained when axis: x" );
53 }
54 } ),
55 item = element.find( "li" ).eq( 0 ),
56 offsetBefore = item.offset();
57
58 item.simulate( "drag", {
59 dx: 50,
60 dy: 25,
61 moves: 1
62 } );
63 } );
64
65 QUnit.test( "{ axis: 'y' }", function( assert ) {
66 assert.expect( 2 );
67
68 var offsetAfter,
69 element = $( "#sortable" ).sortable( {
70 axis: "y",
71 change: function() {
72 offsetAfter = item.offset();
73 assert.equal( offsetAfter.left, offsetBefore.left, "x axis constrained when axis: y" );
74 assert.notEqual( offsetAfter.top, offsetBefore.top, "y axis not constrained when axis: y" );
75 }
76 } ),
77 item = element.find( "li" ).eq( 0 ),
78 offsetBefore = item.offset();
79
80 item.simulate( "drag", {
81 dx: 50,
82 dy: 25,
83 moves: 1
84 } );
85 } );
86
87 QUnit.test( "#7415: Incorrect revert animation with axis: 'y'", function( assert ) {
88 var ready = assert.async();
89 assert.expect( 2 );
90 var expectedLeft,
91 element = $( "#sortable" ).sortable( {
92 axis: "y",
93 revert: true,
94 sort: function() {
95 expectedLeft = item.css( "left" );
96 }
97 } ),
98 item = element.find( "li" ).eq( 0 );
99
100 item.simulate( "drag", {
101 dy: 300,
102 dx: 50
103 } );
104
105 setTimeout( function() {
106 var top = parseFloat( item.css( "top" ) );
107 assert.equal( item.css( "left" ), expectedLeft, "left not animated" );
108 assert.ok( top > 0 && top < 300, "top is animated" );
109
110 // Cleanup
111 item.stop( true );
112
113 ready();
114 }, 100 );
115 } );
116
117 /*
118 Test("{ cancel: 'input,textarea,button,select,option' }, default", function() {
119 ok(false, "missing test - untested code is broken code.");
120 });
121
122 test("{ cancel: Selector }", function() {
123 ok(false, "missing test - untested code is broken code.");
124 });
125 */
126
127 QUnit.test( "#8792: issues with floated items in connected lists", function( assert ) {
128 assert.expect( 2 );
129
130 var element,
131 changeCount = 0;
132
133 $( "#qunit-fixture" )
134 .html( "<ul class='c'><li>a</li><li>a</li></ul><ul class='c'><li>a</li><li>a</li></ul>" )
135 .find( "ul" ).css( { "float": "left", width: "100px" } ).end()
136 .find( "li" ).css( { "float": "left", width: "50px", height: "50px" } );
137
138 $( "#qunit-fixture .c" ).sortable( {
139 connectWith: "#qunit-fixture .c",
140 change: function() {
141 changeCount++;
142 }
143 } );
144
145 element = $( "#qunit-fixture li" ).eq( 0 );
146
147 // Move the first li to the right of the second li in the first ul
148 element.simulate( "drag", {
149 dx: 55,
150 moves: 15
151 } );
152
153 assert.equal( changeCount, 1, "change fired only once (no jitters) when dragging a floated sortable in it's own container" );
154
155 // Move the first li ( which is now in the second spot )
156 // through the first spot in the second ul to the second spot in the second ul
157 element.simulate( "drag", {
158 dx: 100,
159 moves: 15
160 } );
161
162 assert.equal( changeCount, 3, "change fired once for each expected change when dragging a floated sortable to a connected container" );
163 } );
164
165 QUnit.test( "#8301: single axis with connected list", function( assert ) {
166 assert.expect( 1 );
167
168 var element = $( "#sortable" ).sortable( {
169 axis: "y",
170 tolerance: "pointer",
171 connectWith: ".connected"
172 } );
173
174 $( "<ul class='connected'><li>Item 7</li><li>Item 8</li></ul>" )
175 .sortable( {
176 axis: "y",
177 tolerance: "pointer",
178 connectWith: "#sortable",
179 receive: function() {
180 assert.ok( true, "connected list received item" );
181 }
182 } )
183 .insertAfter( element );
184
185 element.find( "li" ).eq( 0 ).simulate( "drag", {
186 handle: "corner",
187 dy: 120,
188 moves: 1
189 } );
190 } );
191
192 /*
193 Test("{ connectWith: false }, default", function() {
194 ok(false, "missing test - untested code is broken code.");
195 });
196
197 test("{ connectWith: Selector }", function() {
198 ok(false, "missing test - untested code is broken code.");
199 });
200
201 test("{ containment: false }, default", function() {
202 ok(false, "missing test - untested code is broken code.");
203 });
204
205 test("{ containment: Element }", function() {
206 ok(false, "missing test - untested code is broken code.");
207 });
208
209 test("{ containment: 'document' }", function() {
210 ok(false, "missing test - untested code is broken code.");
211 });
212
213 test("{ containment: 'parent' }", function() {
214 ok(false, "missing test - untested code is broken code.");
215 });
216
217 test("{ containment: 'window' }", function() {
218 ok(false, "missing test - untested code is broken code.");
219 });
220
221 test("{ containment: Selector }", function() {
222 ok(false, "missing test - untested code is broken code.");
223 });
224
225 test("{ cursor: 'auto' }, default", function() {
226 ok(false, "missing test - untested code is broken code.");
227 });
228
229 test("{ cursor: 'move' }", function() {
230 ok(false, "missing test - untested code is broken code.");
231 });
232
233 test("{ cursorAt: false }, default", function() {
234 ok(false, "missing test - untested code is broken code.");
235 });
236
237 test("{ cursorAt: true }", function() {
238 ok(false, "missing test - untested code is broken code.");
239 });
240
241 test("{ delay: 0 }, default", function() {
242 ok(false, "missing test - untested code is broken code.");
243 });
244
245 test("{ delay: 100 }", function() {
246 ok(false, "missing test - untested code is broken code.");
247 });
248
249 test("{ distance: 1 }, default", function() {
250 ok(false, "missing test - untested code is broken code.");
251 });
252
253 test("{ distance: 10 }", function() {
254 ok(false, "missing test - untested code is broken code.");
255 });
256
257 test("{ dropOnEmpty: true }, default", function() {
258 ok(false, "missing test - untested code is broken code.");
259 });
260
261 test("{ dropOnEmpty: false }", function() {
262 ok(false, "missing test - untested code is broken code.");
263 });
264 */
265
266 QUnit.test( "{ forcePlaceholderSize: false } table rows", function( assert ) {
267 assert.expect( 1 );
268
269 var element = $( "#sortable-table2 tbody" );
270
271 element.sortable( {
272 placeholder: "test",
273 forcePlaceholderSize: false,
274 start: function( event, ui ) {
275 assert.notEqual( ui.placeholder.height(), ui.item.height(),
276 "placeholder is same height as item" );
277 }
278 } );
279
280 // This row has a non-standard height
281 $( "tr", element ).eq( 0 ).simulate( "drag", {
282 dy: 1
283 } );
284 } );
285
286 QUnit.test( "{ forcePlaceholderSize: true } table rows", function( assert ) {
287 assert.expect( 2 );
288
289 // Table should have the placeholder's height set the same as the row we're dragging
290 var element = $( "#sortable-table2 tbody" ),
291 jqMinor = $.fn.jquery.substring( 0, 4 );
292
293 element.sortable( {
294 placeholder: "test",
295 forcePlaceholderSize: true,
296 start: function( event, ui ) {
297 assert.equal( ui.placeholder.height(), ui.item.height(),
298 "placeholder is same height as item" );
299 }
300 } );
301
302 // First row has a non-standard height
303 $( "tr", element ).eq( 0 ).simulate( "drag", {
304 dy: 1
305 } );
306
307 // Second row's height is normal
308 $( "tr", element ).eq( 1 ).simulate( "drag", {
309 dy: 1
310 } );
311 } );
312
313 /*
314 test("{ forceHelperSize: false }, default", function() {
315 ok(false, "missing test - untested code is broken code.");
316 });
317
318 test("{ forceHelperSize: true }", function() {
319 ok(false, "missing test - untested code is broken code.");
320 });
321
322 test("{ grid: false }, default", function() {
323 ok(false, "missing test - untested code is broken code.");
324 });
325
326 test("{ grid: [17, 3] }", function() {
327 ok(false, "missing test - untested code is broken code.");
328 });
329
330 test("{ grid: [3, 7] }", function() {
331 ok(false, "missing test - untested code is broken code.");
332 });
333
334 test("{ handle: false }, default", function() {
335 ok(false, "missing test - untested code is broken code.");
336 });
337
338 test("{ handle: Element }", function() {
339 ok(false, "missing test - untested code is broken code.");
340 });
341
342 test("{ handle: Selector }", function() {
343 ok(false, "missing test - untested code is broken code.");
344 });
345
346 test("{ helper: 'original' }, default", function() {
347 ok(false, "missing test - untested code is broken code.");
348 });
349
350 test("{ helper: Function }", function() {
351 ok(false, "missing test - untested code is broken code.");
352 });
353
354 test("{ items: '> *' }, default", function() {
355 ok(false, "missing test - untested code is broken code.");
356 });
357
358 test("{ items: Selector }", function() {
359 ok(false, "missing test - untested code is broken code.");
360 });
361
362 test("{ opacity: false }, default", function() {
363 ok(false, "missing test - untested code is broken code.");
364 });
365
366 test("{ opacity: .37 }", function() {
367 ok(false, "missing test - untested code is broken code.");
368 });
369
370 test("{ opacity: 1 }", function() {
371 ok(false, "missing test - untested code is broken code.");
372 });
373
374 test("{ placeholder: false }, default", function() {
375 ok(false, "missing test - untested code is broken code.");
376 });
377 */
378
379 QUnit.test( "{ placeholder: false } img", function( assert ) {
380 assert.expect( 3 );
381
382 var done = assert.async(),
383 element = $( "#sortable-images" ).sortable( {
384 start: function( event, ui ) {
385 assert.ok( ui.placeholder.attr( "src" ).indexOf( "images/jqueryui_32x32.png" ) > 0, "placeholder img has correct src" );
386 assert.equal( ui.placeholder.height(), 32, "placeholder has correct height" );
387 assert.equal( ui.placeholder.width(), 32, "placeholder has correct width" );
388 }
389 } );
390
391 // Give browsers some time to load the image if cache is disabled.
392 // This resolves a frequent issue in Chrome/Safari.
393 setTimeout( function() {
394 element.find( "img" ).eq( 0 ).simulate( "drag", {
395 dy: 1
396 } );
397 done();
398 }, 500 );
399 } );
400
401 QUnit.test( "{ placeholder: String }", function( assert ) {
402 assert.expect( 1 );
403
404 var element = $( "#sortable" ).sortable( {
405 placeholder: "test",
406 start: function( event, ui ) {
407 assert.hasClasses( ui.placeholder, "test" );
408 }
409 } );
410
411 element.find( "li" ).eq( 0 ).simulate( "drag", {
412 dy: 1
413 } );
414 } );
415
416 QUnit.test( "{ placholder: String } tr", function( assert ) {
417 assert.expect( 4 );
418
419 var originalWidths,
420 element = $( "#sortable-table tbody" ).sortable( {
421 placeholder: "test",
422 start: function( event, ui ) {
423 var currentWidths = otherRow.children().map( function() {
424 return $( this ).width();
425 } ).get();
426 assert.hasClasses( ui.placeholder, "test" );
427 assert.deepEqual( currentWidths, originalWidths, "table cells maintian size" );
428 assert.equal( ui.placeholder.children().length, dragRow.children().length,
429 "placeholder has correct number of cells" );
430 assert.equal( ui.placeholder.children().html(), $( "<span>&#160;</span>" ).html(),
431 "placeholder td has content for forced dimensions" );
432 }
433 } ),
434 rows = element.children( "tr" ),
435 dragRow = rows.eq( 0 ),
436 otherRow = rows.eq( 1 );
437
438 originalWidths = otherRow.children().map( function() {
439 return $( this ).width();
440 } ).get();
441 dragRow.simulate( "drag", {
442 dy: 1
443 } );
444 } );
445
446 QUnit.test( "{ placholder: String } tbody", function( assert ) {
447 assert.expect( 6 );
448
449 var originalWidths,
450 element = $( "#sortable-table" ).sortable( {
451 placeholder: "test",
452 start: function( event, ui ) {
453 var currentWidths = otherBody.children().map( function() {
454 return $( this ).width();
455 } ).get();
456 assert.ok( ui.placeholder.hasClass( "test" ), "placeholder has class" );
457 assert.deepEqual( currentWidths, originalWidths, "table cells maintain size" );
458 assert.equal( ui.placeholder.children().length, 1,
459 "placeholder has one child" );
460 assert.equal( ui.placeholder.children( "tr" ).length, 1,
461 "placeholder's child is tr" );
462 assert.equal( ui.placeholder.find( "> tr" ).children().length,
463 dragBody.find( "> tr" ).first().children().length,
464 "placeholder's tr has correct number of cells" );
465 assert.equal( ui.placeholder.find( "> tr" ).children().html(),
466 $( "<span>&#160;</span>" ).html(),
467 "placeholder td has content for forced dimensions" );
468 }
469 } ),
470 bodies = element.children( "tbody" ),
471 dragBody = bodies.eq( 0 ),
472 otherBody = bodies.eq( 1 );
473
474 originalWidths = otherBody.children().map( function() {
475 return $( this ).width();
476 } ).get();
477 dragBody.simulate( "drag", {
478 dy: 1
479 } );
480 } );
481
482 // gh-2001
483 // Sortable: Draggable items moved into a sortable had incorrect position
484 QUnit.test( "{ connectToSortable: Selector } positioning (gh-2001)", function( assert ) {
485 assert.expect( 1 );
486
487 // Code from jQuery Simulate with minor modifications.
488 function findCenter( elem ) {
489 var offset,
490 document = $( elem[ 0 ].ownerDocument );
491 offset = elem.offset();
492
493 return {
494 x: Math.floor( offset.left + elem.outerWidth() / 2 - document.scrollLeft() ),
495 y: Math.floor( offset.top + elem.outerHeight() / 2 - document.scrollTop( ) )
496 };
497 }
498
499 var sortableElem = $( "#sortable" );
500
501 sortableElem.css( "position", "relative" );
502
503 var item = $( "<div></div>" )
504 .text( "6" )
505 .insertBefore( "#sortable" );
506
507 // Padding
508 $( "<div></div>" )
509 .css( {
510 width: "100px",
511 height: "100px"
512 } )
513 .insertBefore( "#sortable" );
514
515 item.draggable( {
516 connectToSortable: "#sortable"
517 } );
518 sortableElem.sortable();
519
520 // Simulate a drag without a drop.
521 var center = findCenter( item );
522 item.simulate( "mousedown", {
523 clientX: center.x,
524 clientY: center.y
525 } );
526 item.simulate( "mousemove", {
527 clientX: center.x,
528 clientY: center.y + 60
529 } );
530 item.simulate( "mousemove", {
531 clientX: center.x,
532 clientY: center.y + 120
533 } );
534
535 assert.ok( item.offset().top > sortableElem.children().eq( 0 ).offset().top,
536 "Draggable offset correct after moving into a sortable" );
537 } );
538
539 /*
540 Test("{ revert: false }, default", function() {
541 ok(false, "missing test - untested code is broken code.");
542 });
543
544 test("{ revert: true }", function() {
545 ok(false, "missing test - untested code is broken code.");
546 });
547
548 test("{ scroll: true }, default", function() {
549 ok(false, "missing test - untested code is broken code.");
550 });
551
552 test("{ scroll: false }", function() {
553 ok(false, "missing test - untested code is broken code.");
554 });
555
556 test("{ scrollSensitivity: 20 }, default", function() {
557 ok(false, "missing test - untested code is broken code.");
558 });
559
560 test("{ scrollSensitivity: 2 }", function() {
561 ok(false, "missing test - untested code is broken code.");
562 });
563
564 test("{ scrollSensitivity: 200 }", function() {
565 ok(false, "missing test - untested code is broken code.");
566 });
567
568 test("{ scrollSpeed: 20 }, default", function() {
569 ok(false, "missing test - untested code is broken code.");
570 });
571
572 test("{ scrollSpeed: 2 }", function() {
573 ok(false, "missing test - untested code is broken code.");
574 });
575
576 test("{ scrollSpeed: 200 }", function() {
577 ok(false, "missing test - untested code is broken code.");
578 });
579
580 test("{ scope: 'default' }, default", function() {
581 ok(false, "missing test - untested code is broken code.");
582 });
583
584 test("{ scope: ??? }, unexpected", function() {
585 ok(false, "missing test - untested code is broken code.");
586 });
587
588 test("{ tolerance: 'intersect' }, default", function() {
589 ok(false, "missing test - untested code is broken code.");
590 });
591
592 test("{ tolerance: 'pointer' }", function() {
593 ok(false, "missing test - untested code is broken code.");
594 });
595
596 test("{ zIndex: 1000 }, default", function() {
597 ok(false, "missing test - untested code is broken code.");
598 });
599
600 test("{ zIndex: 1 }", function() {
601 ok(false, "missing test - untested code is broken code.");
602 });
603
604 test("{ zIndex: false }", function() {
605 ok(false, "missing test - untested code is broken code.");
606 });
607 */
608 } );