diff --git a/README.md b/README.md index 6047820..bc29447 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,8 @@ The following is a list of test statistics for the project by date and commit | 2022-06-08 | [a798ac3](https://github.com/stamp-web/stamp-web-aurelia/commit/a798ac36ac61a06258729173d8fa5cacf6a0ff24) | 102 | 18.41% | | 2022-06-08 | [e64d964](https://github.com/stamp-web/stamp-web-aurelia/commit/e64d964202e6b9930dda0712837682a71ad0d1db) | 104 | 18.59% | | 2023-01-04 | [359948b](https://github.com/stamp-web/stamp-web-aurelia/commit/359948b689f088ec8c8554044cab96c24ffe1a77) | 107 | 18.80% | -| 2023-09-21 | | 123 | 20.27% | +| 2023-09-21 | [4412730](https://github.com/stamp-web/stamp-web-aurelia/commit/441273055dc1af57257aba29f929923799563325) | 123 | 20.27% | +| 2023-10-08 | | 134 | 20.68% | ## Optimizing for Browsers diff --git a/src/resources/value-converters/as-number.js b/src/resources/value-converters/as-number.js index 4093e5b..6394699 100644 --- a/src/resources/value-converters/as-number.js +++ b/src/resources/value-converters/as-number.js @@ -14,30 +14,26 @@ limitations under the License. */ import {valueConverter} from 'aurelia-framework'; +import _ from 'lodash'; @valueConverter("asNumber") export class asNumberValueConverter { toView(value, asFloat = false) { if (value) { - try { - value = asFloat ? parseFloat(value.toString()) : parseInt(value.toString()); - } catch (err) { - console.log("Could not parse '" + value + "' to a number."); - value = -1; - } + value = asFloat ? parseFloat(value.toString()) : parseInt(value.toString()); + } + if (_.isNaN(value)) { + value = undefined; } return value; } fromView(value, asFloat = false) { if(value) { - try { - value = (asFloat) ? parseFloat(value) : parseInt(value); - } catch( err ) { - console.log("Could not parse '" + value + "' to a number."); - value = -1; - } + value = (asFloat) ? parseFloat(value) : parseInt(value); + } if (_.isNaN(value)) { + value = undefined; } return value; } diff --git a/src/resources/views/manage/list.js b/src/resources/views/manage/list.js index 50b807e..b804d50 100644 --- a/src/resources/views/manage/list.js +++ b/src/resources/views/manage/list.js @@ -146,6 +146,8 @@ export class EntityListManage { var cacheVal = JSON.parse(filterCache); if(cacheVal[fieldDef.field]) { this.filterText = cacheVal[fieldDef.field]; + } else { + this.filterText = ''; } } } diff --git a/test/unit/value-converters/as-currency-formatted.spec.js b/test/unit/resources/value-converters/as-currency-formatted.spec.js similarity index 100% rename from test/unit/value-converters/as-currency-formatted.spec.js rename to test/unit/resources/value-converters/as-currency-formatted.spec.js diff --git a/test/unit/resources/value-converters/as-number.spec.js b/test/unit/resources/value-converters/as-number.spec.js new file mode 100644 index 0000000..c1fb31e --- /dev/null +++ b/test/unit/resources/value-converters/as-number.spec.js @@ -0,0 +1,91 @@ +/** + Copyright 2023 Jason Drake + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ +import {asNumberValueConverter} from 'resources/value-converters/as-number'; + +describe('asNumberValueConverter test suite', () => { + + describe('toView tests', () => { + let cmp; + + beforeEach(() => { + cmp = new asNumberValueConverter(); + }); + + it('handles NaN', () => { + let value = cmp.toView(NaN); + expect(value).toBeUndefined(); + }); + + it('handles integer', () => { + let value = cmp.toView(53); + expect(value).toBe(53); + }); + + it('handles real number as integer', () => { + let value = cmp.toView(21.25, false); + expect(value).toBe(21); + }); + + it('handles string real number as integer ', () => { + let value = cmp.toView('42.75', false); + expect(value).toBe(42); + }); + + it('handles string real number as real number ', () => { + let value = cmp.toView('63.75', true); + expect(value).toBe(63.75); + }); + }); + + describe('fromView tests', () => { + + let cmp; + + beforeEach(() => { + cmp = new asNumberValueConverter(); + }); + + it('handles NaN', () => { + let value = cmp.fromView(NaN); + expect(value).toBeUndefined(); + }); + + it('handles positive integer value', () => { + let value = cmp.fromView('54'); + expect(value).toBe(54); + }); + + it('handles positive real number value as integer', () => { + let value = cmp.fromView('52.5'); + expect(value).toBe(52); + }); + + it('handles negative number value', () => { + let value = cmp.fromView('-23'); + expect(value).toBe(-23); + }); + + it('handles postive real number value as float', () => { + let value = cmp.fromView('35.25', true); + expect(value).toBe(35.25); + }); + + it('handles String invalid number', () => { + let value = cmp.fromView('ThisIsNotANumber'); + expect(value).toBeUndefined(); + }); + }); +});