Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJose Ivan Vargas <jvargas@gitlab.com>2017-03-28 22:00:00 +0300
committerJose Ivan Vargas <jvargas@gitlab.com>2017-04-03 18:38:16 +0300
commitb4795830026fc1fd361e2dace64a70abeb0cd7ae (patch)
tree74037853e54034fabf98f3033e60caeef5f6a6c3 /spec/javascripts
parentdff378d7fe1d8a66c60abb50ebe6d297e09b8820 (diff)
Added a formatRelevantDigits text utility
Diffstat (limited to 'spec/javascripts')
-rw-r--r--spec/javascripts/lib/utils/text_utility_spec.js26
1 files changed, 26 insertions, 0 deletions
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);
+ });
+ });
});
});
})();