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

Commit 7c75125

Browse files
committed
test: add data-* anotation tests
1 parent 11a3fd2 commit 7c75125

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

test/sortable.spec.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,25 @@ describe('uiSortable', function() {
7777
});
7878
});
7979

80+
it('should refresh sortable properly after an apply [data-* anotation]', function() {
81+
inject(function($compile, $rootScope, $timeout) {
82+
var element;
83+
var childScope = $rootScope.$new();
84+
element = $compile('<ul data-ui-sortable="opts" data-ng-model="items"><li ng-repeat="item in items">{{ item }}</li></ul>')(childScope);
85+
$rootScope.$apply(function() {
86+
childScope.items = ['One', 'Two', 'Three'];
87+
childScope.opts = {};
88+
});
89+
90+
expect(function() {
91+
$timeout.flush();
92+
}).not.toThrow();
93+
94+
expect(childScope.items).toEqual(['One', 'Two', 'Three']);
95+
expect(childScope.items).toEqual(listContent(element));
96+
});
97+
});
98+
8099
it('should not refresh sortable if destroyed', function() {
81100
inject(function($compile, $rootScope, $timeout) {
82101
var element;
@@ -94,6 +113,24 @@ describe('uiSortable', function() {
94113
});
95114
});
96115

116+
it('should not refresh sortable if destroyed [data-* anotation]', function() {
117+
inject(function($compile, $rootScope, $timeout) {
118+
var element;
119+
var childScope = $rootScope.$new();
120+
element = $compile('<div><ul data-ui-sortable="opts" data-ng-model="items"><li ng-repeat="item in items">{{ item }}</li></ul></div>')(childScope);
121+
$rootScope.$apply(function() {
122+
childScope.items = ['One', 'Two', 'Three'];
123+
childScope.opts = {};
124+
});
125+
126+
element.remove(element.firstChild);
127+
expect(function() {
128+
$timeout.flush();
129+
}).not.toThrow();
130+
131+
});
132+
});
133+
97134
it('should not try to apply options to a destroyed sortable', function() {
98135
inject(function($compile, $rootScope, $timeout) {
99136
var element;
@@ -115,6 +152,27 @@ describe('uiSortable', function() {
115152
});
116153
});
117154

155+
it('should not try to apply options to a destroyed sortable [data-* anotation]', function() {
156+
inject(function($compile, $rootScope, $timeout) {
157+
var element;
158+
var childScope = $rootScope.$new();
159+
element = $compile('<div><ul data-ui-sortable="opts" data-ng-model="items"><li ng-repeat="item in items">{{ item }}</li></ul></div>')(childScope);
160+
$rootScope.$apply(function() {
161+
childScope.items = ['One', 'Two', 'Three'];
162+
childScope.opts = {
163+
update: function() {}
164+
};
165+
166+
element.remove(element.firstChild);
167+
});
168+
169+
expect(function() {
170+
$timeout.flush();
171+
}).not.toThrow();
172+
173+
});
174+
});
175+
118176
});
119177

120178
});

0 commit comments

Comments
 (0)