8000 test(sortable): add lazy init tests using $timeout · angular-ui/ui-sortable@a103b25 · GitHub
[go: up one dir, main page]

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

Commit a103b25

Browse files
committed
test(sortable): add lazy init tests using $timeout
1 parent 93dde15 commit a103b25

File tree

1 file changed

+71
-2
lines changed

1 file changed

+71
-2
lines changed

test/sortable.spec.js

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ describe('uiSortable', function() {
319319
});
320320

321321
it('should lazily initialize a latelly enabled sortable (set disabled = false)', function() {
322-
inject(function($compile, $rootScope) {
322+
inject(function($compile, $rootScope, $timeout) {
323323
var element;
324324
var childScope = $rootScope.$new();
325325
spyOn(angular.element.fn, 'sortable');
@@ -336,12 +336,45 @@ describe('uiSortable', function() {
336336
childScope.opts.disabled = false;
337337
});
338338

339+
expect(function() {
340+
$timeout.flush();
341+
}).not.toThrow();
342+
339343
expect(angular.element.fn.sortable).toHaveBeenCalled();
340344
});
341345
});
342346

347+
it('should lazily initialize a sortable enabled in $timeout (set disabled = false)', function() {
348+
inject(function($compile, $rootScope, $timeout) {
349+
var element;
350+
var childScope = $rootScope.$new();
351+
spyOn(angular.element.fn, 'sortable');
352+
353+
childScope.items = ['One', 'Two', 'Three'];
354+
childScope.opts = {
355+
disabled: true
356+
};
357+
element = $compile('<ul ui-sortable="opts" ng-model="items"><li ng-repeat="item in items">{{ item }}</li></ul>')(childScope);
358+
359+
expect(angular.element.fn.sortable).not.toHaveBeenCalled();
360+
361+
$timeout(function () {
362+
childScope.opts.disabled = false;
363+
});
364+
365+
$timeout(function () {
366+
expect(angular.element.fn.sortable).toHaveBeenCalled();
367+
});
368+
369+
expect(function() {
370+
$timeout.flush();
371+
}).not.toThrow();
372+
373+
});
374+
});
375+
343376
it('should lazily initialize a latelly enabled sortable (delete disabled option)', function() {
344-
inject(function($compile, $rootScope) {
377+
inject(function($compile, $rootScope, $timeout) {
345378
var element;
346379
var childScope = $rootScope.$new();
347380
spyOn(angular.element.fn, 'sortable');
@@ -358,10 +391,46 @@ describe('uiSortable', function() {
358391
childScope.opts = {};
359392
});
360393

394+
expect(function() {
395+
$timeout.flush();
396+
}).not.toThrow();
397+
361398
expect(angular.element.fn.sortable).toHaveBeenCalled();
362399
});
363400
});
364401

402+
it('should lazily initialize a sortable enabled in $timeout (delete disabled option)', function() {
403+
inject(function($compile, $rootScope, $timeout) {
404+
var element;
405+
var childScope = $rootScope.$new();
406+
spyOn(angular.element.fn, 'sortable');
407+
408+
childScope.items = ['One', 'Two', 'Three'];
409+
childScope.opts = {
410+
disabled: true
411+
};
412+
element = $compile('<ul ui-sortable="opts" ng-model="items"><li ng-repeat="item in items">{{ item }}</li></ul>')(childScope);
413+
414+
expect(angular.element.fn.sortable).not.toHaveBeenCalled();
415+
416+
expect(function() {
417+
$timeout.flush();
418+
}).not.toThrow();
419+
420+
$timeout(function () {
421+
childScope.opts = {};
422+
});
423+
424+
$timeout(function () {
425+
expect(angular.element.fn.sortable).toHaveBeenCalled();
426+
});
427+
428+
expect(function() {
429+
$timeout.flush();
430+
}).not.toThrow();
431+
432+
});
433+
});
365434

366435
});
367436

0 commit comments

Comments
 (0)
0