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:
Diffstat (limited to 'spec/javascripts')
-rw-r--r--spec/javascripts/lib/utils/number_utility_spec.js41
-rw-r--r--spec/javascripts/lib/utils/text_utility_spec.js26
2 files changed, 41 insertions, 26 deletions
diff --git a/spec/javascripts/lib/utils/number_utility_spec.js b/spec/javascripts/lib/utils/number_utility_spec.js
new file mode 100644
index 00000000000..5fde8be9123
--- /dev/null
+++ b/spec/javascripts/lib/utils/number_utility_spec.js
@@ -0,0 +1,41 @@
+import { formatRelevantDigits } from '~/lib/utils/number_utils';
+
+describe('Number Utils', () => {
+ describe('formatRelevantDigits', () => {
+ it('returns an empty string when the number is NaN', () => {
+ expect(formatRelevantDigits('fail')).toBe('');
+ });
+
+ it('returns 4 decimals when there is 4 plus digits to the left', () => {
+ const formattedNumber = formatRelevantDigits('1000.1234567');
+ const rightFromDecimal = formattedNumber.split('.')[1];
+ const leftFromDecimal = formattedNumber.split('.')[0];
+ expect(rightFromDecimal.length).toBe(4);
+ expect(leftFromDecimal.length).toBe(4);
+ });
+
+ it('returns 3 decimals when there is 1 digit to the left', () => {
+ const formattedNumber = formatRelevantDigits('0.1234567');
+ const rightFromDecimal = formattedNumber.split('.')[1];
+ const leftFromDecimal = formattedNumber.split('.')[0];
+ expect(rightFromDecimal.length).toBe(3);
+ expect(leftFromDecimal.length).toBe(1);
+ });
+
+ it('returns 2 decimals when there is 2 digits to the left', () => {
+ const formattedNumber = formatRelevantDigits('10.1234567');
+ const rightFromDecimal = formattedNumber.split('.')[1];
+ const leftFromDecimal = formattedNumber.split('.')[0];
+ expect(rightFromDecimal.length).toBe(2);
+ expect(leftFromDecimal.length).toBe(2);
+ });
+
+ it('returns 1 decimal when there is 3 digits to the left', () => {
+ const formattedNumber = formatRelevantDigits('100.1234567');
+ const rightFromDecimal = formattedNumber.split('.')[1];
+ const leftFromDecimal = formattedNumber.split('.')[0];
+ expect(rightFromDecimal.length).toBe(1);
+ expect(leftFromDecimal.length).toBe(3);
+ });
+ });
+});
diff --git a/spec/javascripts/lib/utils/text_utility_spec.js b/spec/javascripts/lib/utils/text_utility_spec.js
index 3d0e92ed240..4200e943121 100644
--- a/spec/javascripts/lib/utils/text_utility_spec.js
+++ b/spec/javascripts/lib/utils/text_utility_spec.js
@@ -105,32 +105,6 @@ 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);
- });
- });
});
});
})();