@@ -649,6 +649,82 @@ describe('uiSortable', function() {
649649 } ) ;
650650 } ) ;
651651
652+ it ( 'should properly set ui.item.sortable.droptargetModel when using data-ng-model' , function ( ) {
653+ inject ( function ( $compile , $rootScope ) {
654+ var elementTop , elementBottom , updateCallbackExpectations ;
655+ elementTop = $compile ( '<ul ui-sortable="opts" class="cross-sortable" data-ng-model="itemsTop"><li ng-repeat="item in itemsTop" id="s-top-{{$index}}">{{ item }}</li></ul>' ) ( $rootScope ) ;
656+ elementBottom = $compile ( '<ul ui-sortable="opts" class="cross-sortable" data-ng-model="itemsBottom"><li ng-repeat="item in itemsBottom" id="s-bottom-{{$index}}">{{ item }}</li></ul>' ) ( $rootScope ) ;
657+ $rootScope . $apply ( function ( ) {
658+ $rootScope . itemsTop = [ 'Top One' , 'Top Two' , 'Top Three' ] ;
659+ $rootScope . itemsBottom = [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ;
660+ $rootScope . opts = {
661+ connectWith : '.cross-sortable' ,
662+ update : function ( e , ui ) {
663+ if ( ui . item . scope ( ) &&
664+ ( typeof ui . item . scope ( ) . item === 'string' ) &&
665+ ui . item . scope ( ) . item . indexOf ( 'Two' ) >= 0 ) {
666+ ui . item . sortable . cancel ( ) ;
667+ }
668+ updateCallbackExpectations ( ui . item . sortable ) ;
669+ }
670+ } ;
671+ } ) ;
672+
673+ host . append ( elementTop ) . append ( elementBottom ) . append ( '<div class="clear"></div>' ) ;
674+
675+ var li1 = elementTop . find ( ':eq(1)' ) ;
676+ var li2 = elementBottom . find ( ':eq(0)' ) ;
677+ updateCallbackExpectations = function ( uiItemSortable ) {
678+ expect ( uiItemSortable . droptargetModel ) . toBe ( $rootScope . itemsBottom ) ;
679+ } ;
680+ simulateElementDrag ( li1 , li2 , { place : 'below' , extradx : - 20 , extrady : - 10 } ) ;
681+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top One' , 'Top Two' , 'Top Three' ] ) ;
682+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ) ;
683+ expect ( $rootScope . itemsTop ) . toEqual ( listContent ( elementTop ) ) ;
684+ expect ( $rootScope . itemsBottom ) . toEqual ( listContent ( elementBottom ) ) ;
685+ updateCallbackExpectations = undefined ;
686+
687+ li1 = elementBottom . find ( ':eq(1)' ) ;
688+ li2 = elementTop . find ( ':eq(1)' ) ;
689+ updateCallbackExpectations = function ( uiItemSortable ) {
690+ expect ( uiItemSortable . droptargetModel ) . toBe ( $rootScope . itemsTop ) ;
691+ } ;
692+ simulateElementDrag ( li1 , li2 , { place : 'above' , extradx : - 20 , extrady : - 10 } ) ;
693+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top One' , 'Top Two' , 'Top Three' ] ) ;
694+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ) ;
695+ expect ( $rootScope . itemsTop ) . toEqual ( listContent ( elementTop ) ) ;
696+ expect ( $rootScope . itemsBottom ) . toEqual ( listContent ( elementBottom ) ) ;
697+ updateCallbackExpectations = undefined ;
698+
699+ li1 = elementTop . find ( ':eq(0)' ) ;
700+ li2 = elementBottom . find ( ':eq(0)' ) ;
701+ updateCallbackExpectations = function ( uiItemSortable ) {
702+ expect ( uiItemSortable . droptargetModel ) . toBe ( $rootScope . itemsBottom ) ;
703+ } ;
704+ simulateElementDrag ( li1 , li2 , 'below' ) ;
705+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top Two' , 'Top Three' ] ) ;
706+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 'Top One' , 'Bottom Two' , 'Bottom Three' ] ) ;
707+ expect ( $rootScope . itemsTop ) . toEqual ( listContent ( elementTop ) ) ;
708+ expect ( $rootScope . itemsBottom ) . toEqual ( listContent ( elementBottom ) ) ;
709+ updateCallbackExpectations = undefined ;
710+
711+ li1 = elementBottom . find ( ':eq(1)' ) ;
712+ li2 = elementTop . find ( ':eq(1)' ) ;
713+ updateCallbackExpectations = function ( uiItemSortable ) {
714+ expect ( uiItemSortable . droptargetModel ) . toBe ( $rootScope . itemsTop ) ;
715+ } ;
716+ simulateElementDrag ( li1 , li2 , { place : 'above' , extradx : - 20 , extrady : - 10 } ) ;
717+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top Two' , 'Top One' , 'Top Three' ] ) ;
718+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ) ;
719+ expect ( $rootScope . itemsTop ) . toEqual ( listContent ( elementTop ) ) ;
720+ expect ( $rootScope . itemsBottom ) . toEqual ( listContent ( elementBottom ) ) ;
721+ updateCallbackExpectations = undefined ;
722+
723+ $ ( elementTop ) . remove ( ) ;
724+ $ ( elementBottom ) . remove ( ) ;
725+ } ) ;
726+ } ) ;
727+
652728 it ( 'should properly free ui.item.sortable object' , function ( ) {
653729 inject ( function ( $compile , $rootScope ) {
654730 var elementTop , elementBottom , uiItem , uiItemSortable_Destroy ;
0 commit comments