From e40c91e96cbb1ae254d92c7d9740335977ddc826 Mon Sep 17 00:00:00 2001 From: Ashique Ansari Date: Tue, 16 Jan 2024 23:57:12 +0530 Subject: [PATCH] Unit Test Case for bytesAsGB (number.ts) --- .../src/utilities/__tests__/number.spec.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 frontend/src/utilities/__tests__/number.spec.ts diff --git a/frontend/src/utilities/__tests__/number.spec.ts b/frontend/src/utilities/__tests__/number.spec.ts new file mode 100644 index 0000000000..776b33fd90 --- /dev/null +++ b/frontend/src/utilities/__tests__/number.spec.ts @@ -0,0 +1,18 @@ +import { bytesAsGB } from '~/utilities/number'; + +describe('bytesAsGB', () => { + it('should return 0 for NaN input', () => { + const resultNaN = bytesAsGB(NaN); + expect(resultNaN).toBe(0); + }); + + it('should convert bytes to gigabytes and round to 1 decimal place when greater than or equal to 0.1 GB', () => { + const result1GB = bytesAsGB(1024 * 1024 * 1024); + expect(result1GB).toBe(1); + }); + + it('should round to 2 decimal places when less than 0.1 GB', () => { + const result01GB = bytesAsGB(100 * 1024 * 1024); + expect(result01GB).toBe(0.1); + }); +});