From 70ce85602d2e071678366d047ba69e5cb9653e3a Mon Sep 17 00:00:00 2001 From: Eugenio Romano Date: Thu, 2 Nov 2017 10:43:38 +0000 Subject: [PATCH] [ADF-788] fix error negative and zero value for max file size (#2590) * fix error negative and zero value for max file size * fix null scenario --- .../components/upload-button.component.spec.ts | 16 ++++++++++++++++ .../src/components/upload-button.component.ts | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts index 8195dc9611..2d65528293 100644 --- a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts +++ b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts @@ -283,6 +283,22 @@ describe('UploadButtonComponent', () => { expect(filesCalledWith[0].name).toBe('smallFile.png'); }); + it('should filter out all files if maxFilesSize is 0', () => { + component.maxFilesSize = 0; + + component.uploadFiles(files); + + expect(addToQueueSpy.calls.mostRecent()).toBeUndefined(); + }); + + it('should filter out all files if maxFilesSize is <0', () => { + component.maxFilesSize = -2; + + component.uploadFiles(files); + + expect(addToQueueSpy.calls.mostRecent()).toBeUndefined(); + }); + it('should output an error when you try to upload a file too big', (done) => { component.maxFilesSize = 100; diff --git a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.ts b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.ts index fe4118b008..bbf2170ba8 100644 --- a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.ts +++ b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.ts @@ -225,7 +225,7 @@ export class UploadButtonComponent implements OnInit, OnChanges, NodePermissionS private isFileSizeAcceptable(file: FileModel): boolean { let acceptableSize = true; - if (this.maxFilesSize && file.size > this.maxFilesSize) { + if ((this.maxFilesSize !== undefined && this.maxFilesSize !== null ) && (this.maxFilesSize <= 0 || file.size > this.maxFilesSize)) { acceptableSize = false; this.translateService.get('FILE_UPLOAD.MESSAGES.EXCEED_MAX_FILE_SIZE', {fileName: file.name}).subscribe((message: string) => {