Skip to content

Commit

Permalink
added some tests for "optional '+' prefix to trigger numerical sort" …
Browse files Browse the repository at this point in the history
…feature
  • Loading branch information
a5sk4s committed May 7, 2013
1 parent f3aff74 commit 8e5c0a1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions build/ng-grid.debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* ng-grid JavaScript Library
* Authors: https://github.com/angular-ui/ng-grid/blob/master/README.md
* License: MIT (http://www.opensource.org/licenses/mit-license.php)
* Compiled At: 04/23/2013 14:36
* Compiled At: 05/07/2013 07:44
***********************************************/
(function(window, $) {
'use strict';
Expand Down Expand Up @@ -351,7 +351,7 @@ ngGridServices.factory('$sortService', ['$parse', function($parse) {
return sortService.sortBool;
case "string":
// if number string return number string sort fn. else return the str
return item.match(/^-?[£$¤]?[\d,.]+%?$/) ? sortService.sortNumberStr : sortService.sortAlpha;
return item.match(/^[-+]?[£$¤]?[\d,.]+%?$/) ? sortService.sortNumberStr : sortService.sortAlpha;
default:
//check if the item is a valid Date
if (Object.prototype.toString.call(item) === '[object Date]') {
Expand Down
15 changes: 15 additions & 0 deletions test/unit/servicesSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,21 @@ describe('Sort Service', function () {
beforeEach(inject(function ($sortService) {
$sort = $sortService;
}));

describe('guessing the sort function', function() {
var foo = {};
it('should return the correct function for the type', function () {
expect($sort.guessSortFn(true)).toEqual($sort.sortBool);
expect($sort.guessSortFn(false)).toEqual($sort.sortBool);
expect($sort.guessSortFn(-0.13)).toEqual($sort.sortNumber);
expect($sort.guessSortFn("-0.13")).toEqual($sort.sortNumberStr);
expect($sort.guessSortFn("0.13")).toEqual($sort.sortNumberStr);
expect($sort.guessSortFn("+0.13")).toEqual($sort.sortNumberStr);
expect($sort.guessSortFn(new Date())).toEqual($sort.sortDate);
expect($sort.guessSortFn("foo")).toEqual($sort.sortAlpha);
expect($sort.guessSortFn(foo)).toEqual($sort.basicSort);
});
});
});

describe('Utility Service', function () {
Expand Down

0 comments on commit 8e5c0a1

Please sign in to comment.