@@ -429,6 +429,130 @@ describe('uiSortable', function() {
429429 } ) ;
430430 } ) ;
431431
432+ it ( 'should work when "helper: function" option is used' , function ( ) {
433+ inject ( function ( $compile , $rootScope ) {
434+ var element ;
435+ element = $compile ( '<ul ui-sortable="opts" ng-model="items"><li ng-repeat="item in items" id="s-{{$index}}" class="sortable-item">{{ item }}</li></ul>' ) ( $rootScope ) ;
436+ $rootScope . $apply ( function ( ) {
437+ $rootScope . opts = {
438+ helper : function ( e , item ) {
439+ return item . clone ( ) . text ( 'helper' ) ;
440+ }
441+ } ;
442+ $rootScope . items = [ 'One' , 'Two' , 'Three' ] ;
443+ } ) ;
444+
445+ host . append ( element ) ;
446+
447+ var li = element . find ( ':eq(1)' ) ;
448+ var dy = ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
449+ li . simulate ( 'drag' , { dy : dy } ) ;
450+ expect ( $rootScope . items ) . toEqual ( [ 'One' , 'Three' , 'Two' ] ) ;
451+ expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
452+
453+ li = element . find ( ':eq(1)' ) ;
454+ dy = - ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
455+ li . simulate ( 'drag' , { dy : dy } ) ;
456+ expect ( $rootScope . items ) . toEqual ( [ 'Three' , 'One' , 'Two' ] ) ;
457+ expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
458+
459+ $ ( element ) . remove ( ) ;
460+ } ) ;
461+ } ) ;
462+
463+ it ( 'should work when "helper: function" option is used and a drag is reverted' , function ( ) {
464+ inject ( function ( $compile , $rootScope ) {
465+ var element ;
466+ element = $compile ( '<ul ui-sortable="opts" ng-model="items"><li ng-repeat="item in items" id="s-{{$index}}" class="sortable-item">{{ item }}</li></ul>' ) ( $rootScope ) ;
467+ $rootScope . $apply ( function ( ) {
468+ $rootScope . opts = {
469+ helper : function ( e , item ) {
470+ return item . clone ( ) . text ( 'helper' ) ;
471+ }
472+ } ;
473+ $rootScope . items = [ 'One' , 'Two' , 'Three' ] ;
474+ } ) ;
475+
476+ host . append ( element ) ;
477+
478+ var li = element . find ( ':eq(0)' ) ;
479+ var dy = ( 2 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
480+ li . simulate ( 'dragAndRevert' , { dy : dy } ) ;
481+ expect ( $rootScope . items ) . toEqual ( [ 'One' , 'Two' , 'Three' ] ) ;
482+ expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
483+
484+ li = element . find ( ':eq(0)' ) ;
485+ dy = ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
486+ li . simulate ( 'drag' , { dy : dy } ) ;
487+ expect ( $rootScope . items ) . toEqual ( [ 'Two' , 'One' , 'Three' ] ) ;
488+ expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
489+
490+ li = element . find ( ':eq(1)' ) ;
491+ dy = ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
492+ li . simulate ( 'drag' , { dy : dy } ) ;
493+ expect ( $rootScope . items ) . toEqual ( [ 'Two' , 'Three' , 'One' ] ) ;
494+ expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
495+
496+ li = element . find ( ':eq(1)' ) ;
497+ dy = ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
498+ li . simulate ( 'drag' , { dy : dy } ) ;
499+ expect ( $rootScope . items ) . toEqual ( [ 'Two' , 'One' , 'Three' ] ) ;
500+ expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
501+
502+ $ ( element ) . remove ( ) ;
503+ } ) ;
504+ } ) ;
505+
506+ it ( 'should work when "helper: function" and "placeholder" options are used together.' , function ( ) {
507+ inject ( function ( $compile , $rootScope ) {
508+ var element ;
509+ element = $compile ( '<ul ui-sortable="opts" ng-model="items"><li ng-repeat="item in items" id="s-{{$index}}" class="sortable-item">{{ item }}</li></ul>' ) ( $rootScope ) ;
510+ $rootScope . $apply ( function ( ) {
511+ $rootScope . opts = {
512+ helper : function ( e , item ) {
513+ return item . clone ( ) . text ( 'helper' ) ;
514+ } ,
515+ placeholder : 'sortable-item'
516+ } ;
517+ $rootScope . items = [ 'One' , 'Two' , 'Three' ] ;
518+ } ) ;
519+
520+ host . append ( element ) ;
521+
522+ var li = element . find ( ':eq(0)' ) ;
523+ var dy = ( 2 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
524+ li . simulate ( 'dragAndRevert' , { dy : dy } ) ;
525+ expect ( $rootScope . items ) . toEqual ( [ 'One' , 'Two' , 'Three' ] ) ;
526+ expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
527+
528+ li = element . find ( ':eq(0)' ) ;
529+ dy = ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
530+ li . simulate ( 'drag' , { dy : dy } ) ;
531+ expect ( $rootScope . items ) . toEqual ( [ 'Two' , 'One' , 'Three' ] ) ;
532+ expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
533+
534+ li = element . find ( ':eq(1)' ) ;
535+ dy = ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
536+ li . simulate ( 'drag' , { dy : dy } ) ;
537+ expect ( $rootScope . items ) . toEqual ( [ 'Two' , 'Three' , 'One' ] ) ;
538+ expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
539+
540+ li = element . find ( ':eq(1)' ) ;
541+ dy = ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
542+ li . simulate ( 'dragAndRevert' , { dy : dy } ) ;
543+ expect ( $rootScope . items ) . toEqual ( [ 'Two' , 'Three' , 'One' ] ) ;
544+ expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
545+
546+ li = element . find ( ':eq(1)' ) ;
547+ dy = ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
548+ li . simulate ( 'drag' , { dy : dy } ) ;
549+ expect ( $rootScope . items ) . toEqual ( [ 'Two' , 'One' , 'Three' ] ) ;
550+ expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
551+
552+ $ ( element ) . remove ( ) ;
553+ } ) ;
554+ } ) ;
555+
432556 } ) ;
433557
434558} ) ;
0 commit comments