Skip to content

Commit e14c4c8

Browse files
committed
fixed failing test and reorganization of tests
1 parent a28205a commit e14c4c8

File tree

1 file changed

+40
-40
lines changed

1 file changed

+40
-40
lines changed

test/angular-tree-control-test.js

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
describe('unit testing angular tree control directive', function() {
1+
describe('treeControl', function() {
22
var $compile, $rootScope, element, num;
33

44
beforeEach(function () {
@@ -18,7 +18,7 @@ describe('unit testing angular tree control directive', function() {
1818
return currentLevel;
1919
}
2020

21-
describe('testing that tree is rendered correctly', function () {
21+
describe('rendering', function () {
2222
beforeEach(function () {
2323
$rootScope.treedata = createSubTree(2, 2);
2424
$rootScope.treedata.push({});
@@ -75,7 +75,7 @@ describe('unit testing angular tree control directive', function() {
7575
});
7676
});
7777

78-
describe('testing customising tree leaf / branches using options.isLeaf', function () {
78+
describe('customising using options.isLeaf', function () {
7979
it('should display first level parents as collapsed nodes, including the leaf', function () {
8080
$rootScope.treedata = createSubTree(2, 2);
8181
$rootScope.treedata.push({});
@@ -98,7 +98,7 @@ describe('unit testing angular tree control directive', function() {
9898

9999
});
100100

101-
describe('testing that tree label rendering uses external scope data', function () {
101+
describe('rendering using external scope data', function () {
102102
beforeEach(function () {
103103
$rootScope.label = "exLabel";
104104
$rootScope.treedata = createSubTree(2, 2);
@@ -113,7 +113,7 @@ describe('unit testing angular tree control directive', function() {
113113
});
114114
});
115115

116-
describe('testing that all options are handled correctly', function () {
116+
describe('selection', function() {
117117
it('should publish the currently selected node on scope', function () {
118118
$rootScope.treedata = createSubTree(2, 2);
119119
element = $compile('<treecontrol tree-model="treedata" selected-node="selectedItem">{{node.label}}</treecontrol>')($rootScope);
@@ -154,6 +154,23 @@ describe('unit testing angular tree control directive', function() {
154154
expect($rootScope.itemSelected.calls.length).toBe(1);
155155
});
156156

157+
it('should retain selection after full model refresh', function () {
158+
var testTree = createSubTree(2, 2);
159+
$rootScope.treedata = angular.copy(testTree);
160+
element = $compile('<treecontrol tree-model="treedata">{{node.label}}</treecontrol>')($rootScope);
161+
$rootScope.$digest();
162+
163+
element.find('li:eq(0) div').click();
164+
expect(element.find('.tree-selected').length).toBe(1);
165+
166+
$rootScope.treedata = angular.copy(testTree);
167+
$rootScope.$digest();
168+
expect(element.find('.tree-selected').length).toBe(1);
169+
});
170+
});
171+
172+
describe('options usage', function () {
173+
157174
it('should order sibling nodes in normal order', function() {
158175
$rootScope.treedata = [
159176
{ label: "a", children: [] },
@@ -208,34 +225,6 @@ describe('unit testing angular tree control directive', function() {
208225
expect(element.find('.tree-selected').length).toBe(1);
209226
});
210227

211-
it('should retain expansions after full model refresh', function () {
212-
var testTree = createSubTree(2, 2);
213-
$rootScope.treedata = angular.copy(testTree);
214-
element = $compile('<treecontrol tree-model="treedata">{{node.label}}</treecontrol>')($rootScope);
215-
$rootScope.$digest();
216-
217-
element.find('li:eq(0) .tree-branch-head').click();
218-
expect(element.find('li:eq(0)').hasClass('tree-expanded')).toBeTruthy();
219-
220-
$rootScope.treedata = angular.copy(testTree);
221-
$rootScope.$digest();
222-
expect(element.find('li:eq(0)').hasClass('tree-expanded')).toBeTruthy();
223-
});
224-
225-
it('should retain selection after full model refresh', function () {
226-
var testTree = createSubTree(2, 2);
227-
$rootScope.treedata = angular.copy(testTree);
228-
element = $compile('<treecontrol tree-model="treedata">{{node.label}}</treecontrol>')($rootScope);
229-
$rootScope.$digest();
230-
231-
element.find('li:eq(0) div').click();
232-
expect(element.find('.tree-selected').length).toBe(1);
233-
234-
$rootScope.treedata = angular.copy(testTree);
235-
$rootScope.$digest();
236-
expect(element.find('.tree-selected').length).toBe(1);
237-
});
238-
239228
it('should be able to accept alternative equality function', function () {
240229
$rootScope.treedata = createSubTree(2, 2);
241230
$rootScope.treedata[0].id = 'id0';
@@ -275,7 +264,7 @@ describe('unit testing angular tree control directive', function() {
275264
});
276265
});
277266

278-
describe('testing that tree customizations work properly', function () {
267+
describe('customizations', function () {
279268
beforeEach(function () {
280269
$rootScope.treedata = createSubTree(2, 2);
281270
$rootScope.treedata.push({});
@@ -340,14 +329,11 @@ describe('unit testing angular tree control directive', function() {
340329
});
341330
});
342331

343-
describe('testing that tree nodes can be rendered expanded on tree creation', function () {
332+
describe('expanded-nodes binding', function () {
344333
beforeEach(function () {
345334
$rootScope.treedata = createSubTree(3, 2);
346-
$rootScope.treedata.push({});
347-
$rootScope.treeOptions = {
348-
defaultExpanded: [$rootScope.treedata[1], $rootScope.treedata[1].children[1]]
349-
};
350-
element = $compile('<treecontrol tree-model="treedata" options="treeOptions">{{node.label}}</treecontrol>')($rootScope);
335+
$rootScope.expandedNodes = [$rootScope.treedata[1], $rootScope.treedata[1].children[1]];
336+
element = $compile('<treecontrol tree-model="treedata" expanded-nodes="expandedNodes" options="treeOptions">{{node.label}}</treecontrol>')($rootScope);
351337
$rootScope.$digest();
352338
});
353339

@@ -358,6 +344,20 @@ describe('unit testing angular tree control directive', function() {
358344
expect(element.find('li:eq(1) li:eq(1)').hasClass('tree-expanded')).toBeTruthy();
359345
});
360346

347+
it('should retain expansions after full model refresh', function () {
348+
var testTree = createSubTree(2, 2);
349+
$rootScope.treedata = angular.copy(testTree);
350+
element = $compile('<treecontrol tree-model="treedata">{{node.label}}</treecontrol>')($rootScope);
351+
$rootScope.$digest();
352+
353+
element.find('li:eq(0) .tree-branch-head').click();
354+
expect(element.find('li:eq(0)').hasClass('tree-expanded')).toBeTruthy();
355+
356+
$rootScope.treedata = angular.copy(testTree);
357+
$rootScope.$digest();
358+
expect(element.find('li:eq(0)').hasClass('tree-expanded')).toBeTruthy();
359+
});
360+
361361
});
362362

363363
});

0 commit comments

Comments
 (0)