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

Commit 2905b5d

Browse files
committed
test(sortable): test that deleted options are restored to their default values
1 parent 97c8ad3 commit 2905b5d

File tree

3 files changed

+135
-1
lines changed

3 files changed

+135
-1
lines changed

test/sortable.e2e.callbacks.spec.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,61 @@ describe('uiSortable', function() {
457457
});
458458
});
459459

460+
it('should properly reset a deleted callback option', function() {
461+
inject(function($compile, $rootScope) {
462+
var element, logsElement;
463+
element = $compile(''.concat(
464+
'<ul ui-sortable="opts" ng-model="items">',
465+
beforeLiElement,
466+
'<li ng-repeat="item in items" id="s-{{$index}}">{{ item }}</li>',
467+
afterLiElement +
468+
'</ul>'))($rootScope);
469+
logsElement = $compile(''.concat(
470+
'<ul ng-model="logs">',
471+
beforeLiElement,
472+
'<li ng-repeat="log in logs" id="l-{{$index}}">{{ log }}</li>',
473+
afterLiElement +
474+
'</ul>'))($rootScope);
475+
$rootScope.$apply(function() {
476+
$rootScope.opts = {
477+
stop: function(e, ui) {
478+
$rootScope.logs.push('Moved element ' + ui.item.sortable.model);
479+
}
480+
};
481+
$rootScope.items = ['One', 'Two', 'Three'];
482+
$rootScope.logs = [];
483+
});
484+
485+
host.append(element).append(logsElement);
486+
487+
var li = element.find('[ng-repeat]:eq(1)');
488+
var dy = (1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
489+
li.simulate('drag', { dy: dy });
490+
expect($rootScope.items).toEqual(['One', 'Three', 'Two']);
491+
expect($rootScope.logs).toEqual(['Moved element Two']);
492+
expect($rootScope.items).toEqual(listContent(element));
493+
expect($rootScope.logs).toEqual(listContent(logsElement));
494+
495+
$rootScope.$digest();
496+
497+
$rootScope.$apply(function() {
498+
$rootScope.opts = {};
499+
});
500+
501+
li = element.find('[ng-repeat]:eq(0)');
502+
dy = (1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
503+
li.simulate('drag', { dy: dy });
504+
expect($rootScope.items).toEqual(['Three', 'One', 'Two']);
505+
expect($rootScope.items).toEqual(listContent(element));
506+
// the log should be the same
507+
expect($rootScope.logs).toEqual(['Moved element Two']);
508+
expect($rootScope.logs).toEqual(listContent(logsElement));
509+
510+
$(element).remove();
511+
$(logsElement).remove();
512+
});
513+
});
514+
460515
}
461516

462517
[0, 1].forEach(function(useExtraElements){

test/sortable.e2e.directiveoptions.spec.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,46 @@ describe('uiSortable', function() {
200200
});
201201
});
202202

203+
it('should properly reset deleted directive options', function() {
204+
inject(function($compile, $rootScope) {
205+
var element, logsElement;
206+
element = $compile(''.concat(
207+
'<ul ui-sortable="opts" ng-model="items">',
208+
beforeLiElement,
209+
'<li ng-repeat="item in items" id="s-{{$index}}">{{ item }}</li>',
210+
afterLiElement +
211+
'</ul>'))($rootScope);
212+
$rootScope.$apply(function() {
213+
$rootScope.opts = {
214+
'ui-floating': true
215+
};
216+
$rootScope.items = ['One', 'Two', 'Three'];
217+
});
218+
219+
host.append(element).append(logsElement);
220+
221+
var sortableWidgetInstance = element.data('ui-sortable');
222+
223+
expect(sortableWidgetInstance.floating).toBe(true);
224+
225+
$rootScope.$digest();
226+
227+
$rootScope.$apply(function() {
228+
$rootScope.opts = {};
229+
});
230+
231+
var li = element.find('[ng-repeat]:eq(1)');
232+
var dy = (1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
233+
li.simulate('drag', { dy: dy });
234+
expect($rootScope.items).toEqual(['One', 'Three', 'Two']);
235+
expect($rootScope.items).toEqual(listContent(element));
236+
expect(sortableWidgetInstance.floating).toBe(false);
237+
238+
$(element).remove();
239+
$(logsElement).remove();
240+
});
241+
});
242+
203243
}
204244

205245
[0, 1].forEach(function(useExtraElements){

test/sortable.spec.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,16 +256,55 @@ describe('uiSortable', function() {
256256

257257
});
258258

259+
it('should properly reset the value of a deleted option', function() {
259260

261+
inject(function($compile, $rootScope, $timeout) {
262+
var element;
263+
var childScope = $rootScope.$new();
264+
childScope.opts = {
265+
opacity: 0.7,
266+
placeholder: 'phClass',
267+
update: function() { }
268+
};
260269

270+
element = $compile('<div><ul data-ui-sortable="opts" data-ng-model="items"></ul></div>')(childScope);
271+
var $sortableElement = element.find('[data-ui-sortable]');
261272

273+
expect($sortableElement.sortable('option', 'opacity')).toBe(0.7);
274+
expect($sortableElement.sortable('option', 'placeholder')).toBe('phClass');
275+
expect(typeof $sortableElement.sortable('option', 'update')).toBe('function');
262276

277+
$rootScope.$digest();
263278

279+
$rootScope.$apply(function() {
280+
delete childScope.opts.opacity;
281+
});
264282

265-
});
283+
expect($sortableElement.sortable('option', 'opacity')).toBe(false);
284+
expect($sortableElement.sortable('option', 'placeholder')).toBe('phClass');
285+
expect(typeof $sortableElement.sortable('option', 'update')).toBe('function');
266286

287+
$rootScope.$digest();
267288

289+
$rootScope.$apply(function() {
290+
childScope.opts = {};
291+
});
268292

293+
expect($sortableElement.sortable('option', 'opacity')).toBe(false);
294+
expect($sortableElement.sortable('option', 'placeholder')).toBe(false);
295+
expect(typeof $sortableElement.sortable('option', 'update')).toBe('function');
296+
297+
element.remove(element.firstChild);
298+
299+
expect(function() {
300+
$timeout.flush();
301+
}).not.toThrow();
302+
303+
});
304+
305+
});
306+
307+
});
269308

270309

271310
});

0 commit comments

Comments
 (0)