Skip to content

Commit 90f87ea

Browse files
committed
Renamed nodeCtrl test tree items to match array index positions (ease of testing)
Added additional tests for maxSubDepth()
1 parent 3d27f28 commit 90f87ea

File tree

1 file changed

+57
-47
lines changed

1 file changed

+57
-47
lines changed

source/controllers/nodeCtrl.spec.js

Lines changed: 57 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -46,129 +46,129 @@ describe('treeCtrl', function () {
4646

4747
scope.list = [
4848
{
49-
'id': 1,
50-
'title': 'item1',
49+
'id': 0,
50+
'title': 'item0',
5151
'items': []
5252
},
5353
{
54-
'id': 2,
55-
'title': 'item2',
54+
'id': 1,
55+
'title': 'item1',
5656
'items': [
5757
{
58-
'id': 21,
59-
'title': 'item2.1',
58+
'id': 10,
59+
'title': 'item1.0',
6060
'items': [
6161
{
62-
'id': 211,
63-
'title': 'item2.1.1',
62+
'id': 100,
63+
'title': 'item1.0.0',
6464
'items': []
6565
},
6666
{
67-
'id': 212,
68-
'title': 'item2.1.2',
67+
'id': 101,
68+
'title': 'item1.0.1',
6969
'items': []
7070
},
7171
{
72-
'id': 213,
73-
'title': 'item2.1.3',
72+
'id': 102,
73+
'title': 'item1.0.2',
7474
'items': []
7575
}
7676
]
7777
},
7878
{
79-
'id': 22,
80-
'title': 'item2.2',
79+
'id': 11,
80+
'title': 'item1.1',
8181
'items': []
8282
},
8383
{
84-
'id': 23,
85-
'title': 'item2.3',
84+
'id': 12,
85+
'title': 'item1.2',
8686
'items': [
8787
{
88-
'id': 231,
89-
'title': 'item2.3.1',
88+
'id': 120,
89+
'title': 'item1.2.0',
9090
'items': []
9191
},
9292
{
93-
'id': 232,
94-
'title': 'item2.3.2',
93+
'id': 121,
94+
'title': 'item1.2.1',
9595
'items': []
9696
},
9797
{
98-
'id': 233,
99-
'title': 'item2.3.3',
98+
'id': 122,
99+
'title': 'item1.2.2',
100100
'items': []
101101
}
102102
]
103103
},
104104
{
105-
'id': 24,
106-
'title': 'item2.4',
105+
'id': 13,
106+
'title': 'item1.3',
107107
'items': [
108108
{
109-
'id': 241,
110-
'title': 'item2.4.1',
109+
'id': 130,
110+
'title': 'item1.3.0',
111111
'items': []
112112
},
113113
{
114-
'id': 242,
115-
'title': 'item2.4.2',
114+
'id': 131,
115+
'title': 'item1.3.1',
116116
'items': []
117117
},
118118
{
119-
'id': 243,
119+
'id': 132,
120120
'title': 'item2.4.3',
121121
'items': []
122122
},
123123
{
124124
'id': 244,
125-
'title': 'item2.4.4',
125+
'title': 'item1.3.3',
126126
'items': []
127127
}
128128
]
129129
}
130130
]
131131
},
132132
{
133-
'id': 3,
134-
'title': 'item3',
133+
'id': 2,
134+
'title': 'item2',
135135
'items': [
136136
{
137-
'id': 31,
138-
'title': 'item3.1',
137+
'id': 20,
138+
'title': 'item2.0',
139139
'items': []
140140
},
141141
{
142-
'id': 32,
143-
'title': 'item3.2',
142+
'id': 21,
143+
'title': 'item2.1',
144144
'items': []
145145
},
146146
{
147-
'id': 33,
148-
'title': 'item3.3',
147+
'id': 22,
148+
'title': 'item2.2',
149149
'items': [
150150
{
151-
'id': 331,
152-
'title': 'item3.3.1',
151+
'id': 220,
152+
'title': 'item2.2.0',
153153
'items': []
154154
},
155155
{
156-
'id': 332,
157-
'title': 'item3.3.2',
156+
'id': 221,
157+
'title': 'item2.2.1',
158158
'items': []
159159
},
160160
{
161-
'id': 333,
162-
'title': 'item3.3.3',
161+
'id': 222,
162+
'title': 'item2.2.2',
163163
'items': []
164164
}
165165
]
166166
}
167167
]
168168
},
169169
{
170-
'id': 4,
171-
'title': 'item4',
170+
'id': 3,
171+
'title': 'item3',
172172
'items': []
173173
}
174174
];
@@ -179,7 +179,7 @@ describe('treeCtrl', function () {
179179
scope.$digest();
180180
return element;
181181
}
182-
182+
183183
it('should not include in depth calculation child node scopes with no children', function () {
184184
var tree, localScope;
185185
tree = createTree();
@@ -188,6 +188,16 @@ describe('treeCtrl', function () {
188188
expect(localScope.childNodes()[1].maxSubDepth()).toEqual(2);
189189

190190
});
191+
192+
it('should calculate the depth of any subtree', function () {
193+
var tree, localScope;
194+
tree = createTree();
195+
localScope = angular.element(tree.children('ol').first()).scope();
196+
expect(localScope.childNodes()[0].maxSubDepth()).toEqual(0); // item0
197+
expect(localScope.childNodes()[1].maxSubDepth()).toEqual(2); // item1
198+
expect(localScope.childNodes()[1].childNodes()[0].maxSubDepth()).toEqual(1); // item1.0
199+
expect(localScope.childNodes()[1].childNodes()[0].childNodes()[0].maxSubDepth()).toEqual(0); // item1.0.0
200+
});
191201
});
192202

193203

0 commit comments

Comments
 (0)