Fix file size due to backend code legacy

Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
soupette 2020-03-27 15:28:46 +01:00
parent 0ba62386c1
commit 7e7f1c30db
2 changed files with 9 additions and 7 deletions

View File

@ -1,5 +1,7 @@
// Source: https://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript
function formatBytes(bytes, decimals) {
function formatBytes(receivedBytes, decimals) {
const bytes = receivedBytes * 1000;
if (bytes < 1) {
return '0B';
}

View File

@ -7,27 +7,27 @@ describe('UPLOAD | components | EditForm | utils', () => {
});
it('should return 0B if less than 1 bytes is passed', () => {
expect(formatBytes(0.9)).toEqual('0B');
expect(formatBytes(0.9)).toEqual('900B');
});
it('should return 1KB if 1024 Bytes is passed', () => {
expect(formatBytes(1024)).toEqual('1KB');
expect(formatBytes(1024)).toEqual('1000KB');
});
it("should return 1KB if '1024' Bytes is passed", () => {
expect(formatBytes('1024')).toEqual('1KB');
expect(formatBytes('1024')).toEqual('1000KB');
});
it('should return 1.21KB if 1034 Bytes is passed', () => {
expect(formatBytes(1234)).toEqual('1.21KB');
expect(formatBytes(1234)).toEqual('1.18MB');
});
it('should return 1.21KB if 1034 Bytes is passed with 3 decimals', () => {
expect(formatBytes(1234, 3)).toEqual('1.205KB');
expect(formatBytes(1234, 3)).toEqual('1.177MB');
});
it('should return 1 MB if 1.1e+6 Bytes is passed', () => {
expect(formatBytes(1100000, 0)).toEqual('1MB');
expect(formatBytes(1100000, 0)).toEqual('1GB');
});
});
});