@@ -381,6 +381,62 @@ describe('uiSortable', function() {
381
381
} ) ;
382
382
} ) ;
383
383
384
+ it ( 'should work when "placeholder" and "helper: function" options are used and a drag is reverted' , function ( ) {
385
+ inject ( function ( $compile , $rootScope ) {
386
+ var elementTop , elementBottom ;
387
+ elementTop = $compile ( '<ul ui-sortable="opts" class="cross-sortable" ng-model="itemsTop"><li ng-repeat="item in itemsTop" id="s-top-{{$index}}" class="sortable-item">{{ item }}</li></ul>' ) ( $rootScope ) ;
388
+ elementBottom = $compile ( '<ul ui-sortable="opts" class="cross-sortable" ng-model="itemsBottom"><li ng-repeat="item in itemsBottom" id="s-bottom-{{$index}}" class="sortable-item">{{ item }}</li></ul>' ) ( $rootScope ) ;
389
+ $rootScope . $apply ( function ( ) {
390
+ $rootScope . itemsTop = [ 'Top One' , 'Top Two' , 'Top Three' ] ;
391
+ $rootScope . itemsBottom = [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ;
392
+ $rootScope . opts = {
393
+ helper : function ( e , item ) {
394
+ return item . clone ( ) . text ( 'helper' ) ;
395
+ } ,
396
+ placeholder : 'sortable-item-placeholder' ,
397
+ connectWith : '.cross-sortable'
398
+ } ;
399
+ } ) ;
400
+
401
+ host . append ( elementTop ) . append ( elementBottom ) . append ( '<div class="clear"></div>' ) ;
402
+
403
+ var li1 = elementTop . find ( ':eq(2)' ) ;
404
+ var li2 = elementBottom . find ( ':eq(1)' ) ;
405
+ simulateElementDrag ( li1 , li2 , { place : 'below' , action : 'dragAndRevert' } ) ;
406
+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top One' , 'Top Two' , 'Top Three' ] ) ;
407
+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ) ;
408
+ expect ( $rootScope . itemsTop ) . toEqual ( listContent ( elementTop ) ) ;
409
+ expect ( $rootScope . itemsBottom ) . toEqual ( listContent ( elementBottom ) ) ;
410
+
411
+ li1 = elementTop . find ( ':eq(0)' ) ;
412
+ li2 = elementBottom . find ( ':eq(0)' ) ;
413
+ simulateElementDrag ( li1 , li2 , 'below' ) ;
414
+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top Two' , 'Top Three' ] ) ;
415
+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 'Top One' , 'Bottom Two' , 'Bottom Three' ] ) ;
416
+ expect ( $rootScope . itemsTop ) . toEqual ( listContent ( elementTop ) ) ;
417
+ expect ( $rootScope . itemsBottom ) . toEqual ( listContent ( elementBottom ) ) ;
418
+
419
+ li1 = elementBottom . find ( ':eq(1)' ) ;
420
+ li2 = elementTop . find ( ':eq(1)' ) ;
421
+ simulateElementDrag ( li1 , li2 , { place : 'above' , extradx : - 20 , extrady : - 10 } ) ;
422
+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top Two' , 'Top One' , 'Top Three' ] ) ;
423
+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ) ;
424
+ expect ( $rootScope . itemsTop ) . toEqual ( listContent ( elementTop ) ) ;
425
+ expect ( $rootScope . itemsBottom ) . toEqual ( listContent ( elementBottom ) ) ;
426
+
427
+ li1 = elementTop . find ( ':eq(2)' ) ;
428
+ li2 = elementBottom . find ( ':eq(1)' ) ;
429
+ simulateElementDrag ( li1 , li2 , { place : 'below' , extradx : - 20 , extrady : - 10 } ) ;
430
+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top Two' , 'Top One' ] ) ;
431
+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 'Bottom Two' , 'Top Three' , 'Bottom Three' ] ) ;
432
+ expect ( $rootScope . itemsTop ) . toEqual ( listContent ( elementTop ) ) ;
433
+ expect ( $rootScope . itemsBottom ) . toEqual ( listContent ( elementBottom ) ) ;
434
+
435
+ $ ( elementTop ) . remove ( ) ;
436
+ $ ( elementBottom ) . remove ( ) ;
437
+ } ) ;
438
+ } ) ;
439
+
384
440
it ( 'should work when "helper: function" that returns a list element is used' , function ( ) {
385
441
inject ( function ( $compile , $rootScope ) {
386
442
var elementTop , elementBottom ;
0 commit comments