From b4795830026fc1fd361e2dace64a70abeb0cd7ae Mon Sep 17 00:00:00 2001 From: Jose Ivan Vargas Date: Tue, 28 Mar 2017 13:00:00 -0600 Subject: Added a formatRelevantDigits text utility --- spec/javascripts/lib/utils/text_utility_spec.js | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'spec/javascripts') diff --git a/spec/javascripts/lib/utils/text_utility_spec.js b/spec/javascripts/lib/utils/text_utility_spec.js index 4200e943121..3d0e92ed240 100644 --- a/spec/javascripts/lib/utils/text_utility_spec.js +++ b/spec/javascripts/lib/utils/text_utility_spec.js @@ -105,6 +105,32 @@ require('~/lib/utils/text_utility'); expect(textArea.value).toEqual(`${initialValue}* `); }); }); + + describe('gl.text.formatRelevantDigits', () => { + it('returns 0 when the number is NaN', () => { + expect(gl.text.formatRelevantDigits('fail')).toBe(0); + }); + + it('returns 4 decimals when there is 4 plus digits to the left', () => { + const formattedNumber = gl.text.formatRelevantDigits('1000.1234567').split('.')[1]; + expect(formattedNumber.length).toBe(4); + }); + + it('returns 3 decimals when there is 1 digit to the left', () => { + const formattedNumber = gl.text.formatRelevantDigits('0.1234567').split('.')[1]; + expect(formattedNumber.length).toBe(3); + }); + + it('returns 2 decimals when there is 2 digits to the left', () => { + const formattedNumber = gl.text.formatRelevantDigits('10.1234567').split('.')[1]; + expect(formattedNumber.length).toBe(2); + }); + + it('returns 1 decimal when there is 3 digits to the left', () => { + const formattedNumber = gl.text.formatRelevantDigits('100.1234567').split('.')[1]; + expect(formattedNumber.length).toBe(1); + }); + }); }); }); })(); -- cgit v1.2.3