Skip to content

Commit

Permalink
Merge pull request #23 from raviprajapat/master
Browse files Browse the repository at this point in the history
Validation fix when file extension in uppercase
  • Loading branch information
Vugar authored Feb 5, 2020
2 parents d48290a + acfddb2 commit 6cbf07c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion projects/file-picker/src/lib/file-picker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
9 changes: 9 additions & 0 deletions projects/file-picker/src/lib/file-picker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6cbf07c

Please sign in to comment.