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

Commit 54d442c

Browse files
committed
refactor(sortable): move connected lists cancel() test
1 parent fcb6629 commit 54d442c

File tree

2 files changed

+63
-63
lines changed

2 files changed

+63
-63
lines changed

test/sortable.e2e.callbacks.spec.js

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -105,69 +105,6 @@ describe('uiSortable', function() {
105105
});
106106
});
107107

108-
it('should cancel sorting of nodes that contain "Two"', function() {
109-
inject(function($compile, $rootScope) {
110-
var elementTop, elementBottom;
111-
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);
112-
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);
113-
$rootScope.$apply(function() {
114-
$rootScope.itemsTop = ['Top One', 'Top Two', 'Top Three'];
115-
$rootScope.itemsBottom = ['Bottom One', 'Bottom Two', 'Bottom Three'];
116-
$rootScope.opts = {
117-
connectWith: '.cross-sortable',
118-
update: function(e, ui) {
119-
if (ui.item.scope() &&
120-
(typeof ui.item.scope().item === 'string') &&
121-
ui.item.scope().item.indexOf('Two') >= 0) {
122-
ui.item.sortable.cancel();
123-
}
124-
}
125-
};
126-
});
127-
128-
host.append(elementTop).append(elementBottom);
129-
130-
var li1 = elementTop.find(':eq(1)');
131-
var li2 = elementBottom.find(':eq(0)');
132-
var dy = EXTRA_DY_PERCENTAGE * li1.outerHeight() + (li2.position().top - li1.position().top);
133-
li1.simulate('drag', { dy: dy });
134-
expect($rootScope.itemsTop).toEqual(['Top One', 'Top Two', 'Top Three']);
135-
expect($rootScope.itemsBottom).toEqual(['Bottom One', 'Bottom Two', 'Bottom Three']);
136-
expect($rootScope.itemsTop).toEqual(listContent(elementTop));
137-
expect($rootScope.itemsBottom).toEqual(listContent(elementBottom));
138-
139-
li1 = elementBottom.find(':eq(1)');
140-
li2 = elementTop.find(':eq(1)');
141-
dy = -EXTRA_DY_PERCENTAGE * li1.outerHeight() - (li1.position().top - li2.position().top);
142-
li1.simulate('drag', { dy: dy });
143-
expect($rootScope.itemsTop).toEqual(['Top One', 'Top Two', 'Top Three']);
144-
expect($rootScope.itemsBottom).toEqual(['Bottom One', 'Bottom Two', 'Bottom Three']);
145-
expect($rootScope.itemsTop).toEqual(listContent(elementTop));
146-
expect($rootScope.itemsBottom).toEqual(listContent(elementBottom));
147-
148-
li1 = elementTop.find(':eq(0)');
149-
li2 = elementBottom.find(':eq(0)');
150-
dy = EXTRA_DY_PERCENTAGE * li1.outerHeight() + (li2.position().top - li1.position().top);
151-
li1.simulate('drag', { dy: dy });
152-
expect($rootScope.itemsTop).toEqual(['Top Two', 'Top Three']);
153-
expect($rootScope.itemsBottom).toEqual(['Bottom One', 'Top One', 'Bottom Two', 'Bottom Three']);
154-
expect($rootScope.itemsTop).toEqual(listContent(elementTop));
155-
expect($rootScope.itemsBottom).toEqual(listContent(elementBottom));
156-
157-
li1 = elementBottom.find(':eq(1)');
158-
li2 = elementTop.find(':eq(1)');
159-
dy = -EXTRA_DY_PERCENTAGE * li1.outerHeight() - (li1.position().top - li2.position().top);
160-
li1.simulate('drag', { dy: dy });
161-
expect($rootScope.itemsTop).toEqual(['Top Two', 'Top One', 'Top Three']);
162-
expect($rootScope.itemsBottom).toEqual(['Bottom One', 'Bottom Two', 'Bottom Three']);
163-
expect($rootScope.itemsTop).toEqual(listContent(elementTop));
164-
expect($rootScope.itemsBottom).toEqual(listContent(elementBottom));
165-
166-
$(elementTop).remove();
167-
$(elementBottom).remove();
168-
});
169-
});
170-
171108
it('should update model from update() callback', function() {
172109
inject(function($compile, $rootScope) {
173110
var element, logsElement;

test/sortable.e2e.multi.spec.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,69 @@ describe('uiSortable', function() {
534534
});
535535
});
536536

537+
it('should cancel sorting of nodes that contain "Two"', function() {
538+
inject(function($compile, $rootScope) {
539+
var elementTop, elementBottom;
540+
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+
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+
$rootScope.$apply(function() {
543+
$rootScope.itemsTop = ['Top One', 'Top Two', 'Top Three'];
544+
$rootScope.itemsBottom = ['Bottom One', 'Bottom Two', 'Bottom Three'];
545+
$rootScope.opts = {
546+
connectWith: '.cross-sortable',
547+
update: function(e, ui) {
548+
if (ui.item.scope() &&
549+
(typeof ui.item.scope().item === 'string') &&
550+
ui.item.scope().item.indexOf('Two') >= 0) {
551+
ui.item.sortable.cancel();
552+
}
553+
}
554+
};
555+
});
556+
557+
host.append(elementTop).append(elementBottom);
558+
559+
var li1 = elementTop.find(':eq(1)');
560+
var li2 = elementBottom.find(':eq(0)');
561+
var dy = EXTRA_DY_PERCENTAGE * li1.outerHeight() + (li2.position().top - li1.position().top);
562+
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']);
565+
expect($rootScope.itemsTop).toEqual(listContent(elementTop));
566+
expect($rootScope.itemsBottom).toEqual(listContent(elementBottom));
567+
568+
li1 = elementBottom.find(':eq(1)');
569+
li2 = elementTop.find(':eq(1)');
570+
dy = -EXTRA_DY_PERCENTAGE * li1.outerHeight() - (li1.position().top - li2.position().top);
571+
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']);
574+
expect($rootScope.itemsTop).toEqual(listContent(elementTop));
575+
expect($rootScope.itemsBottom).toEqual(listContent(elementBottom));
576+
577+
li1 = elementTop.find(':eq(0)');
578+
li2 = elementBottom.find(':eq(0)');
579+
dy = EXTRA_DY_PERCENTAGE * li1.outerHeight() + (li2.position().top - li1.position().top);
580+
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']);
583+
expect($rootScope.itemsTop).toEqual(listContent(elementTop));
584+
expect($rootScope.itemsBottom).toEqual(listContent(elementBottom));
585+
586+
li1 = elementBottom.find(':eq(1)');
587+
li2 = elementTop.find(':eq(1)');
588+
dy = -EXTRA_DY_PERCENTAGE * li1.outerHeight() - (li1.position().top - li2.position().top);
589+
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']);
592+
expect($rootScope.itemsTop).toEqual(listContent(elementTop));
593+
expect($rootScope.itemsBottom).toEqual(listContent(elementBottom));
594+
595+
$(elementTop).remove();
596+
$(elementBottom).remove();
597+
});
598+
});
599+
537600
});
538601

539602
});

0 commit comments

Comments
 (0)