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

Commit 492bfa1

Browse files
committed
refactor(tests): move nested lists tests in separate file
1 parent 70e3b8e commit 492bfa1

File tree

2 files changed

+136
-104
lines changed

2 files changed

+136
-104
lines changed

test/sortable.e2e.multi.spec.js

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -450,110 +450,6 @@ describe('uiSortable', function() {
450450
});
451451
});
452452

453-
it('should update model when sorting between nested sortables', function() {
454-
inject(function($compile, $rootScope) {
455-
var elementTree, li1, li2, dy;
456-
457-
elementTree = $compile(''.concat(
458-
'<ul ui-sortable="sortableOptions" ng-model="items" class="apps-container outterList" style="float: left;margin-left: 10px;padding-bottom: 10px;">',
459-
'<li ng-repeat="item in items">',
460-
'<div>',
461-
'<span class="itemContent lvl1ItemContent">{{item.text}}</span>',
462-
'<ul ui-sortable="sortableOptions" ng-model="item.items" class="apps-container innerList" style="margin-left: 10px;padding-bottom: 10px;">',
463-
'<li ng-repeat="i in item.items">',
464-
'<span class="itemContent lvl2ItemContent">{{i.text}}</span>',
465-
'</li>',
466-
'</ul>',
467-
'</div>',
468-
'</li>',
469-
'</ul>',
470-
'<div style="clear: both;"></div>'))($rootScope);
471-
472-
$rootScope.$apply(function() {
473-
$rootScope.items = [
474-
{
475-
text: 'Item 1',
476-
items: []
477-
},
478-
{
479-
text: 'Item 2',
480-
items: [
481-
{ text: 'Item 2.1', items: [] },
482-
{ text: 'Item 2.2', items: [] }
483-
]
484-
}
485-
];
486-
487-
$rootScope.sortableOptions = {
488-
connectWith: '.apps-container'
489-
};
490-
});
491-
492-
host.append(elementTree);
493-
494-
// this should drag the item out of the list and
495-
// the item should return back to its original position
496-
li1 = elementTree.find('.innerList:last').find(':last');
497-
li1.simulate('drag', { dx: -200, moves: 30 });
498-
expect($rootScope.items.map(function(x){ return x.text; }))
499-
.toEqual(['Item 1', 'Item 2']);
500-
expect($rootScope.items.map(function(x){ return x.text; }))
501-
.toEqual(listInnerContent(elementTree, '.lvl1ItemContent'));
502-
expect($rootScope.items[0].items.map(function(x){ return x.text; }))
503-
.toEqual([]);
504-
expect($rootScope.items[0].items.map(function(x){ return x.text; }))
505-
.toEqual(listInnerContent(elementTree.find('.innerList:eq(0)'), '.lvl2ItemContent'));
506-
expect($rootScope.items[1].items.map(function(x){ return x.text; }))
507-
.toEqual(['Item 2.1', 'Item 2.2']);
508-
expect($rootScope.items[1].items.map(function(x){ return x.text; }))
509-
.toEqual(listInnerContent(elementTree.find('.innerList:eq(1)'), '.lvl2ItemContent'));
510-
511-
// this should drag the item from the inner list and
512-
// drop it to the outter list
513-
li1 = elementTree.find('.innerList:last').find(':last');
514-
li2 = elementTree.find('> li:last');
515-
dy = EXTRA_DY_PERCENTAGE * li1.outerHeight() + (li2.position().top - li1.position().top);
516-
li1.simulate('drag', { dy: dy });
517-
expect($rootScope.items.map(function(x){ return x.text; }))
518-
.toEqual(['Item 1', 'Item 2.2', 'Item 2']);
519-
expect($rootScope.items.map(function(x){ return x.text; }))
520-
.toEqual(listInnerContent(elementTree, '.lvl1ItemContent'));
521-
expect($rootScope.items[0].items.map(function(x){ return x.text; }))
522-
.toEqual([]);
523-
expect($rootScope.items[0].items.map(function(x){ return x.text; }))
524-
.toEqual(listInnerContent(elementTree.find('.innerList:eq(0)'), '.lvl2ItemContent'));
525-
expect($rootScope.items[1].items.map(function(x){ return x.text; }))
526-
.toEqual([]);
527-
expect($rootScope.items[1].items.map(function(x){ return x.text; }))
528-
.toEqual(listInnerContent(elementTree.find('.innerList:eq(1)'), '.lvl2ItemContent'));
529-
expect($rootScope.items[2].items.map(function(x){ return x.text; }))
530-
.toEqual(['Item 2.1']);
531-
expect($rootScope.items[2].items.map(function(x){ return x.text; }))
532-
.toEqual(listInnerContent(elementTree.find('.innerList:eq(2)'), '.lvl2ItemContent'));
533-
534-
// this should drag the item from the outter list and
535-
// drop it to the inner list
536-
li1 = elementTree.find('> li:first');
537-
li2 = elementTree.find('.innerList:last').find(':last');
538-
dy = -EXTRA_DY_PERCENTAGE * li1.outerHeight() + (li2.position().top - li1.position().top);
539-
li1.simulate('drag', { dy: dy });
540-
expect($rootScope.items.map(function(x){ return x.text; }))
541-
.toEqual(['Item 2.2', 'Item 2']);
542-
expect($rootScope.items.map(function(x){ return x.text; }))
543-
.toEqual(listInnerContent(elementTree, '.lvl1ItemContent'));
544-
expect($rootScope.items[0].items.map(function(x){ return x.text; }))
545-
.toEqual([]);
546-
expect($rootScope.items[0].items.map(function(x){ return x.text; }))
547-
.toEqual(listInnerContent(elementTree.find('.innerList:eq(0)'), '.lvl2ItemContent'));
548-
expect($rootScope.items[1].items.map(function(x){ return x.text; }))
549-
.toEqual(['Item 1', 'Item 2.1']);
550-
expect($rootScope.items[1].items.map(function(x){ return x.text; }))
551-
.toEqual(listInnerContent(elementTree.find('.innerList:eq(1)'), '.lvl2ItemContent'));
552-
553-
$(elementTree).remove();
554-
});
555-
});
556-
557453
it('should cancel sorting of nodes that contain "Two"', function() {
558454
inject(function($compile, $rootScope) {
559455
var elementTop, elementBottom;

test/sortable.e2e.nested.spec.js

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
'use strict';
2+
3+
describe('uiSortable', function() {
4+
5+
// Ensure the sortable angular module is loaded
6+
beforeEach(module('ui.sortable'));
7+
beforeEach(module('ui.sortable.testHelper'));
8+
9+
var EXTRA_DY_PERCENTAGE, listInnerContent;
10+
11+
beforeEach(inject(function (sortableTestHelper) {
12+
EXTRA_DY_PERCENTAGE = sortableTestHelper.EXTRA_DY_PERCENTAGE;
13+
listInnerContent = sortableTestHelper.listInnerContent;
14+
}));
15+
16+
describe('Nested sortables related', function() {
17+
18+
var host;
19+
20+
beforeEach(inject(function() {
21+
host = $('<div id="test-host"></div>');
22+
$('body').append(host);
23+
}));
24+
25+
afterEach(function() {
26+
host.remove();
27+
host = null;
28+
});
29+
30+
it('should update model when sorting between nested sortables', function() {
31+
inject(function($compile, $rootScope) {
32+
var elementTree, li1, li2, dy;
33+
34+
elementTree = $compile(''.concat(
35+
'<ul ui-sortable="sortableOptions" ng-model="items" class="apps-container outterList" style="float: left;margin-left: 10px;padding-bottom: 10px;">',
36+
'<li ng-repeat="item in items">',
37+
'<div>',
38+
'<span class="itemContent lvl1ItemContent">{{item.text}}</span>',
39+
'<ul ui-sortable="sortableOptions" ng-model="item.items" class="apps-container innerList" style="margin-left: 10px;padding-bottom: 10px;">',
40+
'<li ng-repeat="i in item.items">',
41+
'<span class="itemContent lvl2ItemContent">{{i.text}}</span>',
42+
'</li>',
43+
'</ul>',
44+
'</div>',
45+
'</li>',
46+
'</ul>',
47+
'<div style="clear: both;"></div>'))($rootScope);
48+
49+
$rootScope.$apply(function() {
50+
$rootScope.items = [
51+
{
52+
text: 'Item 1',
53+
items: []
54+
},
55+
{
56+
text: 'Item 2',
57+
items: [
58+
{ text: 'Item 2.1', items: [] },
59+
{ text: 'Item 2.2', items: [] }
60+
]
61+
}
62+
];
63+
64+
$rootScope.sortableOptions = {
65+
connectWith: '.apps-container'
66+
};
67+
});
68+
69+
host.append(elementTree);
70+
71+
// this should drag the item out of the list and
72+
// the item should return back to its original position
73+
li1 = elementTree.find('.innerList:last').find(':last');
74+
li1.simulate('drag', { dx: -200, moves: 30 });
75+
expect($rootScope.items.map(function(x){ return x.text; }))
76+
.toEqual(['Item 1', 'Item 2']);
77+
expect($rootScope.items.map(function(x){ return x.text; }))
78+
.toEqual(listInnerContent(elementTree, '.lvl1ItemContent'));
79+
expect($rootScope.items[0].items.map(function(x){ return x.text; }))
80+
.toEqual([]);
81+
expect($rootScope.items[0].items.map(function(x){ return x.text; }))
82+
.toEqual(listInnerContent(elementTree.find('.innerList:eq(0)'), '.lvl2ItemContent'));
83+
expect($rootScope.items[1].items.map(function(x){ return x.text; }))
84+
.toEqual(['Item 2.1', 'Item 2.2']);
85+
expect($rootScope.items[1].items.map(function(x){ return x.text; }))
86+
.toEqual(listInnerContent(elementTree.find('.innerList:eq(1)'), '.lvl2ItemContent'));
87+
88+
// this should drag the item from the inner list and
89+
// drop it to the outter list
90+
li1 = elementTree.find('.innerList:last').find(':last');
91+
li2 = elementTree.find('> li:last');
92+
dy = EXTRA_DY_PERCENTAGE * li1.outerHeight() + (li2.position().top - li1.position().top);
93+
li1.simulate('drag', { dy: dy });
94+
expect($rootScope.items.map(function(x){ return x.text; }))
95+
.toEqual(['Item 1', 'Item 2.2', 'Item 2']);
96+
expect($rootScope.items.map(function(x){ return x.text; }))
97+
.toEqual(listInnerContent(elementTree, '.lvl1ItemContent'));
98+
expect($rootScope.items[0].items.map(function(x){ return x.text; }))
99+
.toEqual([]);
100+
expect($rootScope.items[0].items.map(function(x){ return x.text; }))
101+
.toEqual(listInnerContent(elementTree.find('.innerList:eq(0)'), '.lvl2ItemContent'));
102+
expect($rootScope.items[1].items.map(function(x){ return x.text; }))
103+
.toEqual([]);
104+
expect($rootScope.items[1].items.map(function(x){ return x.text; }))
105+
.toEqual(listInnerContent(elementTree.find('.innerList:eq(1)'), '.lvl2ItemContent'));
106+
expect($rootScope.items[2].items.map(function(x){ return x.text; }))
107+
.toEqual(['Item 2.1']);
108+
expect($rootScope.items[2].items.map(function(x){ return x.text; }))
109+
.toEqual(listInnerContent(elementTree.find('.innerList:eq(2)'), '.lvl2ItemContent'));
110+
111+
// this should drag the item from the outter list and
112+
// drop it to the inner list
113+
li1 = elementTree.find('> li:first');
114+
li2 = elementTree.find('.innerList:last').find(':last');
115+
dy = -EXTRA_DY_PERCENTAGE * li1.outerHeight() + (li2.position().top - li1.position().top);
116+
li1.simulate('drag', { dy: dy });
117+
expect($rootScope.items.map(function(x){ return x.text; }))
118+
.toEqual(['Item 2.2', 'Item 2']);
119+
expect($rootScope.items.map(function(x){ return x.text; }))
120+
.toEqual(listInnerContent(elementTree, '.lvl1ItemContent'));
121+
expect($rootScope.items[0].items.map(function(x){ return x.text; }))
122+
.toEqual([]);
123+
expect($rootScope.items[0].items.map(function(x){ return x.text; }))
124+
.toEqual(listInnerContent(elementTree.find('.innerList:eq(0)'), '.lvl2ItemContent'));
125+
expect($rootScope.items[1].items.map(function(x){ return x.text; }))
126+
.toEqual(['Item 1', 'Item 2.1']);
127+
expect($rootScope.items[1].items.map(function(x){ return x.text; }))
128+
.toEqual(listInnerContent(elementTree.find('.innerList:eq(1)'), '.lvl2ItemContent'));
129+
130+
$(elementTree).remove();
131+
});
132+
});
133+
134+
});
135+
136+
});

0 commit comments

Comments
 (0)