Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit f4a320d

Browse files
committed
test(sortable): add test for connected sortables that use data-ng-model
1 parent e20710b commit f4a320d

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

test/sortable.e2e.multi.spec.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,82 @@ describe('uiSortable', function() {
610610
});
611611
});
612612

613+
it('should properly set ui.item.sortable.droptargetModel when using data-ng-model', function() {
614+
inject(function($compile, $rootScope) {
615+
var elementTop, elementBottom, updateCallbackExpectations;
616+
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);
617+
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);
618+
$rootScope.$apply(function() {
619+
$rootScope.itemsTop = ['Top One', 'Top Two', 'Top Three'];
620+
$rootScope.itemsBottom = ['Bottom One', 'Bottom Two', 'Bottom Three'];
621+
$rootScope.opts = {
622+
connectWith: '.cross-sortable',
623+
update: function(e, ui) {
624+
if (ui.item.scope() &&
625+
(typeof ui.item.scope().item === 'string') &&
626+
ui.item.scope().item.indexOf('Two') >= 0) {
627+
ui.item.sortable.cancel();
628+
}
629+
updateCallbackExpectations(ui.item.sortable);
630+
}
631+
};
632+
});
633+
634+
host.append(elementTop).append(elementBottom).append('<div class="clear"></div>');
635+
636+
var li1 = elementTop.find(':eq(1)');
637+
var li2 = elementBottom.find(':eq(0)');
638+
updateCallbackExpectations = function(uiItemSortable) {
639+
expect(uiItemSortable.droptargetModel).toBe($rootScope.itemsBottom);
640+
};
641+
simulateElementDrag(li1, li2, { place: 'below', extradx: -20, extrady: -10 });
642+
expect($rootScope.itemsTop).toEqual(['Top One', 'Top Two', 'Top Three']);
643+
expect($rootScope.itemsBottom).toEqual(['Bottom One', 'Bottom Two', 'Bottom Three']);
644+
expect($rootScope.itemsTop).toEqual(listContent(elementTop));
645+
expect($rootScope.itemsBottom).toEqual(listContent(elementBottom));
646+
updateCallbackExpectations = undefined;
647+
648+
li1 = elementBottom.find(':eq(1)');
649+
li2 = elementTop.find(':eq(1)');
650+
updateCallbackExpectations = function(uiItemSortable) {
651+
expect(uiItemSortable.droptargetModel).toBe($rootScope.itemsTop);
652+
};
653+
simulateElementDrag(li1, li2, { place: 'above', extradx: -20, extrady: -10 });
654+
expect($rootScope.itemsTop).toEqual(['Top One', 'Top Two', 'Top Three']);
655+
expect($rootScope.itemsBottom).toEqual(['Bottom One', 'Bottom Two', 'Bottom Three']);
656+
expect($rootScope.itemsTop).toEqual(listContent(elementTop));
657+
expect($rootScope.itemsBottom).toEqual(listContent(elementBottom));
658+
updateCallbackExpectations = undefined;
659+
660+
li1 = elementTop.find(':eq(0)');
661+
li2 = elementBottom.find(':eq(0)');
662+
updateCallbackExpectations = function(uiItemSortable) {
663+
expect(uiItemSortable.droptargetModel).toBe($rootScope.itemsBottom);
664+
};
665+
simulateElementDrag(li1, li2, 'below');
666+
expect($rootScope.itemsTop).toEqual(['Top Two', 'Top Three']);
667+
expect($rootScope.itemsBottom).toEqual(['Bottom One', 'Top One', 'Bottom Two', 'Bottom Three']);
668+
expect($rootScope.itemsTop).toEqual(listContent(elementTop));
669+
expect($rootScope.itemsBottom).toEqual(listContent(elementBottom));
670+
updateCallbackExpectations = undefined;
671+
672+
li1 = elementBottom.find(':eq(1)');
673+
li2 = elementTop.find(':eq(1)');
674+
updateCallbackExpectations = function(uiItemSortable) {
675+
expect(uiItemSortable.droptargetModel).toBe($rootScope.itemsTop);
676+
};
677+
simulateElementDrag(li1, li2, { place: 'above', extradx: -20, extrady: -10 });
678+
expect($rootScope.itemsTop).toEqual(['Top Two', 'Top One', 'Top Three']);
679+
expect($rootScope.itemsBottom).toEqual(['Bottom One', 'Bottom Two', 'Bottom Three']);
680+
expect($rootScope.itemsTop).toEqual(listContent(elementTop));
681+
expect($rootScope.itemsBottom).toEqual(listContent(elementBottom));
682+
updateCallbackExpectations = undefined;
683+
684+
$(elementTop).remove();
685+
$(elementBottom).remove();
686+
});
687+
});
688+
613689
it('should properly free ui.item.sortable object', function() {
614690
inject(function($compile, $rootScope) {
615691
var elementTop, elementBottom, uiItem, uiItemSortable_Destroy;

0 commit comments

Comments
 (0)