3 describe('crmUiOrder', function() {
5 beforeEach(function() {
11 describe('crmUiOrder', function() {
12 var $compile
, $q
, $rootScope
, rows
, element
;
15 ' <span crm-ui-order="{var: \'myOrder\', defaults: [\'-num\']}"></span>' +
19 ' <th><a crm-ui-order-by="[myOrder,\'name\']" id="th-name">Name</a></th>' +
20 ' <th><a crm-ui-order-by="[myOrder,\'num\']" id="th-num">Num</a></th>' +
24 ' <tr ng-repeat="r in rows|orderBy:myOrder.get()">' +
25 ' <td class="row-value">{{r.name}}</td>' +
31 beforeEach(inject(function(_
$compile_
, _
$rootScope_
, _
$q_
) {
32 $compile
= _
$compile_
;
33 $rootScope
= _
$rootScope_
;
36 $rootScope
.rows
= rows
= [
37 {name
: 'a', num
: 200},
38 {name
: 'c', num
: 300},
39 {name
: 'b', num
: 100},
45 it('changes primary ordering on click', function() {
46 element
= $compile(html
)($rootScope
);
48 expect($rootScope
.myOrder
).toEqual(jasmine
.any(Object
));
49 expect(element
.find('.row-value').text()).toBe('cabd');
51 element
.find('#th-name').click();
53 expect(element
.find('.row-value').text()).toBe('abcd');
56 it('cycles through ascending/descending orderings on multiple clicks', function() {
58 element
= $compile(html
)($rootScope
);
60 expect($rootScope
.myOrder
.get()).toEqual(['-num']);
61 expect($rootScope
.myOrder
.getDir('num')).toEqual('-');
62 expect(element
.find('.row-value').text()).toBe('cabd');
64 // toggle: "-num" => ""
65 element
.find('#th-num').click();
67 expect($rootScope
.myOrder
.get()).toEqual([]);
68 expect($rootScope
.myOrder
.getDir('num')).toEqual('');
69 expect(element
.find('.row-value').text()).toBe('acbd');
71 // toggle: "" => "+num"
72 element
.find('#th-num').click();
74 expect($rootScope
.myOrder
.get()).toEqual(['+num']);
75 expect($rootScope
.myOrder
.getDir('num')).toEqual('+');
76 expect(element
.find('.row-value').text()).toBe('dbac');
78 // toggle: "+num" => "-num"
79 element
.find('#th-num').click();
81 expect($rootScope
.myOrder
.get()).toEqual(['-num']);
82 expect($rootScope
.myOrder
.getDir('num')).toEqual('-');
83 expect(element
.find('.row-value').text()).toBe('cabd');