forked from angular-ui/ui-sortable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsortable.spec.js
72 lines (57 loc) · 2.23 KB
/
sortable.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'use strict';
describe('uiSortable', function() {
// Ensure the sortable angular module is loaded
beforeEach(module('ui.sortable'));
describe('Simple use', function() {
it('should have a ui-sortable class', function() {
inject(function($compile, $rootScope) {
var element;
element = $compile('<ul ui-sortable></ul>')($rootScope);
expect(element.hasClass('ui-sortable')).toBeTruthy();
});
});
it('should log that ngModel was not provided', function() {
inject(function($compile, $rootScope, $log) {
var element;
element = $compile('<ul ui-sortable><li ng-repeat="item in items" id="s-{{$index}}">{{ item }}</li></ul>')($rootScope);
$rootScope.$apply(function() {
$rootScope.items = ['One', 'Two', 'Three'];
});
expect($log.info.logs.length).toEqual(1);
expect($log.info.logs[0].length).toEqual(2);
expect($log.info.logs[0][0]).toEqual('ui.sortable: ngModel not provided!');
});
});
it('should not refresh sortable if destroyed', function() {
inject(function($compile, $rootScope, $timeout) {
var element;
var childScope = $rootScope.$new();
element = $compile('<div><ul ui-sortable ng-model="items"><li ng-repeat="item in items">{{ item }}</li></ul></div>')(childScope);
$rootScope.$apply(function() {
childScope.items = ['One', 'Two', 'Three'];
});
element.remove(element.firstChild);
expect(function() {
$timeout.flush();
}).not.toThrow();
});
});
it('should not try to apply options to a destroyed sortable', function() {
inject(function($compile, $rootScope, $timeout) {
var element;
var childScope = $rootScope.$new();
element = $compile('<div><ul ui-sortable="opts" ng-model="items"><li ng-repeat="item in items">{{ item }}</li></ul></div>')(childScope);
$rootScope.$apply(function() {
childScope.items = ['One', 'Two', 'Three'];
childScope.opts = {
update: function() {}
};
element.remove(element.firstChild);
});
expect(function() {
$timeout.flush();
}).not.toThrow();
});
});
});
});