Skip to content

Commit 76114a1

Browse files
committed
Added tests for connected lists when 'helper: clone' option is used.
1 parent e903912 commit 76114a1

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

test/sortable.spec.js

+79
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,85 @@ describe('uiSortable', function() {
636636
});
637637
});
638638

639+
it('should work when "helper: clone" option is used', function() {
640+
inject(function($compile, $rootScope) {
641+
var elementTop, elementBottom;
642+
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);
643+
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);
644+
$rootScope.$apply(function() {
645+
$rootScope.itemsTop = ['Top One', 'Top Two', 'Top Three'];
646+
$rootScope.itemsBottom = ['Bottom One', 'Bottom Two', 'Bottom Three'];
647+
$rootScope.opts = {
648+
helper: 'clone',
649+
connectWith: '.cross-sortable'
650+
};
651+
});
652+
653+
host.append(elementTop).append(elementBottom);
654+
655+
var li1 = elementTop.find(':eq(0)');
656+
var li2 = elementBottom.find(':eq(0)');
657+
var dy = EXTRA_DY_PERCENTAGE * li1.outerHeight() + (li2.position().top - li1.position().top);
658+
li1.simulate('drag', { dy: dy });
659+
expect($rootScope.itemsTop).toEqual(['Top Two', 'Top Three']);
660+
expect($rootScope.itemsBottom).toEqual(['Bottom One', 'Top One', 'Bottom Two', 'Bottom Three']);
661+
expect($rootScope.itemsTop).toEqual(listContent(elementTop));
662+
expect($rootScope.itemsBottom).toEqual(listContent(elementBottom));
663+
664+
li1 = elementBottom.find(':eq(1)');
665+
li2 = elementTop.find(':eq(1)');
666+
dy = -EXTRA_DY_PERCENTAGE * li1.outerHeight() - (li1.position().top - li2.position().top);
667+
li1.simulate('drag', { dy: dy });
668+
expect($rootScope.itemsTop).toEqual(['Top Two', 'Top One', 'Top Three']);
669+
expect($rootScope.itemsBottom).toEqual(['Bottom One', 'Bottom Two', 'Bottom Three']);
670+
expect($rootScope.itemsTop).toEqual(listContent(elementTop));
671+
expect($rootScope.itemsBottom).toEqual(listContent(elementBottom));
672+
673+
$(elementTop).remove();
674+
$(elementBottom).remove();
675+
});
676+
});
677+
678+
it('should work when "placeholder" and "helper: clone" options are used', function() {
679+
inject(function($compile, $rootScope) {
680+
var elementTop, elementBottom;
681+
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);
682+
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);
683+
$rootScope.$apply(function() {
684+
$rootScope.itemsTop = ['Top One', 'Top Two', 'Top Three'];
685+
$rootScope.itemsBottom = ['Bottom One', 'Bottom Two', 'Bottom Three'];
686+
$rootScope.opts = {
687+
helper: 'clone',
688+
placeholder: 'sortable-item-placeholder',
689+
connectWith: '.cross-sortable'
690+
};
691+
});
692+
693+
host.append(elementTop).append(elementBottom);
694+
695+
var li1 = elementTop.find(':eq(0)');
696+
var li2 = elementBottom.find(':eq(0)');
697+
var dy = EXTRA_DY_PERCENTAGE * li1.outerHeight() + (li2.position().top - li1.position().top);
698+
li1.simulate('drag', { dy: dy });
699+
expect($rootScope.itemsTop).toEqual(['Top Two', 'Top Three']);
700+
expect($rootScope.itemsBottom).toEqual(['Bottom One', 'Top One', 'Bottom Two', 'Bottom Three']);
701+
expect($rootScope.itemsTop).toEqual(listContent(elementTop));
702+
expect($rootScope.itemsBottom).toEqual(listContent(elementBottom));
703+
704+
li1 = elementBottom.find(':eq(1)');
705+
li2 = elementTop.find(':eq(1)');
706+
dy = -EXTRA_DY_PERCENTAGE * li1.outerHeight() - (li1.position().top - li2.position().top);
707+
li1.simulate('drag', { dy: dy });
708+
expect($rootScope.itemsTop).toEqual(['Top Two', 'Top One', 'Top Three']);
709+
expect($rootScope.itemsBottom).toEqual(['Bottom One', 'Bottom Two', 'Bottom Three']);
710+
expect($rootScope.itemsTop).toEqual(listContent(elementTop));
711+
expect($rootScope.itemsBottom).toEqual(listContent(elementBottom));
712+
713+
$(elementTop).remove();
714+
$(elementBottom).remove();
715+
});
716+
});
717+
639718
});
640719

641720

0 commit comments

Comments
 (0)