-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(formatters): add AlignRight Formatter & alias AlignCenter=>Center (
#161) * feat(formatters): add AlignRight Formatter & alias AlignCenter=>Center - center already existed but we can add alignCenter to be in line with the other alignRight formatter - note also that there's no need for alignLeft since everything is aligned to the left in SlickGrid
- Loading branch information
1 parent
7b7202b
commit 831580d
Showing
8 changed files
with
67 additions
and
7 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
packages/common/src/formatters/__tests__/alignRightFormatter.spec.ts
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,32 @@ | ||
import { Column } from '../../interfaces/index'; | ||
import { alignRightFormatter } from '../alignRightFormatter'; | ||
|
||
describe('Right Alignment Formatter', () => { | ||
it('should return an empty string when no value is passed', () => { | ||
const output = alignRightFormatter(1, 1, '', {} as Column, {}); | ||
expect(output).toBe('<div style="float: right"></div>'); | ||
}); | ||
|
||
it('should return an empty string when value is null or undefined', () => { | ||
const output1 = alignRightFormatter(1, 1, null, {} as Column, {}); | ||
const output2 = alignRightFormatter(1, 1, undefined, {} as Column, {}); | ||
|
||
expect(output1).toBe('<div style="float: right"></div>'); | ||
expect(output2).toBe('<div style="float: right"></div>'); | ||
}); | ||
|
||
it('should return a string all in uppercase', () => { | ||
const output = alignRightFormatter(1, 1, 'hello', {} as Column, {}); | ||
expect(output).toBe('<div style="float: right">hello</div>'); | ||
}); | ||
|
||
it('should return a number as a string', () => { | ||
const output = alignRightFormatter(1, 1, 99, {} as Column, {}); | ||
expect(output).toBe('<div style="float: right">99</div>'); | ||
}); | ||
|
||
it('should return a boolean as a string all in uppercase', () => { | ||
const output = alignRightFormatter(1, 1, false, {} as Column, {}); | ||
expect(output).toBe('<div style="float: right">false</div>'); | ||
}); | ||
}); |
11 changes: 10 additions & 1 deletion
11
packages/common/src/formatters/__tests__/centerFormatter.spec.ts
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
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
2 changes: 1 addition & 1 deletion
2
packages/common/src/formatters/__tests__/yesNoFormatter.spec.ts
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
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,10 @@ | ||
import { Formatter } from './../interfaces/index'; | ||
|
||
export const alignRightFormatter: Formatter = (_row: number, _cell: number, value: string | any): string => { | ||
let outputValue = value; | ||
|
||
if (value === null || value === undefined) { | ||
outputValue = ''; | ||
} | ||
return `<div style="float: right">${outputValue}</div>`; | ||
}; |
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,9 +1,10 @@ | ||
import { Formatter } from './../interfaces/index'; | ||
|
||
export const centerFormatter: Formatter = (_row: number, _cell: number, value: string | any): string => { | ||
// make sure the value is a string | ||
if (value !== undefined && typeof value !== 'string') { | ||
value = value + ''; | ||
let outputValue = value; | ||
|
||
if (value === null || value === undefined) { | ||
outputValue = ''; | ||
} | ||
return `<center>${value}</center>`; | ||
return `<center>${outputValue}</center>`; | ||
}; |
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
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