Skip to content

Commit bfb6507

Browse files
committed
Draggable: Add battery of tests to cover connectToSortable
Refs #9481 Refs #9675 Closes jquerygh-1323
1 parent 52a1de5 commit bfb6507

File tree

2 files changed

+107
-28
lines changed

2 files changed

+107
-28
lines changed

tests/unit/draggable/draggable.html

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,11 @@
4646
#draggable3, #draggable4 {
4747
z-index: 100;
4848
}
49-
#sortable {
49+
.sortable {
5050
position: relative;
5151
top: 8000px;
5252
left: 10px;
53-
}
54-
#sortable2 {
55-
position: relative;
56-
top: 9000px;
57-
left: 10px;
58-
}
59-
.sortable {
6053
width: 300px;
61-
height: 100px;
6254
padding: 0;
6355
margin: 0;
6456
border: 0;
@@ -117,13 +109,13 @@
117109
<div style="width: 1px; height: 1000px;"></div>
118110
<div style="position: absolute; width: 1px; height: 2000px;"></div>
119111
<ul id="sortable" class="sortable">
120-
<li>Item 0</li>
121-
<li id="draggableSortable">Item 1</li>
112+
<li id="draggableSortable">Item 0</li>
113+
<li id="draggableSortable2">Item 1</li>
122114
<li>Item 2</li>
123115
<li>Item 3</li>
124116
</ul>
125117
<ul id="sortable2" class="sortable">
126-
<li id="draggableSortableClone">Item 0</li>
118+
<li id="draggableSortableClone" class="sortable2Item">Item 0</li>
127119
<li>Item 1</li>
128120
<li>Item 2</li>
129121
<li>Item 3</li>

tests/unit/draggable/draggable_options.js

Lines changed: 103 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -244,23 +244,15 @@ test( "cancelement, default, switching after initialization", function() {
244244
TestHelpers.draggable.shouldNotDrag( element, "cancel: input, input dragged", input );
245245
});
246246

247-
/*
248-
test( "{ connectToSortable: selector }, default", function() {
249-
expect( 1 );
250-
251-
ok(false, "missing test - untested code is broken code" );
252-
});
253-
*/
254-
255247
test( "connectToSortable, dragging out of a sortable", function() {
256-
expect( 3 );
248+
expect( 4 );
257249

258250
var sortItem, dragHelper,
259251
element = $( "#draggableSortable" ).draggable({
260252
scroll: false,
261253
connectToSortable: "#sortable"
262254
}),
263-
sortable = $( "#sortable" ).sortable(),
255+
sortable = $( "#sortable" ).sortable({ revert: 100 }),
264256
dx = 50,
265257
dy = 50,
266258
offsetBefore = element.offset(),
@@ -286,6 +278,10 @@ test( "connectToSortable, dragging out of a sortable", function() {
286278
// HTML IDs are removed when dragging to a Sortable
287279
equal( sortItem[ 0 ], dragHelper[ 0 ], "both have the same helper" );
288280
equal( sortItem.attr( "id" ), dragHelper.attr( "id" ), "both have the same id" );
281+
282+
// http://bugs.jqueryui.com/ticket/9481
283+
// connectToSortable causes sortable revert to fail on second attempt
284+
equal( sortable.sortable( "option", "revert" ), 100, "sortable revert behavior is preserved" );
289285
});
290286

291287
element.simulate( "drag", {
@@ -294,21 +290,31 @@ test( "connectToSortable, dragging out of a sortable", function() {
294290
});
295291
});
296292

297-
test( "connectToSortable, dragging clone into sortable", function() {
298-
expect( 1 );
293+
asyncTest( "connectToSortable, dragging clone into sortable", function() {
294+
expect( 3 );
299295

300-
var element = $( "#draggableSortableClone" ).draggable({
296+
var offsetPlaceholder,
297+
element = $( "#draggableSortableClone" ).draggable({
301298
scroll: false,
302299
connectToSortable: "#sortable",
303300
helper: "clone"
304301
}),
305-
sortable = $( "#sortable" ).sortable(),
302+
sortable = $( "#sortable" ).sortable({ revert: 100 }),
306303
offsetSortable = sortable.offset();
307304

308305
$( sortable ).one( "sort", function( event, ui ) {
306+
offsetPlaceholder = ui.placeholder.offset();
309307
// http://bugs.jqueryui.com/ticket/8809
310308
// Position issue when connected to sortable
311309
deepEqual( ui.helper.offset(), offsetSortable, "sortable offset is correct" );
310+
notDeepEqual( ui.helper.offset(), offsetPlaceholder, "offset not equal to placeholder" );
311+
});
312+
313+
$( sortable ).one( "sortstop", function( event, ui ) {
314+
// http://bugs.jqueryui.com/ticket/9675
315+
// Animation issue with revert and connectToSortable
316+
deepEqual( ui.item.offset(), offsetPlaceholder, "offset eventually equals placeholder" );
317+
start();
312318
});
313319

314320
element.simulate( "drag", {
@@ -318,6 +324,87 @@ test( "connectToSortable, dragging clone into sortable", function() {
318324
});
319325
});
320326

327+
test( "connectToSortable, dragging multiple elements in and out of sortable", function() {
328+
expect( 1 );
329+
330+
var element = $( "#draggableSortableClone" ).draggable({
331+
scroll: false,
332+
connectToSortable: "#sortable",
333+
helper: "clone"
334+
}),
335+
element2 = $( "#draggableSortable" ).draggable({
336+
scroll: false,
337+
connectToSortable: "#sortable"
338+
}),
339+
sortable = $( "#sortable" ).sortable({ revert: false }),
340+
sortableOffset = sortable.offset();
341+
342+
// Move element into sortable
343+
element.simulate( "drag", {
344+
x: sortableOffset.left + 1,
345+
y: sortableOffset.top + 1,
346+
moves: 10
347+
});
348+
349+
// Move element in sortable out
350+
element2.simulate( "drag", {
351+
dx: 200,
352+
dy: 200,
353+
moves: 10
354+
});
355+
356+
// http://bugs.jqueryui.com/ticket/9675
357+
// Animation issue with revert and connectToSortable
358+
sortable.one( "sortstop", function( event, ui ) {
359+
ok( !$.contains( document, ui.placeholder[ 0 ] ), "placeholder was removed" );
360+
});
361+
362+
// Move the clone of the first element back out
363+
$( "#sortable .sortable2Item" ).simulate( "drag", {
364+
dx: 200,
365+
dy: 200,
366+
moves: 10
367+
});
368+
});
369+
370+
test( "connectToSortable, dragging through one sortable to a second", function() {
371+
expect( 2 );
372+
373+
var overCount = 0,
374+
element = $( "#draggableSortable" ).draggable({
375+
scroll: false,
376+
connectToSortable: ".sortable"
377+
}),
378+
delta = 200,
379+
sortable = $( "#sortable" ).sortable({ revert: false }),
380+
sortable2 = $( "#sortable2" ).sortable({ revert: false }),
381+
sortable2Offset = sortable2.offset(),
382+
dragParams = {
383+
x: sortable2Offset.left + 25,
384+
y: sortable2Offset.top + sortable.outerHeight() + delta,
385+
moves: 10
386+
};
387+
388+
$( sortable ).one( "sortover", function() {
389+
overCount++;
390+
sortable2.css( "top", "+=" + delta );
391+
});
392+
393+
$( sortable2 ).on( "sortupdate", function() {
394+
ok( true, "second sortable is updated" );
395+
});
396+
397+
$( sortable2 ).one( "sortover", function() {
398+
overCount++;
399+
});
400+
401+
$( sortable2 ).one( "sortstop", function() {
402+
equal( overCount, 2, "went over both sortables" );
403+
});
404+
405+
element.simulate( "drag", dragParams );
406+
});
407+
321408
test( "{ containment: Element }", function() {
322409
expect( 1 );
323410

@@ -456,8 +543,8 @@ test( "containment, element cant be pulled out of container", function() {
456543
})
457544
.draggable({ containment: "parent" })
458545
.simulate( "drag", {
459-
dx: 200,
460-
dy: 200
546+
dx: 500,
547+
dy: 500
461548
});
462549

463550
offsetBefore = element.offset();

0 commit comments

Comments
 (0)