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

Commit e29492b

Browse files
committed
test(sortable): add test for nested sortables where update is not firing
1 parent d4462d5 commit e29492b

File tree

2 files changed

+68
-3
lines changed

2 files changed

+68
-3
lines changed

test/sortable.e2e.multi.spec.js

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ describe('uiSortable', function() {
66
beforeEach(module('ui.sortable'));
77
beforeEach(module('ui.sortable.testHelper'));
88

9-
var EXTRA_DY_PERCENTAGE, listContent;
9+
var EXTRA_DY_PERCENTAGE, listContent, listInnerContent;
1010

1111
beforeEach(inject(function (sortableTestHelper) {
1212
EXTRA_DY_PERCENTAGE = sortableTestHelper.EXTRA_DY_PERCENTAGE;
1313
listContent = sortableTestHelper.listContent;
14+
listInnerContent = sortableTestHelper.listInnerContent;
1415
}));
1516

1617
describe('Multiple sortables related', function() {
@@ -346,6 +347,66 @@ describe('uiSortable', function() {
346347
});
347348
});
348349

350+
it('should update model when sorting between nested sortables', function() {
351+
inject(function($compile, $rootScope) {
352+
var elementTree;
353+
354+
elementTree = $compile(''.concat(
355+
'<ul ui-sortable="sortableOptions" ng-model="items" class="apps-container outterList" style="float: left;margin-left: 10px;padding-bottom: 10px;">',
356+
'<li ng-repeat="item in items track by $index">',
357+
'<div>',
358+
'<span class="itemContent lvl1ItemContent">{{item.text}}</span>',
359+
'<ul ui-sortable="sortableOptions" ng-model="item.items" class="apps-container innerList" style="float: left;margin-left: 10px;padding-bottom: 10px;">',
360+
'<li ng-repeat="i in item.items track by $index">',
361+
'<span class="itemContent lvl2ItemContent">{{i.text}}</span>',
362+
'</li>',
363+
'</ul>',
364+
'</div>',
365+
'</li>',
366+
'</ul>',
367+
'<div style="clear: both;"></div>'))($rootScope);
368+
369+
$rootScope.$apply(function() {
370+
$rootScope.items = [
371+
{
372+
text: 'Item 1',
373+
items: []
374+
},
375+
{
376+
text: 'Item 2',
377+
items: [
378+
{ text: 'Item 2.1' },
379+
{ text: 'Item 2.2' }
380+
]
381+
}
382+
];
383+
384+
$rootScope.sortableOptions = {
385+
connectWith: '.apps-container'
386+
};
387+
});
388+
389+
host.append(elementTree);
390+
391+
var li = elementTree.find('.innerList:last').find(':last');
392+
li.simulate('drag', { dx: -200, moves: 30 });
393+
expect($rootScope.items.map(function(x){ return x.text; }))
394+
.toEqual(['Item 1', 'Item 2']);
395+
expect($rootScope.items.map(function(x){ return x.text; }))
396+
.toEqual(listInnerContent(elementTree, '.lvl1ItemContent'));
397+
expect($rootScope.items[0].items.map(function(x){ return x.text; }))
398+
.toEqual([]);
399+
expect($rootScope.items[0].items.map(function(x){ return x.text; }))
400+
.toEqual(listInnerContent(elementTree.find('.innerList:eq(0)'), '.lvl2ItemContent'));
401+
expect($rootScope.items[1].items.map(function(x){ return x.text; }))
402+
.toEqual(['Item 2.1', 'Item 2.2']);
403+
expect($rootScope.items[1].items.map(function(x){ return x.text; }))
404+
.toEqual(listInnerContent(elementTree.find('.innerList:eq(1)'), '.lvl2ItemContent'));
405+
406+
$(elementTree).remove();
407+
});
408+
});
409+
349410
});
350411

351412
});

test/sortable.test-helper.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ angular.module('ui.sortable.testHelper', [])
1111
return [];
1212
}
1313

14-
function listInnerContent (list) {
14+
function listInnerContent (list, contentSelector) {
15+
if (!contentSelector) {
16+
contentSelector = '.itemContent';
17+
}
18+
1519
if (list && list.length) {
16-
return list.children().map(function(){ return $(this).find('.itemContent').html(); }).toArray();
20+
return list.children().map(function(){ return $(this).find(contentSelector).html(); }).toArray();
1721
}
1822
return [];
1923
}

0 commit comments

Comments
 (0)