From 4a41e9a9bf37090827b50388cd20751e5a01837b Mon Sep 17 00:00:00 2001 From: zhuyue Date: Wed, 1 Sep 2021 14:36:08 +0800 Subject: [PATCH] fix: Fix for getGBValue return fix for getGBValue return Change-Id: I530fa6fe1359696b10ddf879ff99093cbbbd1e88 --- src/utils/index.js | 2 +- src/utils/index.test.js | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/utils/index.js b/src/utils/index.js index ec176e49..ef5c8a33 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -85,7 +85,7 @@ export const getYesNo = (input) => (input ? t('Yes') : t('No')); export const getGBValue = (input) => { const gb = 1024; if (isNaN(input) || isNil(input) || !input || !isNumber(input)) { - return ''; + return 0; } return parseFloat(Number(input / gb).toFixed(2)); }; diff --git a/src/utils/index.test.js b/src/utils/index.test.js index ec7c42b7..896d7e5d 100644 --- a/src/utils/index.test.js +++ b/src/utils/index.test.js @@ -71,13 +71,13 @@ describe('test utils index.js', () => { expect(getGBValue(2.554 * 1024)).toBe(2.55); expect(getGBValue(2.555 * 1024)).toBe(2.56); expect(getGBValue(2.556 * 1024)).toBe(2.56); - expect(getGBValue(true)).toBe(''); - expect(getGBValue(false)).toBe(''); - expect(getGBValue(null)).toBe(''); - expect(getGBValue(undefined)).toBe(''); - expect(getGBValue(NaN)).toBe(''); - expect(getGBValue('')).toBe(''); - expect(getGBValue(0)).toBe(''); + expect(getGBValue(true)).toBe(0); + expect(getGBValue(false)).toBe(0); + expect(getGBValue(null)).toBe(0); + expect(getGBValue(undefined)).toBe(0); + expect(getGBValue(NaN)).toBe(0); + expect(getGBValue('')).toBe(0); + expect(getGBValue(0)).toBe(0); }); it('getNoValue', () => {