From 9100e2c4b9d9425736f8d4813f186b7c2573c3ae Mon Sep 17 00:00:00 2001 From: ghiscoding Date: Tue, 9 Apr 2019 23:46:38 -0400 Subject: [PATCH] fix(formatter): rewrite formatter do what it was supposed to do - while writting a unit test, we found out the Bold Formatter was dealing with decimal values while it shouldn't --- .../formatters/boldFormatter.spec.ts | 16 ++++++++++++++++ .../formatters/boldFormatter.ts | 11 +---------- 2 files changed, 17 insertions(+), 10 deletions(-) create mode 100644 src/aurelia-slickgrid/formatters/boldFormatter.spec.ts diff --git a/src/aurelia-slickgrid/formatters/boldFormatter.spec.ts b/src/aurelia-slickgrid/formatters/boldFormatter.spec.ts new file mode 100644 index 000000000..6734b5616 --- /dev/null +++ b/src/aurelia-slickgrid/formatters/boldFormatter.spec.ts @@ -0,0 +1,16 @@ +import { Column } from '../models'; +import { boldFormatter } from './boldFormatter'; + +describe('the Bold Formatter', () => { + it('should return an empty string when no value is passed', () => { + const value = null; + const result = boldFormatter(0, 0, value, {} as Column, {}); + expect(result).toBe(''); + }); + + it('should return a bold html formatted string when value is filled', () => { + const value = 'john'; + const result = boldFormatter(0, 0, value, {} as Column, {}); + expect(result).toBe(`${value}`); + }); +}); diff --git a/src/aurelia-slickgrid/formatters/boldFormatter.ts b/src/aurelia-slickgrid/formatters/boldFormatter.ts index e3fdc9a38..70eac463c 100644 --- a/src/aurelia-slickgrid/formatters/boldFormatter.ts +++ b/src/aurelia-slickgrid/formatters/boldFormatter.ts @@ -1,14 +1,5 @@ import { Column, Formatter } from './../models/index'; -import { decimalFormatted } from './../services/utilities'; export const boldFormatter: Formatter = (row: number, cell: number, value: any, columnDef: Column, dataContext: any) => { - const isNumber = (value === null || value === undefined || value === '') ? false : !isNaN(+value); - - if (!isNumber) { - return ''; - } else if (value >= 0) { - return `${decimalFormatted(value, 2, 2)}$`; - } else { - return `${decimalFormatted(value, 2, 2)}$`; - } + return value ? `${value}` : ''; };