@@ -471,6 +471,145 @@ describe('uiSortable', function() {
471471 } ) ;
472472 } ) ;
473473
474+ it ( 'should properly set ui.item.sortable properties' , function ( ) {
475+ inject ( function ( $compile , $rootScope ) {
476+ var elementTop , elementBottom , updateCallbackExpectations , stopCallbackExpectations ;
477+ elementTop = $compile ( '<ul ui-sortable="opts" class="cross-sortable" ng-model="itemsTop"><li ng-repeat="item in itemsTop" id="s-top-{{$index}}">{{ item }}</li></ul>' ) ( $rootScope ) ;
478+ elementBottom = $compile ( '<ul ui-sortable="opts" class="cross-sortable" ng-model="itemsBottom"><li ng-repeat="item in itemsBottom" id="s-bottom-{{$index}}">{{ item }}</li></ul>' ) ( $rootScope ) ;
479+ $rootScope . $apply ( function ( ) {
480+ $rootScope . itemsTop = [ 'Top One' , 'Top Two' , 'Top Three' ] ;
481+ $rootScope . itemsBottom = [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ;
482+ $rootScope . opts = {
483+ connectWith : '.cross-sortable' ,
484+ update : function ( e , ui ) {
485+ if ( ui . item . scope ( ) &&
486+ ( typeof ui . item . scope ( ) . item === 'string' ) &&
487+ ui . item . scope ( ) . item . indexOf ( 'Two' ) >= 0 ) {
488+ ui . item . sortable . cancel ( ) ;
489+ }
490+ updateCallbackExpectations ( ui . item . sortable ) ;
491+ } ,
492+ stop : function ( e , ui ) {
493+ stopCallbackExpectations ( ui . item . sortable ) ;
494+ }
495+ } ;
496+ } ) ;
497+
498+ host . append ( elementTop ) . append ( elementBottom ) . append ( '<div class="clear"></div>' ) ;
499+
500+ var li1 = elementTop . find ( ':eq(1)' ) ;
501+ var li2 = elementBottom . find ( ':eq(0)' ) ;
502+ updateCallbackExpectations = function ( uiItemSortable ) {
503+ expect ( uiItemSortable . model ) . toEqual ( 'Top Two' ) ;
504+ expect ( uiItemSortable . index ) . toEqual ( 1 ) ;
505+ expect ( uiItemSortable . source . length ) . toEqual ( 1 ) ;
506+ expect ( uiItemSortable . source [ 0 ] ) . toBe ( host . children ( ) [ 0 ] ) ;
507+ expect ( uiItemSortable . sourceModel ) . toBe ( $rootScope . itemsTop ) ;
508+ expect ( uiItemSortable . isCanceled ( ) ) . toBe ( true ) ;
509+ expect ( uiItemSortable . isCustomHelperUsed ( ) ) . toBe ( false ) ;
510+
511+ expect ( uiItemSortable . dropindex ) . toEqual ( 1 ) ;
512+ expect ( uiItemSortable . droptarget . length ) . toBe ( 1 ) ;
513+ expect ( uiItemSortable . droptarget [ 0 ] ) . toBe ( host . children ( ) [ 1 ] ) ;
514+ expect ( uiItemSortable . droptargetModel ) . toBe ( $rootScope . itemsBottom ) ;
515+ } ;
516+ stopCallbackExpectations = function ( uiItemSortable ) {
517+ expect ( uiItemSortable . received ) . toBe ( true ) ;
518+ expect ( uiItemSortable . moved ) . toBe ( undefined ) ;
519+ } ;
520+ simulateElementDrag ( li1 , li2 , { place : 'below' , extradx : - 20 , extrady : - 10 } ) ;
521+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top One' , 'Top Two' , 'Top Three' ] ) ;
522+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ) ;
523+ expect ( $rootScope . itemsTop ) . toEqual ( listContent ( elementTop ) ) ;
524+ expect ( $rootScope . itemsBottom ) . toEqual ( listContent ( elementBottom ) ) ;
525+ updateCallbackExpectations = stopCallbackExpectations = undefined ;
526+
527+ li1 = elementBottom . find ( ':eq(1)' ) ;
528+ li2 = elementTop . find ( ':eq(1)' ) ;
529+ updateCallbackExpectations = function ( uiItemSortable ) {
530+ expect ( uiItemSortable . model ) . toEqual ( 'Bottom Two' ) ;
531+ expect ( uiItemSortable . index ) . toEqual ( 1 ) ;
532+ expect ( uiItemSortable . source . length ) . toEqual ( 1 ) ;
533+ expect ( uiItemSortable . source [ 0 ] ) . toBe ( host . children ( ) [ 1 ] ) ;
534+ expect ( uiItemSortable . sourceModel ) . toBe ( $rootScope . itemsBottom ) ;
535+ expect ( uiItemSortable . isCanceled ( ) ) . toBe ( true ) ;
536+ expect ( uiItemSortable . isCustomHelperUsed ( ) ) . toBe ( false ) ;
537+
538+ expect ( uiItemSortable . dropindex ) . toEqual ( 1 ) ;
539+ expect ( uiItemSortable . droptarget . length ) . toBe ( 1 ) ;
540+ expect ( uiItemSortable . droptarget [ 0 ] ) . toBe ( host . children ( ) [ 0 ] ) ;
541+ expect ( uiItemSortable . droptargetModel ) . toBe ( $rootScope . itemsTop ) ;
542+ } ;
543+ stopCallbackExpectations = function ( uiItemSortable ) {
544+ expect ( uiItemSortable . received ) . toBe ( true ) ;
545+ expect ( uiItemSortable . moved ) . toBe ( undefined ) ;
546+ } ;
547+ simulateElementDrag ( li1 , li2 , { place : 'above' , extradx : - 20 , extrady : - 10 } ) ;
548+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top One' , 'Top Two' , 'Top Three' ] ) ;
549+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ) ;
550+ expect ( $rootScope . itemsTop ) . toEqual ( listContent ( elementTop ) ) ;
551+ expect ( $rootScope . itemsBottom ) . toEqual ( listContent ( elementBottom ) ) ;
552+ updateCallbackExpectations = stopCallbackExpectations = undefined ;
553+
554+ li1 = elementTop . find ( ':eq(0)' ) ;
555+ li2 = elementBottom . find ( ':eq(0)' ) ;
556+ updateCallbackExpectations = function ( uiItemSortable ) {
557+ expect ( uiItemSortable . model ) . toEqual ( 'Top One' ) ;
558+ expect ( uiItemSortable . index ) . toEqual ( 0 ) ;
559+ expect ( uiItemSortable . source . length ) . toEqual ( 1 ) ;
560+ expect ( uiItemSortable . source [ 0 ] ) . toBe ( host . children ( ) [ 0 ] ) ;
561+ expect ( uiItemSortable . sourceModel ) . toBe ( $rootScope . itemsTop ) ;
562+ expect ( uiItemSortable . isCanceled ( ) ) . toBe ( false ) ;
563+ expect ( uiItemSortable . isCustomHelperUsed ( ) ) . toBe ( false ) ;
564+
565+ expect ( uiItemSortable . dropindex ) . toEqual ( 1 ) ;
566+ expect ( uiItemSortable . droptarget . length ) . toBe ( 1 ) ;
567+ expect ( uiItemSortable . droptarget [ 0 ] ) . toBe ( host . children ( ) [ 1 ] ) ;
568+ expect ( uiItemSortable . droptargetModel ) . toBe ( $rootScope . itemsBottom ) ;
569+ } ;
570+ stopCallbackExpectations = function ( uiItemSortable ) {
571+ expect ( uiItemSortable . received ) . toBe ( true ) ;
572+ expect ( uiItemSortable . moved ) . toBe ( 'Top One' ) ;
573+ } ;
574+ simulateElementDrag ( li1 , li2 , 'below' ) ;
575+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top Two' , 'Top Three' ] ) ;
576+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 'Top One' , 'Bottom Two' , 'Bottom Three' ] ) ;
577+ expect ( $rootScope . itemsTop ) . toEqual ( listContent ( elementTop ) ) ;
578+ expect ( $rootScope . itemsBottom ) . toEqual ( listContent ( elementBottom ) ) ;
579+ updateCallbackExpectations = stopCallbackExpectations = undefined ;
580+
581+ li1 = elementBottom . find ( ':eq(1)' ) ;
582+ li2 = elementTop . find ( ':eq(1)' ) ;
583+ updateCallbackExpectations = function ( uiItemSortable ) {
584+ expect ( uiItemSortable . model ) . toEqual ( 'Top One' ) ;
585+ expect ( uiItemSortable . index ) . toEqual ( 1 ) ;
586+ expect ( uiItemSortable . source . length ) . toEqual ( 1 ) ;
587+ expect ( uiItemSortable . source [ 0 ] ) . toBe ( host . children ( ) [ 1 ] ) ;
588+ expect ( uiItemSortable . sourceModel ) . toBe ( $rootScope . itemsBottom ) ;
589+ expect ( uiItemSortable . isCanceled ( ) ) . toBe ( false ) ;
590+ expect ( uiItemSortable . isCustomHelperUsed ( ) ) . toBe ( false ) ;
591+
592+ expect ( uiItemSortable . dropindex ) . toEqual ( 1 ) ;
593+ expect ( uiItemSortable . droptarget . length ) . toBe ( 1 ) ;
594+ expect ( uiItemSortable . droptarget [ 0 ] ) . toBe ( host . children ( ) [ 0 ] ) ;
595+ expect ( uiItemSortable . droptargetModel ) . toBe ( $rootScope . itemsTop ) ;
596+ } ;
597+ stopCallbackExpectations = function ( uiItemSortable ) {
598+ expect ( uiItemSortable . received ) . toBe ( true ) ;
599+ expect ( uiItemSortable . moved ) . toBe ( 'Top One' ) ;
600+ } ;
601+ simulateElementDrag ( li1 , li2 , { place : 'above' , extradx : - 20 , extrady : - 10 } ) ;
602+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top Two' , 'Top One' , 'Top Three' ] ) ;
603+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ) ;
604+ expect ( $rootScope . itemsTop ) . toEqual ( listContent ( elementTop ) ) ;
605+ expect ( $rootScope . itemsBottom ) . toEqual ( listContent ( elementBottom ) ) ;
606+ updateCallbackExpectations = stopCallbackExpectations = undefined ;
607+
608+ $ ( elementTop ) . remove ( ) ;
609+ $ ( elementBottom ) . remove ( ) ;
610+ } ) ;
611+ } ) ;
612+
474613 it ( 'should properly free ui.item.sortable object' , function ( ) {
475614 inject ( function ( $compile , $rootScope ) {
476615 var elementTop , elementBottom , uiItem , uiItemSortable_Destroy ;
0 commit comments