[ACS-8994] the upload new version button is not disabled when clicked and the uploading starts (#10391)

* [ACS-8994] Disable upload button when new version is uploading

* [ACS-8994] Disable upload button when new version is uploading
This commit is contained in:
AleksanderSklorz 2024-11-18 14:19:55 +01:00 committed by GitHub
parent 3adccc132e
commit cbb5f14473
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 73 additions and 29 deletions

View File

@ -5,6 +5,7 @@
<!--Single Files Upload--> <!--Single Files Upload-->
<ng-container *ngIf="!multipleFiles"> <ng-container *ngIf="!multipleFiles">
<input <input
class="adf-upload-button-file-container-upload-single-file"
id="upload-single-file" id="upload-single-file"
data-automation-id="upload-single-file" data-automation-id="upload-single-file"
[type]="file ? 'button' : 'file'" [type]="file ? 'button' : 'file'"

View File

@ -24,4 +24,11 @@
box-shadow: 0 5px 5px -3px #0003, 0 8px 10px 1px rgba(0, 0, 0, 0.14), 0 3px 14px 2px rgba(0, 0, 0, 0.12); box-shadow: 0 5px 5px -3px #0003, 0 8px 10px 1px rgba(0, 0, 0, 0.14), 0 3px 14px 2px rgba(0, 0, 0, 0.12);
} }
} }
&-upload-button-file-container-upload-single-file[disabled] + &-upload-button-label {
background-color: var(--adf-disabled-button-background);
color: var(--adf-theme-foreground-disabled-text-color);
box-shadow: none;
cursor: default;
}
} }

View File

@ -22,6 +22,9 @@ import { ContentTestingModule } from '../testing/content.testing.module';
import { Node } from '@alfresco/js-api'; import { Node } from '@alfresco/js-api';
import { UploadService } from '../common/services/upload.service'; import { UploadService } from '../common/services/upload.service';
import { ContentService } from '../common/services/content.service'; import { ContentService } from '../common/services/content.service';
import { Subject } from 'rxjs';
import { FileUploadErrorEvent, FileUploadEvent, UploadVersionButtonComponent } from '@alfresco/adf-content-services';
import { By } from '@angular/platform-browser';
describe('VersionUploadComponent', () => { describe('VersionUploadComponent', () => {
let component: VersionUploadComponent; let component: VersionUploadComponent;
@ -58,40 +61,12 @@ describe('VersionUploadComponent', () => {
contentService = TestBed.inject(ContentService); contentService = TestBed.inject(ContentService);
spyOn(contentService, 'hasAllowableOperations').and.returnValue(true); spyOn(contentService, 'hasAllowableOperations').and.returnValue(true);
component.node = node; component.node = node;
fixture.detectChanges();
}); });
afterEach(() => { afterEach(() => {
fixture.destroy(); fixture.destroy();
}); });
it('should disabled upload button on upload starts', () => {
component.uploadStarted.subscribe(() => {
expect(component.disabled).toEqual(true);
});
uploadService.fileUploadStarting.next(undefined);
});
it('should enable upload button on error', () => {
spyOn(component, 'canUpload').and.returnValue(true);
component.error.subscribe(() => {
expect(component.disabled).toEqual(false);
});
component.onError({} as any);
fixture.detectChanges();
});
it('should enable upload button on success', () => {
spyOn(component, 'canUpload').and.returnValue(true);
component.success.subscribe(() => {
expect(component.disabled).toEqual(false);
});
component.onSuccess(true);
fixture.detectChanges();
});
it('should update next major version', () => { it('should update next major version', () => {
let majorVersion = component.getNextMajorVersion('1.0'); let majorVersion = component.getNextMajorVersion('1.0');
expect(majorVersion).toEqual('2.0'); expect(majorVersion).toEqual('2.0');
@ -105,4 +80,64 @@ describe('VersionUploadComponent', () => {
minorVersion = component.getNextMinorVersion('1.10'); minorVersion = component.getNextMinorVersion('1.10');
expect(minorVersion).toEqual('1.11'); expect(minorVersion).toEqual('1.11');
}); });
describe('Upload version button', () => {
let uploadVersionButtonComponent: UploadVersionButtonComponent;
let upload$: Subject<FileUploadEvent>;
let uploadEvent: FileUploadEvent;
beforeEach(() => {
upload$ = new Subject<FileUploadEvent>();
uploadService.fileUploadStarting = upload$;
fixture.detectChanges();
uploadVersionButtonComponent = fixture.debugElement.query(By.directive(UploadVersionButtonComponent)).componentInstance;
uploadEvent = {
file: {
name: 'some file'
}
} as FileUploadEvent;
spyOn(component.uploadStarted, 'emit');
upload$.next(uploadEvent);
fixture.detectChanges();
});
it('should be disabled when uploading', () => {
expect(uploadVersionButtonComponent.disabled).toBeTrue();
});
it('should be disabled when uploading is successful', () => {
uploadVersionButtonComponent.success.next({});
fixture.detectChanges();
expect(uploadVersionButtonComponent.disabled).toBeTrue();
});
it('should be enabled when uploading is failed', () => {
uploadVersionButtonComponent.error.next({} as FileUploadErrorEvent);
fixture.detectChanges();
expect(uploadVersionButtonComponent.disabled).toBeFalse();
});
it('should be emitted uploadStarted when started uploading', () => {
expect(component.uploadStarted.emit).toHaveBeenCalledWith(uploadEvent);
});
it('should be emitted success when uploading is successful', () => {
spyOn(component.success, 'emit');
uploadVersionButtonComponent.success.next({});
fixture.detectChanges();
expect(component.success.emit).toHaveBeenCalledWith({});
});
it('should be emitted error when uploading is failed', () => {
spyOn(component.error, 'emit');
const errorEvent = {
error: 'Some error'
} as FileUploadErrorEvent;
uploadVersionButtonComponent.error.next(errorEvent);
fixture.detectChanges();
expect(component.error.emit).toHaveBeenCalledWith(errorEvent);
});
});
}); });

View File

@ -138,7 +138,6 @@ export class VersionUploadComponent implements OnInit, OnDestroy {
} }
onSuccess(event: any) { onSuccess(event: any) {
this.disabled = false;
this.success.emit(event); this.success.emit(event);
} }

View File

@ -89,6 +89,7 @@
--adf-error-color: $adf-error-color, --adf-error-color: $adf-error-color,
--adf-secondary-button-background: $adf-secondary-button-background, --adf-secondary-button-background: $adf-secondary-button-background,
--adf-secondary-modal-text-color: $adf-secondary-modal-text-color, --adf-secondary-modal-text-color: $adf-secondary-modal-text-color,
--adf-disabled-button-background: $adf-disabled-button-background,
--adf-display-external-property-widget-preview-selection-color: mat.get-color-from-palette($foreground, secondary-text) --adf-display-external-property-widget-preview-selection-color: mat.get-color-from-palette($foreground, secondary-text)
); );

View File

@ -28,3 +28,4 @@ $adf-ref-header-icon-border-radius: 50%;
$adf-error-color: #ba1b1b; $adf-error-color: #ba1b1b;
$adf-secondary-button-background: #2121210d; $adf-secondary-button-background: #2121210d;
$adf-secondary-modal-text-color: #212121; $adf-secondary-modal-text-color: #212121;
$adf-disabled-button-background: rgba(0, 0, 0, 0.12);