Skip to content

Commit

Permalink
feat(formatters): add numberPrefix & Suffix to Decimal Formatter (#193)
Browse files Browse the repository at this point in the history
* feat(formatters): add numberPrefix & Suffix to Decimal Formatter
  • Loading branch information
ghiscoding committed Dec 11, 2020
1 parent d92f8c6 commit 0e4d30c
Show file tree
Hide file tree
Showing 46 changed files with 345 additions and 306 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@ 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, {});
const output = alignRightFormatter(1, 1, '', {} as Column, {}, {} as any);
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, {});
const output1 = alignRightFormatter(1, 1, null, {} as Column, {}, {} as any);
const output2 = alignRightFormatter(1, 1, undefined, {} as Column, {}, {} as any);

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, {});
const output = alignRightFormatter(1, 1, 'hello', {} as Column, {}, {} as any);
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, {});
const output = alignRightFormatter(1, 1, 99, {} as Column, {}, {} as any);
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, {});
const output = alignRightFormatter(1, 1, false, {} as Column, {}, {} as any);
expect(output).toBe('<div style="float: right">false</div>');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,41 @@ describe('the ArrayObjectToCsv Formatter', () => {
];

it('should throw an error when omitting to pass "propertyNames" to "params"', () => {
expect(() => arrayObjectToCsvFormatter(0, 0, 'anything', {} as Column, {}))
expect(() => arrayObjectToCsvFormatter(0, 0, 'anything', {} as Column, {}, {} as any))
.toThrowError('Formatters.arrayObjectToCsv requires you to pass an array of "propertyNames"');
});

it('should return original input value when the "propertyNames" is not found in the given object', () => {
const params = { propertyNames: ['name'] };
const result = arrayObjectToCsvFormatter(0, 0, 'anything', { field: 'roles', params } as Column, {});
const result = arrayObjectToCsvFormatter(0, 0, 'anything', { field: 'roles', params } as Column, {}, {} as any);
expect(result).toBe('anything');
});

it('should return original input value when the "propertyNames" is found to be holding an empty array', () => {
const params = { propertyNames: ['name'] };
const result = arrayObjectToCsvFormatter(0, 0, 'anything', { field: 'roles', params } as Column, dataset[2]);
const result = arrayObjectToCsvFormatter(0, 0, 'anything', { field: 'roles', params } as Column, dataset[2], {} as any);
expect(result).toBe('anything');
});

it('should return csv string in a span (with it\'s content and title attribute to be the same) when multiple input values are passed', () => {
const params = { propertyNames: ['name'] };
const expectedOutput = 'Administrator, Regular User';
const result = arrayObjectToCsvFormatter(0, 0, 'anything', { field: 'roles', params } as Column, dataset[0]);
const result = arrayObjectToCsvFormatter(0, 0, 'anything', { field: 'roles', params } as Column, dataset[0], {} as any);
expect(result).toBe(`<span title="${expectedOutput}">${expectedOutput}</span>`);
});

it('should return regular string in a span (with it\'s content and title attribute to be the same) when 1 input value is passed', () => {
const params = { propertyNames: ['name'] };
const expectedOutput = 'Regular User';
const result = arrayObjectToCsvFormatter(0, 0, 'anything', { field: 'roles', params } as Column, dataset[1]);
const result = arrayObjectToCsvFormatter(0, 0, 'anything', { field: 'roles', params } as Column, dataset[1], {} as any);
expect(result).toBe(`<span title="${expectedOutput}">${expectedOutput}</span>`);
});

it(`should return csv string in a span when multiple input values are passed
and user provide a different "dataContextProperty" to pull the data from a different field of the dataContext object`, () => {
const params = { dataContextProperty: 'roles', propertyNames: ['name'] };
const expectedOutput = 'Administrator, Regular User';
const result = arrayObjectToCsvFormatter(0, 0, 'anything', { field: 'email', params } as Column, dataset[0]);
const result = arrayObjectToCsvFormatter(0, 0, 'anything', { field: 'email', params } as Column, dataset[0], {} as any);
expect(result).toBe(`<span title="${expectedOutput}">${expectedOutput}</span>`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ import { arrayToCsvFormatter } from '../arrayToCsvFormatter';
describe('the ArrayToCsv Formatter', () => {
it('should return same output when no value is passed', () => {
const valueArray = null;
const result = arrayToCsvFormatter(0, 0, valueArray, {} as Column, {});
const result = arrayToCsvFormatter(0, 0, valueArray, {} as Column, {}, {} as any);
expect(result).toBe(null);
});

it('should return an empty array when value passed is an empty array', () => {
const valueArray = [];
const result = arrayToCsvFormatter(0, 0, valueArray, {} as Column, {});
const result = arrayToCsvFormatter(0, 0, valueArray, {} as Column, {}, {} as any);
expect(result).toEqual([]);
});

it('should return original value when input is not an array', () => {
const inputValue = 'anything';
const result = arrayToCsvFormatter(0, 0, inputValue, {} as Column, {});
const result = arrayToCsvFormatter(0, 0, inputValue, {} as Column, {}, {} as any);
expect(result).toBe(inputValue);
});

it('should return a CSV string when value passed is an array of string', () => {
const valueArray = ['john', 'doe'];
const result = arrayToCsvFormatter(0, 0, valueArray, {} as Column, {});
const result = arrayToCsvFormatter(0, 0, valueArray, {} as Column, {}, {} as any);
expect(result).toBe(`<span title="${valueArray.join(', ')}">${valueArray.join(', ')}</span>`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ 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, {});
const result = boldFormatter(0, 0, value, {} as Column, {}, {} as any);
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, {});
const result = boldFormatter(0, 0, value, {} as Column, {}, {} as any);
expect(result).toBe(`<b>${value}</b>`);
});
});
12 changes: 6 additions & 6 deletions packages/common/src/formatters/__tests__/centerFormatter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@ import { centerFormatter } from '../centerFormatter';

describe('Center Alignment Formatter', () => {
it('should return an empty string when no value is passed', () => {
const output = centerFormatter(1, 1, '', {} as Column, {});
const output = centerFormatter(1, 1, '', {} as Column, {}, {} as any);
expect(output).toBe('<center></center>');
});

it('should return an empty string when value is null or undefined', () => {
const output1 = centerFormatter(1, 1, null, {} as Column, {});
const output2 = centerFormatter(1, 1, undefined, {} as Column, {});
const output1 = centerFormatter(1, 1, null, {} as Column, {}, {} as any);
const output2 = centerFormatter(1, 1, undefined, {} as Column, {}, {} as any);

expect(output1).toBe('<center></center>');
expect(output2).toBe('<center></center>');
});


it('should return a string all in uppercase', () => {
const output = centerFormatter(1, 1, 'hello', {} as Column, {});
const output = centerFormatter(1, 1, 'hello', {} as Column, {}, {} as any);
expect(output).toBe('<center>hello</center>');
});

it('should return a number as a string', () => {
const output = centerFormatter(1, 1, 99, {} as Column, {});
const output = centerFormatter(1, 1, 99, {} as Column, {}, {} as any);
expect(output).toBe('<center>99</center>');
});

it('should return a boolean as a string all in uppercase', () => {
const output = centerFormatter(1, 1, false, {} as Column, {});
const output = centerFormatter(1, 1, false, {} as Column, {}, {} as any);
expect(output).toBe('<center>false</center>');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ import { checkboxFormatter } from '../checkboxFormatter';
describe('the Checkbox Formatter', () => {
it('should return an empty string when no value is passed', () => {
const value = null;
const result = checkboxFormatter(0, 0, value, {} as Column, {});
const result = checkboxFormatter(0, 0, value, {} as Column, {}, {} as any);
expect(result).toBe('');
});

it('should return an empty string when False is provided', () => {
const value = false;
const result = checkboxFormatter(0, 0, value, {} as Column, {});
const result = checkboxFormatter(0, 0, value, {} as Column, {}, {} as any);
expect(result).toBe('');
});

it('should return the unicode value of a checkbox when input is True', () => {
const value = true;
const result = checkboxFormatter(0, 0, value, {} as Column, {});
const result = checkboxFormatter(0, 0, value, {} as Column, {}, {} as any);
expect(result).toBe('&#x2611;');
});

it('should return the unicode value of a checkbox when input is filled with any string', () => {
const value = 'anything';
const result = checkboxFormatter(0, 0, value, {} as Column, {});
const result = checkboxFormatter(0, 0, value, {} as Column, {}, {} as any);
expect(result).toBe('&#x2611;');
});
});
38 changes: 19 additions & 19 deletions packages/common/src/formatters/__tests__/checkmarkFormatter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,94 +4,94 @@ import { checkmarkFormatter } from '../checkmarkFormatter';
describe('the Checkmark Formatter', () => {
it('should return an empty string when no value is passed', () => {
const value = null;
const result = checkmarkFormatter(0, 0, value, {} as Column, {});
const result = checkmarkFormatter(0, 0, value, {} as Column, {}, {} as any);
expect(result).toBe('');
});

it('should return an empty string when False is provided', () => {
const value = false;
const result = checkmarkFormatter(0, 0, value, {} as Column, {});
const result = checkmarkFormatter(0, 0, value, {} as Column, {}, {} as any);
expect(result).toBe('');
});

it('should return an empty string when the string "FALSE" (case insensitive) is provided', () => {
const value = 'FALSE';
const result1 = checkmarkFormatter(0, 0, value.toLowerCase(), {} as Column, {});
const result2 = checkmarkFormatter(0, 0, value.toUpperCase(), {} as Column, {});
const result1 = checkmarkFormatter(0, 0, value.toLowerCase(), {} as Column, {}, {} as any);
const result2 = checkmarkFormatter(0, 0, value.toUpperCase(), {} as Column, {}, {} as any);
expect(result1).toBe('');
expect(result2).toBe('');
});

it('should return the Font Awesome Checkmark icon when the string "True" (case insensitive) is provided', () => {
const value = 'True';
const result1 = checkmarkFormatter(0, 0, value.toLowerCase(), {} as Column, {});
const result2 = checkmarkFormatter(0, 0, value.toUpperCase(), {} as Column, {});
const result1 = checkmarkFormatter(0, 0, value.toLowerCase(), {} as Column, {}, {} as any);
const result2 = checkmarkFormatter(0, 0, value.toUpperCase(), {} as Column, {}, {} as any);
expect(result1).toBe('<i class="fa fa-check checkmark-icon" aria-hidden="true"></i>');
expect(result2).toBe('<i class="fa fa-check checkmark-icon" aria-hidden="true"></i>');
});

it('should return the Font Awesome Checkmark icon when input is True', () => {
const value = true;
const result = checkmarkFormatter(0, 0, value, {} as Column, {});
const result = checkmarkFormatter(0, 0, value, {} as Column, {}, {} as any);
expect(result).toBe('<i class="fa fa-check checkmark-icon" aria-hidden="true"></i>');
});

it('should return the Font Awesome Checkmark icon when input is a string even if it start with 0', () => {
const value = '005A00ABC';
const result1 = checkmarkFormatter(0, 0, value, {} as Column, {});
const result1 = checkmarkFormatter(0, 0, value, {} as Column, {}, {} as any);
expect(result1).toBe('<i class="fa fa-check checkmark-icon" aria-hidden="true"></i>');
});

it('should return an empty string when the string "0" is provided', () => {
const value = '0';
const result = checkmarkFormatter(0, 0, value, {} as Column, {});
const result = checkmarkFormatter(0, 0, value, {} as Column, {}, {} as any);
expect(result).toBe('');
});

it('should return the Font Awesome Checkmark icon when input is a number greater than 0', () => {
const value = 0.000001;
const result1 = checkmarkFormatter(0, 0, value, {} as Column, {});
const result1 = checkmarkFormatter(0, 0, value, {} as Column, {}, {} as any);
expect(result1).toBe('<i class="fa fa-check checkmark-icon" aria-hidden="true"></i>');
});

it('should return the Font Awesome Checkmark icon when input is a number as a text greater than 0', () => {
const value = '0.000001';
const result1 = checkmarkFormatter(0, 0, value, {} as Column, {});
const result1 = checkmarkFormatter(0, 0, value, {} as Column, {}, {} as any);
expect(result1).toBe('<i class="fa fa-check checkmark-icon" aria-hidden="true"></i>');
});

it('should return an empty string when input is a number lower or equal to 0', () => {
const value1 = 0;
const value2 = -0.5;
const result1 = checkmarkFormatter(0, 0, value1, {} as Column, {});
const result2 = checkmarkFormatter(0, 0, value2, {} as Column, {});
const result1 = checkmarkFormatter(0, 0, value1, {} as Column, {}, {} as any);
const result2 = checkmarkFormatter(0, 0, value2, {} as Column, {}, {} as any);
expect(result1).toBe('');
expect(result2).toBe('');
});

it('should return an empty string when input is a number as a text and lower or equal to 0', () => {
const value1 = '0';
const value2 = '-0.5';
const result1 = checkmarkFormatter(0, 0, value1, {} as Column, {});
const result2 = checkmarkFormatter(0, 0, value2, {} as Column, {});
const result1 = checkmarkFormatter(0, 0, value1, {} as Column, {}, {} as any);
const result2 = checkmarkFormatter(0, 0, value2, {} as Column, {}, {} as any);
expect(result1).toBe('');
expect(result2).toBe('');
});

it('should return an empty string when input is type null or undefined', () => {
const value1 = null;
const value2 = undefined;
const result1 = checkmarkFormatter(0, 0, value1, {} as Column, {});
const result2 = checkmarkFormatter(0, 0, value2, {} as Column, {});
const result1 = checkmarkFormatter(0, 0, value1, {} as Column, {}, {} as any);
const result2 = checkmarkFormatter(0, 0, value2, {} as Column, {}, {} as any);
expect(result1).toBe('');
expect(result2).toBe('');
});

it('should return the Font Awesome Checkmark icon when input is the "null" or "undefined"', () => {
const value1 = 'null';
const value2 = 'undefined';
const result1 = checkmarkFormatter(0, 0, value1, {} as Column, {});
const result2 = checkmarkFormatter(0, 0, value2, {} as Column, {});
const result1 = checkmarkFormatter(0, 0, value1, {} as Column, {}, {} as any);
const result2 = checkmarkFormatter(0, 0, value2, {} as Column, {}, {} as any);
expect(result1).toBe('<i class="fa fa-check checkmark-icon" aria-hidden="true"></i>');
expect(result2).toBe('<i class="fa fa-check checkmark-icon" aria-hidden="true"></i>');
});
Expand Down
Loading

0 comments on commit 0e4d30c

Please sign in to comment.