mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-4838] Upload Dialog - canceling a pending file cancels the file in progress (#5063)
* add automation id * call cancel upload api only if file is not pending * tests * e2e
This commit is contained in:
committed by
Eugenio Romano
parent
4de00fd6ca
commit
5b9f37d01f
@@ -82,6 +82,7 @@
|
||||
mat-icon-button
|
||||
*ngIf="file.status === FileUploadStatus.Pending"
|
||||
(click)="onCancel(file)"
|
||||
data-automation-id="cancel-upload-queue"
|
||||
class="adf-file-uploading-row__group"
|
||||
title="{{ 'ADF_FILE_UPLOAD.BUTTON.CANCEL_FILE' | translate }}"
|
||||
[attr.aria-label]="'ADF_FILE_UPLOAD.ARIA-LABEL.CANCEL_FILE' | translate: { file: file.name }">
|
||||
|
@@ -62,11 +62,25 @@ describe('FileUploadingListComponent', () => {
|
||||
});
|
||||
|
||||
describe('cancelFile()', () => {
|
||||
it('should call uploadService api when cancelling a file', () => {
|
||||
it('should call cancelUpload service when cancelling a file', () => {
|
||||
component.cancelFile(file);
|
||||
|
||||
expect(uploadService.cancelUpload).toHaveBeenCalledWith(file);
|
||||
});
|
||||
|
||||
it('should not call cancelUpload service when file has `Pending` status', () => {
|
||||
file.status = FileUploadStatus.Pending;
|
||||
component.cancelFile(file);
|
||||
|
||||
expect(uploadService.cancelUpload).not.toHaveBeenCalledWith(file);
|
||||
});
|
||||
|
||||
it('should set `Cancelled` status on `Pending` file', () => {
|
||||
file.status = FileUploadStatus.Pending;
|
||||
component.cancelFile(file);
|
||||
|
||||
expect(file.status).toBe(FileUploadStatus.Cancelled);
|
||||
});
|
||||
});
|
||||
|
||||
describe('removeFile()', () => {
|
||||
@@ -106,6 +120,40 @@ describe('FileUploadingListComponent', () => {
|
||||
expect(uploadService.cancelUpload).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should set `Deleted` status on file version instances when original is removed', () => {
|
||||
component.files = <any> [
|
||||
{
|
||||
data: {
|
||||
entry: { id: 'nodeId' }
|
||||
},
|
||||
name: 'file',
|
||||
status: FileUploadStatus.Complete,
|
||||
options: {
|
||||
newVersion: false
|
||||
}
|
||||
},
|
||||
{
|
||||
data: {
|
||||
entry: { id: 'nodeId' }
|
||||
},
|
||||
name: 'file_v1',
|
||||
status: FileUploadStatus.Complete,
|
||||
options: {
|
||||
newVersion: true
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
spyOn(nodesApiService, 'deleteNode').and.returnValue(of(component.files[0]));
|
||||
|
||||
component.removeFile(component.files[0]);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(nodesApiService.deleteNode).toHaveBeenCalledTimes(1);
|
||||
expect(component.files[0].status).toBe(FileUploadStatus.Deleted);
|
||||
expect(component.files[1].status).toBe(FileUploadStatus.Deleted);
|
||||
});
|
||||
|
||||
describe('Events', () => {
|
||||
|
||||
it('should throw an error event if delete file goes wrong', (done) => {
|
||||
|
@@ -65,7 +65,11 @@ export class FileUploadingListComponent {
|
||||
* @memberOf FileUploadingListComponent
|
||||
*/
|
||||
cancelFile(file: FileModel): void {
|
||||
this.uploadService.cancelUpload(file);
|
||||
if (file.status === FileUploadStatus.Pending) {
|
||||
file.status = FileUploadStatus.Cancelled;
|
||||
} else {
|
||||
this.uploadService.cancelUpload(file);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,8 +165,9 @@ export class FileUploadingListComponent {
|
||||
this.files
|
||||
.filter(
|
||||
(item) =>
|
||||
item.data.entry.id === file.data.entry.id &&
|
||||
item.options.newVersion
|
||||
item.options.newVersion &&
|
||||
item.data.entry.id === file.data.entry.id
|
||||
|
||||
)
|
||||
.map((item) => {
|
||||
item.status = FileUploadStatus.Deleted;
|
||||
|
Reference in New Issue
Block a user