fix: Fix for getGBValue return

fix for getGBValue return

Change-Id: I530fa6fe1359696b10ddf879ff99093cbbbd1e88
This commit is contained in:
zhuyue 2021-09-01 14:36:08 +08:00
parent 96d3924fbc
commit 4a41e9a9bf
2 changed files with 8 additions and 8 deletions

View File

@ -85,7 +85,7 @@ export const getYesNo = (input) => (input ? t('Yes') : t('No'));
export const getGBValue = (input) => { export const getGBValue = (input) => {
const gb = 1024; const gb = 1024;
if (isNaN(input) || isNil(input) || !input || !isNumber(input)) { if (isNaN(input) || isNil(input) || !input || !isNumber(input)) {
return ''; return 0;
} }
return parseFloat(Number(input / gb).toFixed(2)); return parseFloat(Number(input / gb).toFixed(2));
}; };

View File

@ -71,13 +71,13 @@ describe('test utils index.js', () => {
expect(getGBValue(2.554 * 1024)).toBe(2.55); expect(getGBValue(2.554 * 1024)).toBe(2.55);
expect(getGBValue(2.555 * 1024)).toBe(2.56); expect(getGBValue(2.555 * 1024)).toBe(2.56);
expect(getGBValue(2.556 * 1024)).toBe(2.56); expect(getGBValue(2.556 * 1024)).toBe(2.56);
expect(getGBValue(true)).toBe(''); expect(getGBValue(true)).toBe(0);
expect(getGBValue(false)).toBe(''); expect(getGBValue(false)).toBe(0);
expect(getGBValue(null)).toBe(''); expect(getGBValue(null)).toBe(0);
expect(getGBValue(undefined)).toBe(''); expect(getGBValue(undefined)).toBe(0);
expect(getGBValue(NaN)).toBe(''); expect(getGBValue(NaN)).toBe(0);
expect(getGBValue('')).toBe(''); expect(getGBValue('')).toBe(0);
expect(getGBValue(0)).toBe(''); expect(getGBValue(0)).toBe(0);
}); });
it('getNoValue', () => { it('getNoValue', () => {