@@ -400,6 +400,42 @@ describe('uiSortable', function() {
400
400
} ) ;
401
401
} ) ;
402
402
403
+ it ( 'should update model when sorting a "falsy" item between sortables' , function ( ) {
404
+ inject ( function ( $compile , $rootScope ) {
405
+ var elementTop , elementBottom ;
406
+ 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 ) ;
407
+ 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 ) ;
408
+ $rootScope . $apply ( function ( ) {
409
+ $rootScope . itemsTop = [ 0 , 'Top Two' , 'Top Three' ] ;
410
+ $rootScope . itemsBottom = [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ;
411
+ $rootScope . opts = { connectWith : '.cross-sortable' } ;
412
+ } ) ;
413
+
414
+ host . append ( elementTop ) . append ( elementBottom ) ;
415
+
416
+ var li1 = elementTop . find ( ':eq(0)' ) ;
417
+ var li2 = elementBottom . find ( ':eq(0)' ) ;
418
+ var dy = EXTRA_DY_PERCENTAGE * li1 . outerHeight ( ) + ( li2 . position ( ) . top - li1 . position ( ) . top ) ;
419
+ li1 . simulate ( 'drag' , { dy : dy } ) ;
420
+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top Two' , 'Top Three' ] ) ;
421
+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 0 , 'Bottom Two' , 'Bottom Three' ] ) ;
422
+ expect ( $rootScope . itemsTop ) . toEqualListContent ( elementTop ) ;
423
+ expect ( $rootScope . itemsBottom ) . toEqualListContent ( elementBottom ) ;
424
+
425
+ li1 = elementBottom . find ( ':eq(1)' ) ;
426
+ li2 = elementTop . find ( ':eq(1)' ) ;
427
+ dy = - EXTRA_DY_PERCENTAGE * li1 . outerHeight ( ) - ( li1 . position ( ) . top - li2 . position ( ) . top ) ;
428
+ li1 . simulate ( 'drag' , { dy : dy } ) ;
429
+ expect ( $rootScope . itemsTop ) . toEqual ( [ 'Top Two' , 0 , 'Top Three' ] ) ;
430
+ expect ( $rootScope . itemsBottom ) . toEqual ( [ 'Bottom One' , 'Bottom Two' , 'Bottom Three' ] ) ;
431
+ expect ( $rootScope . itemsTop ) . toEqualListContent ( elementTop ) ;
432
+ expect ( $rootScope . itemsBottom ) . toEqualListContent ( elementBottom ) ;
433
+
434
+ $ ( elementTop ) . remove ( ) ;
435
+ $ ( elementBottom ) . remove ( ) ;
436
+ } ) ;
437
+ } ) ;
438
+
403
439
it ( 'should work when "placeholder" option is used' , function ( ) {
404
440
inject ( function ( $compile , $rootScope ) {
405
441
var elementTop , elementBottom ;
@@ -540,14 +576,14 @@ describe('uiSortable', function() {
540
576
// 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);
541
577
// 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);
542
578
// $rootScope.$apply(function() {
543
- // $rootScope.itemsTop = [" Top One", " Top Two", " Top Three" ];
544
- // $rootScope.itemsBottom = [" Bottom One", " Bottom Two", " Bottom Three" ];
579
+ // $rootScope.itemsTop = [' Top One', ' Top Two', ' Top Three' ];
580
+ // $rootScope.itemsBottom = [' Bottom One', ' Bottom Two', ' Bottom Three' ];
545
581
// $rootScope.opts = {
546
- // connectWith: " .cross-sortable" ,
582
+ // connectWith: ' .cross-sortable' ,
547
583
// update: function(e, ui) {
548
584
// if (ui.item.scope() &&
549
585
// (typeof ui.item.scope().item === 'string') &&
550
- // ui.item.scope().item.indexOf(" Two" ) >= 0) {
586
+ // ui.item.scope().item.indexOf(' Two' ) >= 0) {
551
587
// ui.item.parent().sortable('cancel');
552
588
// }
553
589
// }
@@ -560,35 +596,35 @@ describe('uiSortable', function() {
560
596
// var li2 = elementBottom.find(':eq(0)');
561
597
// var dy = EXTRA_DY_PERCENTAGE * li1.outerHeight() + (li2.position().top - li1.position().top);
562
598
// li1.simulate('drag', { dy: dy });
563
- // expect($rootScope.itemsTop).toEqual([" Top One", " Top Two", " Top Three" ]);
564
- // expect($rootScope.itemsBottom).toEqual([" Bottom One", " Bottom Two", " Bottom Three" ]);
599
+ // expect($rootScope.itemsTop).toEqual([' Top One', ' Top Two', ' Top Three' ]);
600
+ // expect($rootScope.itemsBottom).toEqual([' Bottom One', ' Bottom Two', ' Bottom Three' ]);
565
601
// expect($rootScope.itemsTop).toEqualListContent(elementTop);
566
602
// expect($rootScope.itemsBottom).toEqualListContent(elementBottom);
567
603
568
604
// li1 = elementBottom.find(':eq(1)');
569
605
// li2 = elementTop.find(':eq(1)');
570
606
// dy = -EXTRA_DY_PERCENTAGE * li1.outerHeight() - (li1.position().top - li2.position().top);
571
607
// li1.simulate('drag', { dy: dy });
572
- // expect($rootScope.itemsTop).toEqual([" Top One", " Top Two", " Top Three" ]);
573
- // expect($rootScope.itemsBottom).toEqual([" Bottom One", " Bottom Two", " Bottom Three" ]);
608
+ // expect($rootScope.itemsTop).toEqual([' Top One', ' Top Two', ' Top Three' ]);
609
+ // expect($rootScope.itemsBottom).toEqual([' Bottom One', ' Bottom Two', ' Bottom Three' ]);
574
610
// expect($rootScope.itemsTop).toEqualListContent(elementTop);
575
611
// expect($rootScope.itemsBottom).toEqualListContent(elementBottom);
576
612
577
613
// li1 = elementTop.find(':eq(0)');
578
614
// li2 = elementBottom.find(':eq(0)');
579
615
// dy = EXTRA_DY_PERCENTAGE * li1.outerHeight() + (li2.position().top - li1.position().top);
580
616
// li1.simulate('drag', { dy: dy });
581
- // expect($rootScope.itemsTop).toEqual([" Top Two", " Top Three" ]);
582
- // expect($rootScope.itemsBottom).toEqual([" Bottom One", " Top One", " Bottom Two", " Bottom Three" ]);
617
+ // expect($rootScope.itemsTop).toEqual([' Top Two', ' Top Three' ]);
618
+ // expect($rootScope.itemsBottom).toEqual([' Bottom One', ' Top One', ' Bottom Two', ' Bottom Three' ]);
583
619
// expect($rootScope.itemsTop).toEqualListContent(elementTop);
584
620
// expect($rootScope.itemsBottom).toEqualListContent(elementBottom);
585
621
586
622
// li1 = elementBottom.find(':eq(1)');
587
623
// li2 = elementTop.find(':eq(1)');
588
624
// dy = -EXTRA_DY_PERCENTAGE * li1.outerHeight() - (li1.position().top - li2.position().top);
589
625
// li1.simulate('drag', { dy: dy });
590
- // expect($rootScope.itemsTop).toEqual([" Top Two", " Top One", " Top Three" ]);
591
- // expect($rootScope.itemsBottom).toEqual([" Bottom One", " Bottom Two", " Bottom Three" ]);
626
+ // expect($rootScope.itemsTop).toEqual([' Top Two', ' Top One', ' Top Three' ]);
627
+ // expect($rootScope.itemsBottom).toEqual([' Bottom One', ' Bottom Two', ' Bottom Three' ]);
592
628
// expect($rootScope.itemsTop).toEqualListContent(elementTop);
593
629
// expect($rootScope.itemsBottom).toEqualListContent(elementBottom);
594
630
0 commit comments