-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
f0496fb
commit 9100e2c
Showing
2 changed files
with
17 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>` : ''; | ||
}; |