Repository navigation
Expand file tree
/
Copy pathmain.spec.js
More file actions
165 lines (150 loc) · 4.24 KB
/
Copy pathmain.spec.js
File metadata and controls
165 lines (150 loc) · 4.24 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
describe('main', function () {
var scope, $compile, element;
beforeEach(module('ui.tree'));
beforeEach(inject(function ($rootScope, _$compile_) {
scope = $rootScope;
$compile = _$compile_;
// TODO: move test element + data to a generic module so we can reuse it for other tests
element = angular.element('<div ui-tree="options">' +
'<ol ui-tree-nodes ng-model="list">' +
'<li ng-repeat="item in list" ui-tree-node="">' +
'<div ui-tree-handle>' +
'{{item.title}}' +
'</div>' +
'<ol ui-tree-nodes="" ng-model="item.items">' +
'<li ng-repeat="subItem in item.items" ui-tree-node="">' +
'<div ui-tree-handle>' +
'{{subItem.title}}' +
'</div>' +
'<ol ui-tree-nodes="" ng-model="subItem.items">' +
'<li ng-repeat="subItem1 in subItem.items" ui-tree-node="">' +
'<div ui-tree-handle>' +
'{{subItem1.title}}' +
'</div>' +
'</li>' +
'</ol>' +
'</li>' +
'</ol>' +
'</li>' +
'</ol>' +
'</div>');
scope.list = [
{
id: 1,
'title': 'item1',
'items': []
},
{
'id': 2,
'title': 'item2',
'items': [
{
'id': 21,
'title': 'item2.1',
'items': [
{
'id': 211,
'title': 'item2.1.1',
'items': []
},
{
'id': 212,
'title': 'item2.1.2',
'items': []
},
{
'id': 213,
'title': 'item2.1.3',
'items': []
}
]
},
{
'id': 22,
'title': 'item2.2',
'items': []
}
]
},
{
'id': 3,
'title': 'item3',
'items': [
{
'id': 31,
'title': 'item3.1',
'items': []
},
{
'id': 32,
'title': 'item3.2',
'items': []
},
{
'id': 33,
'title': 'item3.3',
'items': [
{
'id': 331,
'title': 'item3.3.1',
'items': []
},
{
'id': 332,
'title': 'item3.3.2',
'items': []
},
{
'id': 333,
'title': 'item3.3.3',
'items': []
}
]
}
]
},
{
'id': 4,
'title': 'item4',
'items': []
}
];
}));
function createTree() {
$compile(element)(scope);
scope.$digest();
return element;
}
it('should be created', function () {
var tree = createTree();
expect(tree.find('ol')).toExist();
});
// test if nodes and child nodes all are rendered
it('should show 15 nodes', function () {
var tree = createTree();
expect(tree.find('li').length).toEqual(15);
});
it('should show 4 root nodes', function () {
var tree = createTree();
expect(tree.children('ol').first().children('li').length).toEqual(4);
});
it('should show the first node with no child nodes', function () {
var tree = createTree();
expect(tree.children('li').first().children('li').length).toEqual(0);
});
it('should show the third node with 3 child nodes', function () {
var tree = createTree();
expect(tree.children('ol').first().children('li').eq(2).find('> ol').children('li').length).toEqual(3);
});
// test if the node text is shown
it('should show \'item1\' as text for the first node', function () {
var tree = createTree();
expect(tree.children('ol').first().children('li').first()).toHaveText('item1');
});
it('should show \'item2.1.2\' as text for the second child node of the first child node of node 2', function () {
var tree = createTree();
expect(tree.children('ol').first().children('li').eq(1).find('> ol').children('li').first().find('> ol').children('li').eq(1)).toHaveText('item2.1.2');
});
// TODO: simulate drag and drop events and check if the position of the nodes is still correct
// code to simulate d&d: https://github.com/jquery/jquery-ui/blob/master/tests/jquery.simulate.js
});