|
| 1 | +import { isValid_File_Extension } from '../file-extension'; |
| 2 | + |
| 3 | +describe('File Extension Validation', () => { |
| 4 | + it('should return true for a valid file extension', () => { |
| 5 | + const fileName = 'document.pdf'; |
| 6 | + const allowedExtensions = ['pdf', 'doc', 'txt']; |
| 7 | + expect(isValid_File_Extension(fileName, allowedExtensions)).toBe(true); |
| 8 | + }); |
| 9 | + |
| 10 | + it('should return false for an invalid file extension', () => { |
| 11 | + const fileName = 'image.jpeg'; |
| 12 | + const allowedExtensions = ['pdf', 'doc', 'txt']; |
| 13 | + expect(isValid_File_Extension(fileName, allowedExtensions)).toBe(false); |
| 14 | + }); |
| 15 | + |
| 16 | + it('should return false for a file with no extension', () => { |
| 17 | + const fileName = 'file'; |
| 18 | + const allowedExtensions = ['pdf', 'doc', 'txt']; |
| 19 | + expect(isValid_File_Extension(fileName, allowedExtensions)).toBe(false); |
| 20 | + }); |
| 21 | + |
| 22 | + it('should return true for a valid file extension with mixed case', () => { |
| 23 | + const fileName = 'presentation.PPT'; |
| 24 | + const allowedExtensions = ['ppt', 'doc', 'txt']; |
| 25 | + expect(isValid_File_Extension(fileName, allowedExtensions)).toBe(true); |
| 26 | + }); |
| 27 | + |
| 28 | + it('should return false for an empty file name', () => { |
| 29 | + const fileName = ''; |
| 30 | + const allowedExtensions = ['pdf', 'doc', 'txt']; |
| 31 | + expect(isValid_File_Extension(fileName, allowedExtensions)).toBe(false); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should return false for an empty allowed extensions list', () => { |
| 35 | + const fileName = 'document.pdf'; |
| 36 | + const allowedExtensions: string[] = []; |
| 37 | + expect(isValid_File_Extension(fileName, allowedExtensions)).toBe(false); |
| 38 | + }); |
| 39 | +}); |
0 commit comments