Skip to content
Snippets Groups Projects
Verified Commit 6af99c53 authored by Sebastian Bergandy's avatar Sebastian Bergandy :keyboard:
Browse files

OZG-5977 set loading on multi upload button

parent e3458f51
No related branches found
No related tags found
1 merge request!67OZG-5977 add multi option to file upload button
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
[accept]="accept" [accept]="accept"
[attr.data-test-id]="(label | convertForDataTest) + '-file-upload-button'" [attr.data-test-id]="(label | convertForDataTest) + '-file-upload-button'"
[multi]="true" [multi]="true"
[isLoading]="false" [isLoading]="isUploadInProgress$ | async"
class="relative w-72" class="relative w-72"
> >
<ods-spinner-icon spinner size="medium" /> <ods-spinner-icon spinner size="medium" />
......
...@@ -30,7 +30,9 @@ import { getUrl, Resource } from '@ngxp/rest'; ...@@ -30,7 +30,9 @@ import { getUrl, Resource } from '@ngxp/rest';
import { FileUploadButtonComponent, SpinnerIconComponent } from '@ods/system'; import { FileUploadButtonComponent, SpinnerIconComponent } from '@ods/system';
import { getDataTestIdOf } from 'libs/tech-shared/test/data-test'; import { getDataTestIdOf } from 'libs/tech-shared/test/data-test';
import { MockComponent } from 'ng-mocks'; import { MockComponent } from 'ng-mocks';
import { of } from 'rxjs';
import { createFileList } from '../../../../tech-shared/test/file'; import { createFileList } from '../../../../tech-shared/test/file';
import { singleColdCompleted } from '../../../../tech-shared/test/marbles';
import { createDummyResource } from '../../../../tech-shared/test/resource'; import { createDummyResource } from '../../../../tech-shared/test/resource';
import { MultiFileUploadEditorComponent } from './multi-file-upload-editor.component'; import { MultiFileUploadEditorComponent } from './multi-file-upload-editor.component';
...@@ -49,6 +51,15 @@ describe('MultiFileUploadEditorComponent', () => { ...@@ -49,6 +51,15 @@ describe('MultiFileUploadEditorComponent', () => {
binaryFileService = mock(BinaryFileService); binaryFileService = mock(BinaryFileService);
}); });
function createComponent(): void {
fixture = TestBed.createComponent(MultiFileUploadEditorComponent);
component = fixture.componentInstance;
component.uploadResource = uploadResource;
component.uploadLinkRelation = uploadLinkRel;
component.label = 'Ein Label';
fixture.detectChanges();
}
beforeEach(async () => { beforeEach(async () => {
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({
declarations: [ declarations: [
...@@ -64,15 +75,8 @@ describe('MultiFileUploadEditorComponent', () => { ...@@ -64,15 +75,8 @@ describe('MultiFileUploadEditorComponent', () => {
}, },
], ],
}).compileComponents(); }).compileComponents();
});
beforeEach(() => { createComponent();
fixture = TestBed.createComponent(MultiFileUploadEditorComponent);
component = fixture.componentInstance;
component.uploadResource = uploadResource;
component.uploadLinkRelation = uploadLinkRel;
component.label = 'Ein Label';
fixture.detectChanges();
}); });
describe('component', () => { describe('component', () => {
...@@ -80,6 +84,14 @@ describe('MultiFileUploadEditorComponent', () => { ...@@ -80,6 +84,14 @@ describe('MultiFileUploadEditorComponent', () => {
expect(component).toBeTruthy(); expect(component).toBeTruthy();
}); });
it('should set initial values', () => {
binaryFileService.isUploadInProgress = jest.fn().mockReturnValue(of(true));
createComponent();
expect(component.isUploadInProgress$).toBeObservable(singleColdCompleted(true));
});
describe('onFilesUpload', () => { describe('onFilesUpload', () => {
beforeEach(() => { beforeEach(() => {
component._uploadFiles = jest.fn(); component._uploadFiles = jest.fn();
...@@ -122,12 +134,14 @@ describe('MultiFileUploadEditorComponent', () => { ...@@ -122,12 +134,14 @@ describe('MultiFileUploadEditorComponent', () => {
}); });
it('should have inputs', () => { it('should have inputs', () => {
binaryFileService.isUploadInProgress = jest.fn().mockReturnValue(of(true));
createComponent();
const fileButtonComponent: FileUploadButtonComponent = getElementComponentFromFixtureByCss(fixture, buttonTestId); const fileButtonComponent: FileUploadButtonComponent = getElementComponentFromFixtureByCss(fixture, buttonTestId);
expect(fileButtonComponent.id).toEqual(component.uploadButtonId); expect(fileButtonComponent.id).toEqual(component.uploadButtonId);
expect(fileButtonComponent.accept).toEqual(component.accept); expect(fileButtonComponent.accept).toEqual(component.accept);
expect(fileButtonComponent.multi).toEqual(true); expect(fileButtonComponent.multi).toEqual(true);
expect(fileButtonComponent.isLoading).toEqual(false); expect(fileButtonComponent.isLoading).toEqual(true);
}); });
}); });
}); });
...@@ -23,13 +23,16 @@ ...@@ -23,13 +23,16 @@
*/ */
import { BinaryFileModule } from '@alfa-client/binary-file'; import { BinaryFileModule } from '@alfa-client/binary-file';
import { BinaryFileService, FileUploadType } from '@alfa-client/binary-file-shared'; import { BinaryFileService, FileUploadType } from '@alfa-client/binary-file-shared';
import { KOMMENTAR_UPLOADED_ATTACHMENTS } from '@alfa-client/kommentar-shared';
import { TechSharedModule } from '@alfa-client/tech-shared'; import { TechSharedModule } from '@alfa-client/tech-shared';
import { AsyncPipe } from '@angular/common';
import { Component, HostListener, inject, Input } from '@angular/core'; import { Component, HostListener, inject, Input } from '@angular/core';
import { ControlContainer, FormGroupDirective, ReactiveFormsModule } from '@angular/forms'; import { ControlContainer, FormGroupDirective, ReactiveFormsModule } from '@angular/forms';
import { getUrl, Resource } from '@ngxp/rest'; import { getUrl, Resource } from '@ngxp/rest';
import { FormControlEditorAbstractComponent } from '@ods/component'; import { FormControlEditorAbstractComponent } from '@ods/component';
import { AttachmentIconComponent, FileUploadButtonComponent, SpinnerIconComponent } from '@ods/system'; import { AttachmentIconComponent, FileUploadButtonComponent, SpinnerIconComponent } from '@ods/system';
import { uniqueId } from 'lodash-es'; import { uniqueId } from 'lodash-es';
import { Observable } from 'rxjs';
@Component({ @Component({
selector: 'ods-multi-file-upload-editor', selector: 'ods-multi-file-upload-editor',
...@@ -43,6 +46,7 @@ import { uniqueId } from 'lodash-es'; ...@@ -43,6 +46,7 @@ import { uniqueId } from 'lodash-es';
ReactiveFormsModule, ReactiveFormsModule,
TechSharedModule, TechSharedModule,
BinaryFileModule, BinaryFileModule,
AsyncPipe,
], ],
}) })
export class MultiFileUploadEditorComponent extends FormControlEditorAbstractComponent { export class MultiFileUploadEditorComponent extends FormControlEditorAbstractComponent {
...@@ -54,9 +58,13 @@ export class MultiFileUploadEditorComponent extends FormControlEditorAbstractCom ...@@ -54,9 +58,13 @@ export class MultiFileUploadEditorComponent extends FormControlEditorAbstractCom
private readonly binaryFileService: BinaryFileService = inject(BinaryFileService); private readonly binaryFileService: BinaryFileService = inject(BinaryFileService);
public isUploadInProgress$: Observable<boolean> = this.binaryFileService.isUploadInProgress(KOMMENTAR_UPLOADED_ATTACHMENTS);
public readonly uploadButtonId: string = uniqueId(); public readonly uploadButtonId: string = uniqueId();
@HostListener('change', ['$event.target.files']) onFilesUpload(fileList: FileList): void { @HostListener('change', ['$event.target.files'])
public onFilesUpload(fileList: FileList): void {
this.binaryFileService.isUploadInProgress(KOMMENTAR_UPLOADED_ATTACHMENTS).subscribe(console.info);
this._uploadFiles(fileList); this._uploadFiles(fileList);
this.setErrors(); this.setErrors();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment