Skip to content

Commit

Permalink
fix(formatters): date formatters should accept ISO input & output to US
Browse files Browse the repository at this point in the history
- also make all Formatter arguments never undefined
  • Loading branch information
Ghislain Beaulac authored and Ghislain Beaulac committed Nov 27, 2020
1 parent 13809b4 commit 482d0f5
Show file tree
Hide file tree
Showing 61 changed files with 595 additions and 517 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, {}, {});
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, {}, {});
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, {});
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, {});
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, {});
const output = alignRightFormatter(1, 1, false, {} as Column, {}, {});
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, {}, {}))
.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, {}, {});
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], {});
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], {});
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], {});
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]);
expect(result).toBe(`<span title="${expectedOutput}">${expectedOutput}</span>`);
});
const params = { dataContextProperty: 'roles', propertyNames: ['name'] };
const expectedOutput = 'Administrator, Regular User';
const result = arrayObjectToCsvFormatter(0, 0, 'anything', { field: 'email', params } as Column, dataset[0], {});
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, {}, {});
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, {}, {});
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, {}, {});
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, {}, {});
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, {}, {});
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, {}, {});
expect(result).toBe(`<b>${value}</b>`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { bsDropdownFormatter } from '../bsDropdownFormatter';

describe('the Bootstrap dropdown Formatter', () => {
it('should throw an error when omitting to pass "propertyNames" to "params"', () => {
expect(() => bsDropdownFormatter(0, 0, 'anything', {} as Column, {}))
expect(() => bsDropdownFormatter(0, 0, 'anything', {} as Column, {}, {}))
.toThrowError('You must provide the "label" or "formatterLabel" via the generic "params"');
});

Expand All @@ -12,7 +12,7 @@ describe('the Bootstrap dropdown Formatter', () => {
const label = 'Action';
const row = 0;
const cell = 0;
const result = bsDropdownFormatter(row, cell, input, { field: 'user', params: { label } } as Column, {});
const result = bsDropdownFormatter(row, cell, input, { field: 'user', params: { label } } as Column, {}, {});

expect(result).toBe(`<div id="myDrop-r${row}-c${cell}" class="dropdown pointer">
<a class="dropdown-toggle">
Expand All @@ -28,7 +28,7 @@ describe('the Bootstrap dropdown Formatter', () => {
const label = 'Action';
const row = 0;
const cell = 0;
const result = bsDropdownFormatter(row, cell, input, { field: 'user', params: { label } } as Column, {});
const result = bsDropdownFormatter(row, cell, input, { field: 'user', params: { label } } as Column, {}, {});

expect(result).toBe(`<div id="myDrop-r${row}-c${cell}" class="dropdown pointer">
<a class="dropdown-toggle">
Expand Down
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, {}, {});
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, {}, {});
const output2 = centerFormatter(1, 1, undefined, {} as Column, {}, {});

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, {}, {});
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, {}, {});
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, {}, {});
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, {}, {});
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, {}, {});
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, {}, {});
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, {}, {});
expect(result).toBe('&#x2611;');
});
});
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, {}, {});
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, {}, {});
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, {}, {});
const result2 = checkmarkFormatter(0, 0, value.toUpperCase(), {} as Column, {}, {});
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, {}, {});
const result2 = checkmarkFormatter(0, 0, value.toUpperCase(), {} as Column, {}, {});
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, {}, {});
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, {}, {});
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, {}, {});
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, {}, {});
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, {}, {});
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, {}, {});
const result2 = checkmarkFormatter(0, 0, value2, {} as Column, {}, {});
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, {}, {});
const result2 = checkmarkFormatter(0, 0, value2, {} as Column, {}, {});
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, {}, {});
const result2 = checkmarkFormatter(0, 0, value2, {} as Column, {}, {});
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, {}, {});
const result2 = checkmarkFormatter(0, 0, value2, {} as Column, {}, {});
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

0 comments on commit 482d0f5

Please sign in to comment.