-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
96 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import formatFileSize from "./formatFileSize"; | ||
|
||
describe('formatFileSize', () => { | ||
|
||
it('returns rounded file size formats for valid inputs', () => { | ||
|
||
expect(formatFileSize(0)).toBe('0 bytes'); | ||
expect(formatFileSize(-0)).toBe('0 bytes'); | ||
expect(formatFileSize(1)).toBe('1 bytes'); | ||
expect(formatFileSize(1.5)).toBe('2 bytes'); | ||
|
||
expect(formatFileSize(1023)).toBe('1023 bytes'); | ||
expect(formatFileSize(1024)).toBe('1 KB'); | ||
expect(formatFileSize(1025)).toBe('1 KB'); | ||
|
||
expect(formatFileSize(1535)).toBe('1 KB'); | ||
expect(formatFileSize(1536)).toBe('2 KB'); | ||
expect(formatFileSize(2048)).toBe('2 KB'); | ||
|
||
expect(formatFileSize(Math.pow(2, 20) - 1)).toBe('1024 KB'); | ||
expect(formatFileSize(Math.pow(2, 20))).toBe('1 MB'); | ||
expect(formatFileSize(Math.pow(2, 20) + 1)).toBe('1 MB'); | ||
|
||
expect(formatFileSize(Math.pow(2, 30) - 1)).toBe('1024 MB'); | ||
expect(formatFileSize(Math.pow(2, 30))).toBe('1 GB'); | ||
expect(formatFileSize(Math.pow(2, 30) + 1)).toBe('1 GB'); | ||
|
||
}); | ||
|
||
it('throws "Invalid file size" exception for invalid inputs', () => { | ||
|
||
expect(() => formatFileSize(Number.MIN_SAFE_INTEGER)).toThrow('Invalid file size'); | ||
expect(() => formatFileSize(-1)).toThrow('Invalid file size'); | ||
expect(() => formatFileSize(NaN)).toThrow('Invalid file size'); | ||
expect(() => formatFileSize(undefined as unknown as number)).toThrow('Invalid file size'); | ||
expect(() => formatFileSize(Math.pow(2, 40))).toThrow('Invalid file size'); // 1TB | ||
expect(() => formatFileSize(Number.MAX_SAFE_INTEGER)).toThrow('Invalid file size'); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ export type SearchResult = { | |
created: string; | ||
virusScannerResult: string; | ||
ID: string; | ||
fileSize: number; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters