From d4e77d1902afbef7d303dd5e7b7fe4d75fab6cfd Mon Sep 17 00:00:00 2001 From: "M. Adam Kendall" Date: Tue, 28 Apr 2015 10:05:08 -0400 Subject: [PATCH] Don't try to format value if it is NA --- app/scripts/modules/hmdaFilters.js | 36 ++++++++++++++++-------------- test/spec/modules/hmdaFilters.js | 4 ++++ 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/app/scripts/modules/hmdaFilters.js b/app/scripts/modules/hmdaFilters.js index 8f2f0a1..8ca186f 100644 --- a/app/scripts/modules/hmdaFilters.js +++ b/app/scripts/modules/hmdaFilters.js @@ -75,23 +75,25 @@ angular.module('hmdaFilters', []) }; return function(value, scope, property) { - var section = getFileSpecSection(scope, value.lineNumber); - var fileSpec = HMDAEngine.getFileSpec(HMDAEngine.getRuleYear()); - var propSpec = fileSpec[section][property]; - - if (propSpec !== undefined && propSpec.hasOwnProperty('validation')) { - var propVal = propSpec.validation; - var result; - - if (propVal.type === 'percent') { - return value + '%'; - } else if (propVal.type === 'date' && propVal.match === 'yyyyMMdd') { - return $filter('date')(value.toDate(), 'M/d/yyyy'); - } else if (propVal.type === 'date' && propVal.match === 'yyyyMMddHHmm') { - return $filter('date')(value.toDate(), 'M/d/yyyy H:mm'); - } else if (propVal.type === 'currency') { - result = parseInt(value) * parseInt(propVal.multiplier); - return $filter('currency')(result, '$', 0); + if (value !== 'NA') { + var section = getFileSpecSection(scope, value.lineNumber); + var fileSpec = HMDAEngine.getFileSpec(HMDAEngine.getRuleYear()); + var propSpec = fileSpec[section][property]; + + if (propSpec !== undefined && propSpec.hasOwnProperty('validation')) { + var propVal = propSpec.validation; + var result; + + if (propVal.type === 'percent') { + return value + '%'; + } else if (propVal.type === 'date' && propVal.match === 'yyyyMMdd') { + return $filter('date')(value.toDate(), 'M/d/yyyy'); + } else if (propVal.type === 'date' && propVal.match === 'yyyyMMddHHmm') { + return $filter('date')(value.toDate(), 'M/d/yyyy H:mm'); + } else if (propVal.type === 'currency') { + result = parseInt(value) * parseInt(propVal.multiplier); + return $filter('currency')(result, '$', 0); + } } } return value; diff --git a/test/spec/modules/hmdaFilters.js b/test/spec/modules/hmdaFilters.js index 641a81b..8a7a897 100644 --- a/test/spec/modules/hmdaFilters.js +++ b/test/spec/modules/hmdaFilters.js @@ -160,6 +160,10 @@ describe('Filters: hmdaFilters', function() { expect(hmdaValueFilter('100', 'lar', 'number')).toBe('100'); })); + it('should not format a value of NA', angular.mock.inject(function(hmdaValueFilter) { + expect(hmdaValueFilter('NA', 'lar', 'percent')).toBe('NA'); + })); + it('should format a file-spec property of type percent', angular.mock.inject(function(hmdaValueFilter) { expect(hmdaValueFilter('12.34', 'lar', 'percent')).toBe('12.34%'); }));