|
1 | 1 | describe('treeControl', function() { |
2 | | - var $compile, $rootScope, element, num; |
| 2 | + var $compile, $rootScope, orderBy, element, num; |
3 | 3 |
|
4 | 4 | beforeEach(function () { |
5 | 5 | module('treeControl'); |
@@ -357,34 +357,38 @@ describe('treeControl', function() { |
357 | 357 | expect(element.find('li:eq(2)').text()).toBe('b'); |
358 | 358 | }); |
359 | 359 |
|
360 | | - it('should order sibling nodes in normal order', function() { |
361 | | - $rootScope.treedata = [ |
362 | | - { label: "a", children: [] }, |
363 | | - { label: "c", children: [] }, |
364 | | - { label: "b", children: [] } |
365 | | - ]; |
366 | | - $rootScope.predicate = 'label'; |
367 | | - $rootScope.reverse = false; |
368 | | - element = $compile('<treecontrol tree-model="treedata" order-by="{{predicate}}" reverse-order="{{reverse}}">{{node.label}}</treecontrol>')($rootScope); |
369 | | - $rootScope.$digest(); |
370 | | - expect(element.find('li:eq(0)').text()).toBe('a'); |
371 | | - expect(element.find('li:eq(1)').text()).toBe('b'); |
372 | | - expect(element.find('li:eq(2)').text()).toBe('c'); |
373 | | - }); |
374 | | - |
375 | | - it('should order sibling nodes in reverse order', function() { |
376 | | - $rootScope.treedata = [ |
377 | | - { label: "a", children: [] }, |
378 | | - { label: "c", children: [] }, |
379 | | - { label: "b", children: [] } |
380 | | - ]; |
381 | | - $rootScope.predicate = 'label'; |
382 | | - $rootScope.reverse = true; |
383 | | - element = $compile('<treecontrol tree-model="treedata" order-by="{{predicate}}" reverse-order="{{reverse}}">{{node.label}}</treecontrol>')($rootScope); |
384 | | - $rootScope.$digest(); |
385 | | - expect(element.find('li:eq(0)').text()).toBe('c'); |
386 | | - expect(element.find('li:eq(1)').text()).toBe('b'); |
387 | | - expect(element.find('li:eq(2)').text()).toBe('a'); |
| 360 | + [false, true].forEach(function (orderbyExpression) { |
| 361 | + it('should order sibling nodes in normal order', function() { |
| 362 | + $rootScope.treedata = [ |
| 363 | + { label: "a", children: [] }, |
| 364 | + { label: "c", children: [] }, |
| 365 | + { label: "b", children: [] } |
| 366 | + ]; |
| 367 | + $rootScope.predicate = 'label'; |
| 368 | + $rootScope.reverse = false; |
| 369 | + orderBy = orderbyExpression ? 'order-by-expression="predicate"' : 'order-by="{{predicate}}"'; |
| 370 | + element = $compile('<treecontrol tree-model="treedata" ' + orderBy + ' reverse-order="{{reverse}}">{{node.label}}</treecontrol>')($rootScope); |
| 371 | + $rootScope.$digest(); |
| 372 | + expect(element.find('li:eq(0)').text()).toBe('a'); |
| 373 | + expect(element.find('li:eq(1)').text()).toBe('b'); |
| 374 | + expect(element.find('li:eq(2)').text()).toBe('c'); |
| 375 | + }); |
| 376 | + |
| 377 | + it('should order sibling nodes in reverse order', function() { |
| 378 | + $rootScope.treedata = [ |
| 379 | + { label: "a", children: [] }, |
| 380 | + { label: "c", children: [] }, |
| 381 | + { label: "b", children: [] } |
| 382 | + ]; |
| 383 | + $rootScope.predicate = 'label'; |
| 384 | + $rootScope.reverse = true; |
| 385 | + orderBy = orderbyExpression ? 'order-by-expression="predicate"' : 'order-by="{{predicate}}"'; |
| 386 | + element = $compile('<treecontrol tree-model="treedata" ' + orderBy + ' reverse-order="{{reverse}}">{{node.label}}</treecontrol>')($rootScope); |
| 387 | + $rootScope.$digest(); |
| 388 | + expect(element.find('li:eq(0)').text()).toBe('c'); |
| 389 | + expect(element.find('li:eq(1)').text()).toBe('b'); |
| 390 | + expect(element.find('li:eq(2)').text()).toBe('a'); |
| 391 | + }); |
388 | 392 | }); |
389 | 393 |
|
390 | 394 | it('should be able to accept alternative children variable name', function () { |
|
0 commit comments