diff options
Diffstat (limited to 'spec/frontend/lib/utils/number_utility_spec.js')
-rw-r--r-- | spec/frontend/lib/utils/number_utility_spec.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/spec/frontend/lib/utils/number_utility_spec.js b/spec/frontend/lib/utils/number_utility_spec.js index dc4aa0ea5ed..d2591cd2328 100644 --- a/spec/frontend/lib/utils/number_utility_spec.js +++ b/spec/frontend/lib/utils/number_utility_spec.js @@ -3,6 +3,7 @@ import { bytesToKiB, bytesToMiB, bytesToGiB, + numberToHumanSizeSplit, numberToHumanSize, numberToMetricPrefix, sum, @@ -13,6 +14,12 @@ import { isNumeric, isPositiveInteger, } from '~/lib/utils/number_utils'; +import { + BYTES_FORMAT_BYTES, + BYTES_FORMAT_KIB, + BYTES_FORMAT_MIB, + BYTES_FORMAT_GIB, +} from '~/lib/utils/constants'; describe('Number Utils', () => { describe('formatRelevantDigits', () => { @@ -78,6 +85,28 @@ describe('Number Utils', () => { }); }); + describe('numberToHumanSizeSplit', () => { + it('should return bytes', () => { + expect(numberToHumanSizeSplit(654)).toEqual(['654', BYTES_FORMAT_BYTES]); + expect(numberToHumanSizeSplit(-654)).toEqual(['-654', BYTES_FORMAT_BYTES]); + }); + + it('should return KiB', () => { + expect(numberToHumanSizeSplit(1079)).toEqual(['1.05', BYTES_FORMAT_KIB]); + expect(numberToHumanSizeSplit(-1079)).toEqual(['-1.05', BYTES_FORMAT_KIB]); + }); + + it('should return MiB', () => { + expect(numberToHumanSizeSplit(10485764)).toEqual(['10.00', BYTES_FORMAT_MIB]); + expect(numberToHumanSizeSplit(-10485764)).toEqual(['-10.00', BYTES_FORMAT_MIB]); + }); + + it('should return GiB', () => { + expect(numberToHumanSizeSplit(10737418240)).toEqual(['10.00', BYTES_FORMAT_GIB]); + expect(numberToHumanSizeSplit(-10737418240)).toEqual(['-10.00', BYTES_FORMAT_GIB]); + }); + }); + describe('numberToHumanSize', () => { it('should return bytes', () => { expect(numberToHumanSize(654)).toEqual('654 bytes'); |