@@ -347,6 +347,89 @@ describe('uiSortable', function() {
347347 } ) ;
348348 } ) ;
349349
350+ it ( 'should work when "helper: function" that returns a list element is used' , function ( ) {
351+ inject ( function ( $compile , $rootScope ) {
352+ var elementTop , elementBottom ;
353+ 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 ) ;
354+ 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 ) ;
355+ $rootScope . $apply ( function ( ) {
356+ $rootScope . itemsTop = [ 'Top One' , 'Top Two' , 'Top Three' ] ;
357+ $rootScope . itemsBottom = [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ;
358+ $rootScope . opts = {
359+ helper : function ( e , item ) {
360+ return item ;
361+ } ,
362+ connectWith : '.cross-sortable'
363+ } ;
364+ } ) ;
365+
366+ host . append ( elementTop ) . append ( elementBottom ) ;
367+
368+ var li1 = elementTop . find ( ':eq(0)' ) ;
369+ var li2 = elementBottom . find ( ':eq(0)' ) ;
370+ var dy = EXTRA_DY_PERCENTAGE * li1 . outerHeight ( ) + ( li2 . position ( ) . top - li1 . position ( ) . top ) ;
371+ li1 . simulate ( 'drag' , { dy : dy } ) ;
372+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top Two' , 'Top Three' ] ) ;
373+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 'Top One' , 'Bottom Two' , 'Bottom Three' ] ) ;
374+ expect ( $rootScope . itemsTop ) . toEqual ( listContent ( elementTop ) ) ;
375+ expect ( $rootScope . itemsBottom ) . toEqual ( listContent ( elementBottom ) ) ;
376+
377+ li1 = elementBottom . find ( ':eq(1)' ) ;
378+ li2 = elementTop . find ( ':eq(1)' ) ;
379+ dy = - EXTRA_DY_PERCENTAGE * li1 . outerHeight ( ) - ( li1 . position ( ) . top - li2 . position ( ) . top ) ;
380+ li1 . simulate ( 'drag' , { dy : dy } ) ;
381+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top Two' , 'Top One' , 'Top Three' ] ) ;
382+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ) ;
383+ expect ( $rootScope . itemsTop ) . toEqual ( listContent ( elementTop ) ) ;
384+ expect ( $rootScope . itemsBottom ) . toEqual ( listContent ( elementBottom ) ) ;
385+
386+ $ ( elementTop ) . remove ( ) ;
387+ $ ( elementBottom ) . remove ( ) ;
388+ } ) ;
389+ } ) ;
390+
391+ it ( 'should work when "placeholder" and "helper: function" that returns a list element are used' , function ( ) {
392+ inject ( function ( $compile , $rootScope ) {
393+ var elementTop , elementBottom ;
394+ 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 ) ;
395+ 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 ) ;
396+ $rootScope . $apply ( function ( ) {
397+ $rootScope . itemsTop = [ 'Top One' , 'Top Two' , 'Top Three' ] ;
398+ $rootScope . itemsBottom = [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ;
399+ $rootScope . opts = {
400+ helper : function ( e , item ) {
401+ return item ;
402+ } ,
403+ placeholder : 'sortable-item-placeholder' ,
404+ connectWith : '.cross-sortable'
405+ } ;
406+ } ) ;
407+
408+ host . append ( elementTop ) . append ( elementBottom ) ;
409+
410+ var li1 = elementTop . find ( ':eq(0)' ) ;
411+ var li2 = elementBottom . find ( ':eq(0)' ) ;
412+ var dy = EXTRA_DY_PERCENTAGE * li1 . outerHeight ( ) + ( li2 . position ( ) . top - li1 . position ( ) . top ) ;
413+ li1 . simulate ( 'drag' , { dy : dy } ) ;
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+ dy = - EXTRA_DY_PERCENTAGE * li1 . outerHeight ( ) - ( li1 . position ( ) . top - li2 . position ( ) . top ) ;
422+ li1 . simulate ( 'drag' , { dy : dy } ) ;
423+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top Two' , 'Top One' , 'Top Three' ] ) ;
424+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ) ;
425+ expect ( $rootScope . itemsTop ) . toEqual ( listContent ( elementTop ) ) ;
426+ expect ( $rootScope . itemsBottom ) . toEqual ( listContent ( elementBottom ) ) ;
427+
428+ $ ( elementTop ) . remove ( ) ;
429+ $ ( elementBottom ) . remove ( ) ;
430+ } ) ;
431+ } ) ;
432+
350433 it ( 'should update model when sorting between nested sortables' , function ( ) {
351434 inject ( function ( $compile , $rootScope ) {
352435 var elementTree , li1 , li2 , dy ;
0 commit comments