Skip to content

Commit d010517

Browse files
author
Phú
committed
fix(stConfig): use skipNatural correctly
1 parent 8460641 commit d010517

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/stSort.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ng.module('smart-table')
1212
var classDescent = attr.stClassDescent || stConfig.sort.descentClass;
1313
var stateClasses = [classAscent, classDescent];
1414
var sortDefault;
15-
var skipNatural = attr.stSkipNatural !== undefined ? attr.stSkipNatural : stConfig.skipNatural;
15+
var skipNatural = attr.stSkipNatural !== undefined ? attr.stSkipNatural : stConfig.sort.skipNatural;
1616

1717
if (attr.stSortDefault) {
1818
sortDefault = scope.$eval(attr.stSortDefault) !== undefined ? scope.$eval(attr.stSortDefault) : attr.stSortDefault;

test/spec/stSort.spec.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ describe('stSort Directive', function () {
3737
beforeEach(inject(function ($compile, $rootScope, stConfig) {
3838
var oldAscentClass = stConfig.sort.ascentClass;
3939
var oldDescentClass = stConfig.sort.descentClass;
40+
var oldSkipNatural = stConfig.sort.skipNatural;
4041
stConfig.sort.ascentClass = 'custom-ascent';
4142
stConfig.sort.descentClass = 'custom-descent';
43+
stConfig.sort.skipNatural = true;
4244

4345
rootScope = $rootScope;
4446
scope = $rootScope.$new();
@@ -81,6 +83,7 @@ describe('stSort Directive', function () {
8183

8284
stConfig.sort.ascentClass = oldAscentClass;
8385
stConfig.sort.descentClass = oldDescentClass;
86+
stConfig.sort.skipNatural = oldSkipNatural;
8487
}));
8588

8689
it('should customize classes for sorting', function() {
@@ -89,6 +92,26 @@ describe('stSort Directive', function () {
8992
expect(hasClass(ths[1], 'custom-ascent')).toBe(true);
9093
expect(hasClass(ths[1], 'custom-descent')).toBe(false);
9194
});
95+
96+
it('should skip natural order', function() {
97+
var ths = element.find('th');
98+
var th1 = angular.element(ths[1]);
99+
th1.triggerHandler('click');
100+
th1.triggerHandler('click');
101+
th1.triggerHandler('click');
102+
scope.$apply();
103+
var actual = trToModel(element.find('tr.test-row'));
104+
expect(hasClass(ths[1], 'custom-ascent')).toBe(true);
105+
expect(hasClass(ths[1], 'custom-descent')).toBe(false);
106+
expect(actual).toEqual([
107+
{name: 'Faivre', firstname: 'Blandine', age: 44},
108+
{name: 'Leponge', firstname: 'Bob', age: 22},
109+
{name: 'Francoise', firstname: 'Frere', age: 99},
110+
{name: 'Renard', firstname: 'Laurent', age: 66},
111+
{name: 'Renard', firstname: 'Olivier', age: 33}
112+
]);
113+
});
114+
92115
});
93116

94117
describe('normal stConfig', function() {
@@ -387,4 +410,4 @@ describe('stSort Directive', function () {
387410
});
388411

389412

390-
});
413+
});

0 commit comments

Comments
 (0)