From b481bde483d84e3ada2ab6f16e3567767e6b7262 Mon Sep 17 00:00:00 2001 From: Vito Date: Mon, 22 Jan 2018 17:52:02 +0100 Subject: [PATCH] [ADF-2170] fixed condition for file size equal zero (#2860) * [ADF-2170] fixed condition for file size equal zero * [ADF-2170] refactored if condition --- .../components/upload-button.component.spec.ts | 11 +++++++++++ .../upload/components/upload-button.component.ts | 14 +++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/content-services/upload/components/upload-button.component.spec.ts b/lib/content-services/upload/components/upload-button.component.spec.ts index d6f2b1b2c8..031631e819 100644 --- a/lib/content-services/upload/components/upload-button.component.spec.ts +++ b/lib/content-services/upload/components/upload-button.component.spec.ts @@ -216,6 +216,17 @@ describe('UploadButtonComponent', () => { expect(addToQueueSpy.calls.mostRecent()).toBeUndefined(); }); + it('should allow file of 0 size when the max file size is set to 0', () => { + const zeroFiles: File[] = [ + { name: 'zeroFile.png', size: 0 } + ]; + component.maxFilesSize = 0; + + component.uploadFiles(zeroFiles); + + expect(addToQueueSpy.calls.mostRecent()).toBeDefined(); + }); + it('should filter out all files if maxFilesSize is <0', () => { component.maxFilesSize = -2; diff --git a/lib/content-services/upload/components/upload-button.component.ts b/lib/content-services/upload/components/upload-button.component.ts index 59151e5dac..acc7fd38e2 100644 --- a/lib/content-services/upload/components/upload-button.component.ts +++ b/lib/content-services/upload/components/upload-button.component.ts @@ -201,7 +201,7 @@ export class UploadButtonComponent implements OnInit, OnChanges, NodePermissionS private isFileSizeAcceptable(file: FileModel): boolean { let acceptableSize = true; - if ((this.maxFilesSize !== undefined && this.maxFilesSize !== null ) && (this.maxFilesSize <= 0 || file.size > this.maxFilesSize)) { + if (this.isFileSizeAllowed(file)) { acceptableSize = false; this.translateService.get('FILE_UPLOAD.MESSAGES.EXCEED_MAX_FILE_SIZE', {fileName: file.name}).subscribe((message: string) => { @@ -212,6 +212,18 @@ export class UploadButtonComponent implements OnInit, OnChanges, NodePermissionS return acceptableSize; } + private isFileSizeAllowed(file: FileModel) { + return this.isMaxFileSizeDefined() && this.isFileSizeCorrect(file); + } + + private isMaxFileSizeDefined() { + return this.maxFilesSize !== undefined && this.maxFilesSize !== null; + } + + private isFileSizeCorrect(file: FileModel) { + return this.maxFilesSize < 0 || file.size > this.maxFilesSize; + } + checkPermission() { if (this.rootFolderId) { this.getFolderNode(this.rootFolderId).subscribe(