Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Extract isNumberField function to an external util file * format dateParse arr from the constants prevent DRY * Removed the logic from componentDidMount that was causing extra re-rendering by setting the state * Added back the original doc * Add unit tests for the isNumberField fnct * Ditch the UNSAFE_componentWillReceiveProp * handlePatch refactoring * More refactoring within MasterWidget move validatePrecision outside * Add unit tests for formatValueByWidgetType * Add unit tests for the validatePrecision * Import only the necessary actions * Removed desc on main render function * Changed variable name * Added extra safety checks Co-authored-by: Petrica Nanca <petrica.nanca@metasfresh.com>
- Loading branch information
Showing
3 changed files
with
227 additions
and
139 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,88 @@ | ||
import { | ||
isNumberField, | ||
formatValueByWidgetType, | ||
validatePrecision, | ||
} from '../../utils/widgetHelper'; | ||
|
||
describe('Widget helpers', () => { | ||
describe('is NumberField function', () => { | ||
it('createAmmount works correctly', () => { | ||
const resultToCheckOne = isNumberField('Integer'); | ||
expect(resultToCheckOne).toBe(true); | ||
|
||
const resultToCheckTwo = isNumberField('Amount'); | ||
expect(resultToCheckTwo).toBe(true); | ||
|
||
const resultToCheckThree = isNumberField('Quantity'); | ||
expect(resultToCheckThree).toBe(true); | ||
|
||
const resultToCheckFour = isNumberField('Date'); | ||
expect(resultToCheckFour).toBe(false); | ||
|
||
const resultToCheckFive = isNumberField('Color'); | ||
expect(resultToCheckFive).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('formatValueByWidgetType function', () => { | ||
it('works correctly', () => { | ||
const resultToCheckOne = formatValueByWidgetType({ | ||
widgetType: 'Quantity', | ||
value: '', | ||
}); | ||
expect(resultToCheckOne).toBe(null); | ||
|
||
const resultToCheckTwo = formatValueByWidgetType({ | ||
widgetType: 'Amount', | ||
value: null, | ||
}); | ||
expect(resultToCheckTwo).toBe('0'); | ||
}); | ||
}); | ||
|
||
describe('validatePrecision function', () => { | ||
it('works correctly', () => { | ||
const resultToCheckOne = validatePrecision({ | ||
widgetValue: '223,544334', | ||
widgetType: 'Quantity', | ||
precision: 2, | ||
}); | ||
expect(resultToCheckOne).toBe(true); | ||
|
||
|
||
const resultToCheckTwo = validatePrecision({ | ||
widgetValue: '223,544334', | ||
widgetType: 'Quantity', | ||
precision: 0, | ||
}); | ||
expect(resultToCheckTwo).toBe(true); | ||
|
||
|
||
const resultToCheckThree = validatePrecision({ | ||
widgetValue: '223.544334', | ||
widgetType: 'Amount', | ||
precision: 0, | ||
}); | ||
|
||
expect(resultToCheckThree).toBe(false); | ||
}); | ||
|
||
it('test null and empty object as value', () => { | ||
const resultToCheckNull = validatePrecision({ | ||
widgetValue: null, | ||
widgetType: 'Quantity', | ||
precision: 0, | ||
}); | ||
expect(resultToCheckNull).toBe(false); | ||
|
||
|
||
const resultToCheckEmptyObj = validatePrecision({ | ||
widgetValue: {}, | ||
widgetType: 'Amount', | ||
precision: 0, | ||
}); | ||
|
||
expect(resultToCheckEmptyObj).toBe(false); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.