Skip to content

Commit

Permalink
chore: add unit test for returnFileSize func (#882)
Browse files Browse the repository at this point in the history
Co-authored-by: uyarnchen <[email protected]>
  • Loading branch information
uyarn and uyarnchen authored Sep 29, 2022
1 parent 2b64243 commit ba9b7c6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
6 changes: 5 additions & 1 deletion js/upload/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ export function returnFileSize(number: number) {
if (number >= SIZE_MAP.KB && number < SIZE_MAP.MB) {
return `${(number / SIZE_MAP.KB).toFixed(1)} KB`;
}
if (number >= SIZE_MAP.MB) {
if (number >= SIZE_MAP.MB && number < SIZE_MAP.GB) {
return `${(number / SIZE_MAP.MB).toFixed(1)} MB`;
}

if (number >= SIZE_MAP.GB) {
return `${(number / SIZE_MAP.GB).toFixed(1)} GB`;
}
return '';
}

Expand Down
27 changes: 27 additions & 0 deletions test/unit/upload/returnFileSize.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { returnFileSize } from '../../../js/upload/utils';

describe('returnFileSize', () => {
it('size is 1 B return 1 Byte', () => {
expect(returnFileSize(1)).toBe('1 Bytes');
});

it('size is 1023 B return 1023 Byte', () => {
expect(returnFileSize(1023)).toBe('1023 Bytes');
});

it('size is 1025 B return 1.0 KB', () => {
expect(returnFileSize(1025)).toBe('1.0 KB');
});

it('size is 2097152 B return 2.0 MB', () => {
expect(returnFileSize(2097152)).toBe('2.0 MB');
});

it('size is 1073741823 B return 1024.0 MB', () => {
expect(returnFileSize(1073741823)).toBe('1024.0 MB');
});

it('size is 1073741824 B return 1.0 GB', () => {
expect(returnFileSize(1073741824)).toBe('1.0 GB');
});
});

0 comments on commit ba9b7c6

Please sign in to comment.