diff --git a/lib/content-services/upload/components/base-upload/upload-base.spec.ts b/lib/content-services/upload/components/base-upload/upload-base.spec.ts index 7d4df105e9..f106ea6db4 100644 --- a/lib/content-services/upload/components/base-upload/upload-base.spec.ts +++ b/lib/content-services/upload/components/base-upload/upload-base.spec.ts @@ -233,6 +233,59 @@ describe('UploadBase', () => { addToQueueSpy = spyOn(uploadService, 'addToQueue'); }); + it('should filter out file, when file type having white space in the beginning', () => { + component.acceptedFilesType = ' .jpg'; + + component.uploadFiles(files); + + const filesCalledWith = addToQueueSpy.calls.mostRecent().args; + expect(filesCalledWith.length).toBe(1, 'Files should contain only one element'); + expect(filesCalledWith[0].name).toBe('phobos.jpg', 'png file should be filtered out'); + }); + + it('should filter out file, when file types having white space in the beginning', () => { + component.acceptedFilesType = '.jpg, .png'; + + component.uploadFiles(files); + + const filesCalledWith = addToQueueSpy.calls.mostRecent().args; + expect(filesCalledWith.length).toBe(2, 'Files should contain two elements'); + expect(filesCalledWith[0].name).toBe('phobos.jpg'); + expect(filesCalledWith[1].name).toBe('deimos.png'); + }); + + it('should not filter out file, when file type having white space in the middle', () => { + component.acceptedFilesType = '.jpg, .p ng'; + + component.uploadFiles(files); + + const filesCalledWith = addToQueueSpy.calls.mostRecent().args; + expect(filesCalledWith.length).toBe(1, 'Files should contain only one element'); + expect(filesCalledWith[0].name).toBe('phobos.jpg', 'png file should be filtered out'); + }); + + it('should filter out file, when file types having white space in the end', () => { + component.acceptedFilesType = '.jpg ,.png '; + + component.uploadFiles(files); + + const filesCalledWith = addToQueueSpy.calls.mostRecent().args; + expect(filesCalledWith.length).toBe(2, 'Files should contain two elements'); + expect(filesCalledWith[0].name).toBe('phobos.jpg'); + expect(filesCalledWith[1].name).toBe('deimos.png'); + }); + + it('should filter out file, when file types not having space and dot', () => { + component.acceptedFilesType = 'jpg,png'; + + component.uploadFiles(files); + + const filesCalledWith = addToQueueSpy.calls.mostRecent().args; + expect(filesCalledWith.length).toBe(2, 'Files should contain two elements'); + expect(filesCalledWith[0].name).toBe('phobos.jpg'); + expect(filesCalledWith[1].name).toBe('deimos.png'); + }); + it('should filter out file, which is not part of the acceptedFilesType', () => { component.acceptedFilesType = '.jpg'; diff --git a/lib/content-services/upload/components/base-upload/upload-base.ts b/lib/content-services/upload/components/base-upload/upload-base.ts index 851af75698..477e95a85e 100644 --- a/lib/content-services/upload/components/base-upload/upload-base.ts +++ b/lib/content-services/upload/components/base-upload/upload-base.ts @@ -156,7 +156,7 @@ export abstract class UploadBase implements OnInit, OnDestroy { const allowedExtensions = this.acceptedFilesType .split(',') - .map((ext) => ext.replace(/^\./, '')); + .map((ext) => ext.trim().replace(/^\./, '')); if (allowedExtensions.indexOf(file.extension) !== -1) { return true;