mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AAE-3543] Attach button enabled only when all files uploaded (#6731)
* [AAE-3543] Attach button enabled only when all files uploaded * [AAE-3543] Add unit tests * [AAE-3543] Corrected name of unit test * [AAE-3543] Merged isQueueFinishedUploading() with isUploading() * [AAE-3543] Added spacing to unit tests
This commit is contained in:
@@ -80,7 +80,7 @@
|
||||
</button>
|
||||
|
||||
<button mat-button
|
||||
[disabled]="!hasNodeSelected()"
|
||||
[disabled]="isChooseButtonDisabled()"
|
||||
class="adf-choose-action"
|
||||
(click)="onClick()"
|
||||
data-automation-id="content-node-selector-actions-choose">{{ buttonActionName | translate }}
|
||||
|
@@ -17,7 +17,7 @@
|
||||
|
||||
import { Component, Inject, OnInit, ViewEncapsulation } from '@angular/core';
|
||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||
import { TranslationService, NotificationService, AllowableOperationsEnum, ContentService } from '@alfresco/adf-core';
|
||||
import { TranslationService, NotificationService, AllowableOperationsEnum, ContentService, UploadService } from '@alfresco/adf-core';
|
||||
import { Node } from '@alfresco/js-api';
|
||||
|
||||
import { ContentNodeSelectorComponentData } from './content-node-selector.component-data.interface';
|
||||
@@ -44,6 +44,7 @@ export class ContentNodeSelectorComponent implements OnInit {
|
||||
constructor(private translation: TranslationService,
|
||||
private contentService: ContentService,
|
||||
private notificationService: NotificationService,
|
||||
private uploadService: UploadService,
|
||||
private dialog: MatDialogRef<ContentNodeSelectorComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public data: ContentNodeSelectorComponentData) {
|
||||
this.action = data.actionName ? data.actionName.toUpperCase() : 'CHOOSE';
|
||||
@@ -107,6 +108,10 @@ export class ContentNodeSelectorComponent implements OnInit {
|
||||
this.notificationService.showError(error);
|
||||
}
|
||||
|
||||
isChooseButtonDisabled(): boolean {
|
||||
return this.uploadService.isUploading() || !this.hasNodeSelected();
|
||||
}
|
||||
|
||||
hasNodeSelected(): boolean {
|
||||
return this.chosenNode?.length > 0;
|
||||
}
|
||||
|
@@ -105,6 +105,41 @@ describe('UploadService', () => {
|
||||
expect(service.getQueue().length).toEqual(2);
|
||||
});
|
||||
|
||||
it('should not have the queue uploading if all files are complete, cancelled, aborted, errored or deleted', () => {
|
||||
const file1 = new FileModel(<File> { name: 'fake-file-1', size: 10 });
|
||||
const file2 = new FileModel(<File> { name: 'fake-file-2', size: 20 });
|
||||
const file3 = new FileModel(<File> { name: 'fake-file-3', size: 30 });
|
||||
const file4 = new FileModel(<File> { name: 'fake-file-4', size: 40 });
|
||||
const file5 = new FileModel(<File> { name: 'fake-file-5', size: 50 });
|
||||
|
||||
file1.status = FileUploadStatus.Complete;
|
||||
file2.status = FileUploadStatus.Cancelled;
|
||||
file3.status = FileUploadStatus.Aborted;
|
||||
file4.status = FileUploadStatus.Error;
|
||||
file5.status = FileUploadStatus.Deleted;
|
||||
|
||||
service.addToQueue(file1, file2, file3, file4, file5);
|
||||
|
||||
expect(service.isUploading()).toBe(false);
|
||||
});
|
||||
|
||||
it('should have the queue still uploading if some files are still pending, starting or in progress', () => {
|
||||
const file1 = new FileModel(<File> { name: 'fake-file-1', size: 10 });
|
||||
const file2 = new FileModel(<File> { name: 'fake-file-2', size: 20 });
|
||||
|
||||
service.addToQueue(file1, file2);
|
||||
|
||||
file1.status = FileUploadStatus.Complete;
|
||||
file2.status = FileUploadStatus.Pending;
|
||||
expect(service.isUploading()).toBe(true);
|
||||
|
||||
file2.status = FileUploadStatus.Starting;
|
||||
expect(service.isUploading()).toBe(true);
|
||||
|
||||
file2.status = FileUploadStatus.Progress;
|
||||
expect(service.isUploading()).toBe(true);
|
||||
});
|
||||
|
||||
it('should skip hidden macOS files', () => {
|
||||
const file1 = new FileModel(new File([''], '.git'));
|
||||
const file2 = new FileModel(new File([''], 'readme.md'));
|
||||
|
@@ -88,11 +88,14 @@ export class UploadService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the service is uploading a file.
|
||||
* @returns True if a file is uploading, false otherwise
|
||||
* Checks whether the service still has files uploading or awaiting upload.
|
||||
* @returns True if files in the queue are still uploading, false otherwise
|
||||
*/
|
||||
isUploading(): boolean {
|
||||
return !!this.activeTask;
|
||||
const finishedFileStates = [FileUploadStatus.Complete, FileUploadStatus.Cancelled, FileUploadStatus.Aborted, FileUploadStatus.Error, FileUploadStatus.Deleted];
|
||||
return this.queue.reduce((stillUploading: boolean, currentFile: FileModel) => {
|
||||
return stillUploading || finishedFileStates.indexOf(currentFile.status) === -1;
|
||||
}, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user