Skip to content

Commit

Permalink
fix(formatter): rewrite formatter do what it was supposed to do
Browse files Browse the repository at this point in the history
- while writting a unit test, we found out the Bold Formatter was dealing with decimal values while it shouldn't
  • Loading branch information
ghiscoding committed Apr 10, 2019
1 parent f0496fb commit 9100e2c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
16 changes: 16 additions & 0 deletions src/aurelia-slickgrid/formatters/boldFormatter.spec.ts
Original file line number Diff line number Diff line change
@@ -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(`<span style="font-weight: bold">${value}</span>`);
});
});
11 changes: 1 addition & 10 deletions src/aurelia-slickgrid/formatters/boldFormatter.ts
Original file line number Diff line number Diff line change
@@ -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 `<span style="font-weight: bold">${decimalFormatted(value, 2, 2)}$</span>`;
} else {
return `<span style="font-weight: bold">${decimalFormatted(value, 2, 2)}$</span>`;
}
return value ? `<span style="font-weight: bold">${value}</span>` : '';
};

0 comments on commit 9100e2c

Please sign in to comment.