From acfddb25530110f29d623e6bca3da74e42d996dc Mon Sep 17 00:00:00 2001 From: raviprajapat Date: Tue, 4 Feb 2020 22:52:30 +0530 Subject: [PATCH] When file extension in uppercase validation fix --- projects/file-picker/src/lib/file-picker.component.ts | 2 +- projects/file-picker/src/lib/file-picker.spec.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/projects/file-picker/src/lib/file-picker.component.ts b/projects/file-picker/src/lib/file-picker.component.ts index dbd5fb5..701a88e 100644 --- a/projects/file-picker/src/lib/file-picker.component.ts +++ b/projects/file-picker/src/lib/file-picker.component.ts @@ -294,7 +294,7 @@ export class FilePickerComponent implements OnInit, OnDestroy { isValidExtension(file: File, fileName: string): boolean { if (!this.fileExtensions) {return true; } const extension = fileName.split('.').pop(); - if (this.fileExtensions && (!this.fileExtensions.includes(extension))) { + if (this.fileExtensions && (!this.fileExtensions.toLowerCase().includes(extension.toLowerCase()))) { this.validationError.next({file: file, error: FileValidationTypes.extensions}); return false; } diff --git a/projects/file-picker/src/lib/file-picker.spec.ts b/projects/file-picker/src/lib/file-picker.spec.ts index 0689e3c..4725b64 100644 --- a/projects/file-picker/src/lib/file-picker.spec.ts +++ b/projects/file-picker/src/lib/file-picker.spec.ts @@ -139,6 +139,15 @@ describe('FilePickerComponent', () => { expect(res).toBe(false); expect(component.validationError.next).toHaveBeenCalledWith({file: file, error: FileValidationTypes.extensions}); +}); +it('should isValidMaxExtension work if file extension in uppercase', () => { + component.fileExtensions = 'png'; + spyOn(component.validationError, 'next'); + const file = createMockFile('demo2.PNG', 'image/png'); + const res = component.isValidExtension(file, file.name); + expect(res).toBe(true); + expect(component.validationError.next).not.toHaveBeenCalled(); + }); it('should isValidMaxFileCount work', () => { component.fileMaxCount = 1;