|
| 1 | +import { Utils } from "../../utils/utils"; |
| 2 | + |
| 3 | +describe('getFileExtension', () => { |
| 4 | + it('should return the file extension with dot', () => { |
| 5 | + const fileName = 'document.pdf'; |
| 6 | + const result = Utils.getFileExtension(fileName, false); |
| 7 | + expect(result).toBe('.pdf'); |
| 8 | + }); |
| 9 | + it('should return the file extension without dot', () => { |
| 10 | + const fileName = 'image.jpeg'; |
| 11 | + const result = Utils.getFileExtension(fileName, true); |
| 12 | + expect(result).toBe('jpeg'); |
| 13 | + }); |
| 14 | + it('should handle filenames with multiple dots', () => { |
| 15 | + const fileName = 'archive.tar.gz'; |
| 16 | + const resultWithDot = Utils.getFileExtension(fileName, false); |
| 17 | + const resultWithoutDot = Utils.getFileExtension(fileName, true); |
| 18 | + expect(resultWithDot).toBe('.gz'); |
| 19 | + expect(resultWithoutDot).toBe('gz'); |
| 20 | + }); |
| 21 | + it('should handle filenames with upper case extensions', () => { |
| 22 | + const fileName = 'movie.MP4'; |
| 23 | + const result = Utils.getFileExtension(fileName, true); |
| 24 | + expect(result).toBe('mp4'); |
| 25 | + }); |
| 26 | + it('should handle file name with special characters', () => { |
| 27 | + const fileName = '/repo/349d72de-e342-4461-a10a-45265c9cb4c2/raw/HEIC/arec4-j1qmq%20(1).heic'; |
| 28 | + const result = Utils.getFileExtension(fileName, true); |
| 29 | + expect(result).toBe('heic'); |
| 30 | + }); |
| 31 | +}); |
| 32 | + |
| 33 | +describe('bytesToSize', () => { |
| 34 | + it('should return empty string if bytes is undefined', () => { |
| 35 | + const result = Utils.bytesToSize(undefined); |
| 36 | + expect(result).toBe(' '); |
| 37 | + }); |
| 38 | + it('should return double dash if bytes is negative', () => { |
| 39 | + const result = Utils.bytesToSize(-1); |
| 40 | + expect(result).toBe('--'); |
| 41 | + }); |
| 42 | + it('should return bytes with unit if bytes is 0', () => { |
| 43 | + const result = Utils.bytesToSize(0); |
| 44 | + expect(result).toBe('0 B'); |
| 45 | + }); |
| 46 | + it('should return bytes with unit if bytes is positive', () => { |
| 47 | + const result = Utils.bytesToSize(1000); |
| 48 | + expect(result).toBe('1.0 KB'); |
| 49 | + }); |
| 50 | + it('should handle different units', () => { |
| 51 | + const result = Utils.bytesToSize(1000 * 1000); |
| 52 | + expect(result).toBe('1.0 MB'); |
| 53 | + }); |
| 54 | + it('should handle different units', () => { |
| 55 | + const result = Utils.bytesToSize(1000 * 1000 * 1000); |
| 56 | + expect(result).toBe('1.0 GB'); |
| 57 | + }); |
| 58 | + it('should handle different units', () => { |
| 59 | + const result = Utils.bytesToSize(1000 * 1000 * 1000 * 1000); |
| 60 | + expect(result).toBe('1.0 TB'); |
| 61 | + }); |
| 62 | +}); |
| 63 | + |
0 commit comments