From 8e5c0a1fdadb12197f2c61cad63a5ac768686aad Mon Sep 17 00:00:00 2001 From: Andreas Kemkes Date: Tue, 7 May 2013 07:50:31 -0700 Subject: [PATCH] added some tests for "optional '+' prefix to trigger numerical sort" feature --- build/ng-grid.debug.js | 4 ++-- test/unit/servicesSpec.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/build/ng-grid.debug.js b/build/ng-grid.debug.js index 1ab885515c..5e8eab9c7c 100644 --- a/build/ng-grid.debug.js +++ b/build/ng-grid.debug.js @@ -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'; @@ -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]') { diff --git a/test/unit/servicesSpec.js b/test/unit/servicesSpec.js index 8cffbc5ba9..9cdc67cd24 100644 --- a/test/unit/servicesSpec.js +++ b/test/unit/servicesSpec.js @@ -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 () {