diff --git a/alfa-client/libs/bescheid-shared/src/lib/bescheid.service.spec.ts b/alfa-client/libs/bescheid-shared/src/lib/bescheid.service.spec.ts index 78fe8433b135b716b9882a8c4a7bf4cccd2fef0b..228b24efb9cd33d7d236fbb0a5b4a4499cee4169 100644 --- a/alfa-client/libs/bescheid-shared/src/lib/bescheid.service.spec.ts +++ b/alfa-client/libs/bescheid-shared/src/lib/bescheid.service.spec.ts @@ -1520,4 +1520,14 @@ describe('BescheidService', () => { }); }); }); + + describe('clear attachment upload', () => { + it('should clear stateresource', () => { + service.uploadAttachmentInProgress$.next(createStateResource(createUploadFileInProgress())); + + service.clearAttachmentUpload(); + + expect(service.uploadAttachmentInProgress$.value).toEqual(createEmptyStateResource()); + }); + }); }); diff --git a/alfa-client/libs/bescheid-shared/src/lib/bescheid.service.ts b/alfa-client/libs/bescheid-shared/src/lib/bescheid.service.ts index a8994d7ff2c9f8d74952af4e523dd240543e8929..76b74767032eac3979371d834d17c59217323600 100644 --- a/alfa-client/libs/bescheid-shared/src/lib/bescheid.service.ts +++ b/alfa-client/libs/bescheid-shared/src/lib/bescheid.service.ts @@ -589,4 +589,8 @@ export class BescheidService { public getUploadedAttachment(): Observable<StateResource<BinaryFileResource>> { return this.uploadedAttachment$.asObservable(); } + + public clearAttachmentUpload(): void { + this.uploadAttachmentInProgress$.next(createEmptyStateResource()); + } } diff --git a/alfa-client/libs/vorgang-detail/src/lib/vorgang-detail-page/vorgang-detail-bescheiden/vorgang-detail-bescheiden-result/vorgang-detail-bescheiden-result.component.spec.ts b/alfa-client/libs/vorgang-detail/src/lib/vorgang-detail-page/vorgang-detail-bescheiden/vorgang-detail-bescheiden-result/vorgang-detail-bescheiden-result.component.spec.ts index 63d46924cd75604ec3975f452e36034aecd854c0..b0b363829a8bbc5d1fc404163e0283f38115b4e4 100644 --- a/alfa-client/libs/vorgang-detail/src/lib/vorgang-detail-page/vorgang-detail-bescheiden/vorgang-detail-bescheiden-result/vorgang-detail-bescheiden-result.component.spec.ts +++ b/alfa-client/libs/vorgang-detail/src/lib/vorgang-detail-page/vorgang-detail-bescheiden/vorgang-detail-bescheiden-result/vorgang-detail-bescheiden-result.component.spec.ts @@ -1,15 +1,15 @@ import { BescheidLinkRel, BescheidResource, BescheidService } from '@alfa-client/bescheid-shared'; import { CommandOrder, CommandResource } from '@alfa-client/command-shared'; import { + StateResource, createEmptyStateResource, createStateResource, - StateResource, } from '@alfa-client/tech-shared'; import { + Mock, dispatchEventFromFixture, existsAsHtmlElement, getElementFromFixture, - Mock, mock, notExistsAsHtmlElement, } from '@alfa-client/test-utils'; @@ -213,32 +213,6 @@ describe('VorgangDetailBescheidenResultComponent', () => { expect(bescheidService.getBescheidDocument).toHaveBeenCalled(); }); - it('should call formservice to get active step', () => { - component.ngOnInit(); - - expect(formService.getActiveStep).toHaveBeenCalled(); - }); - - it.each([1, 2])('should reset save and send in progress in step %d', (step: number) => { - formService.getActiveStep.mockReturnValue(of(step)); - component.resetSend = jest.fn(); - - component.ngOnInit(); - - component.activeStep$.subscribe(); - expect(component.resetSend).toHaveBeenCalled(); - }); - - it('should not reset save and send in progress in last step', () => { - formService.getActiveStep.mockReturnValue(of(3)); - component.resetSend = jest.fn(); - - component.ngOnInit(); - - component.activeStep$.subscribe(); - expect(component.resetSend).not.toHaveBeenCalled(); - }); - it('should call formservice to get current bescheid/formular', () => { component.ngOnInit(); @@ -263,6 +237,14 @@ describe('VorgangDetailBescheidenResultComponent', () => { expect(bescheidService.getCreateBescheidDocumentInProgress).toHaveBeenCalled(); }); + it('should get active step', () => { + component.getActiveStep = jest.fn(); + + component.ngOnInit(); + + expect(component.getActiveStep).toHaveBeenCalled(); + }); + describe('canSave$', () => { it('should emit true', () => { bescheidService.getBescheidDraft.mockReturnValue( @@ -620,21 +602,70 @@ describe('VorgangDetailBescheidenResultComponent', () => { }); }); - describe('ifNotLastStep', () => { - it.each([1, 2])('should do it in step %d', (step: number) => { - const doIt = jest.fn(); + describe('get active step', () => { + it('should call formService', () => { + component.getActiveStep().pipe(first()).subscribe(); + + expect(formService.getActiveStep).toHaveBeenCalled(); + }); + + it.each([1, VorgangDetailBescheidenResultComponent.BESCHEID_VERSENDEN_STEP])( + 'should call bescheidService to clear attachment upload on step %s', + (step: number) => { + formService.getActiveStep.mockReturnValue(of(step)); + + component.getActiveStep().pipe(first()).subscribe(); + + expect(bescheidService.clearAttachmentUpload).toHaveBeenCalled(); + }, + ); + + describe('reset send', () => { + beforeEach(() => { + component.resetSend = jest.fn(); + }); + + it.each([1, VorgangDetailBescheidenResultComponent.ADD_DOCUMENTS_STEP])( + 'should be called on step %s', + (step: number) => { + formService.getActiveStep.mockReturnValue(of(step)); + + component.getActiveStep().pipe(first()).subscribe(); + + expect(component.resetSend).toHaveBeenCalled(); + }, + ); + + it('should not be called on last step', () => { + formService.getActiveStep.mockReturnValue(of(3)); + + component.getActiveStep().pipe(first()).subscribe(); + + expect(component.resetSend).not.toHaveBeenCalled(); + }); + }); + }); + + describe('reset send', () => { + it('should clear saveAndSendInProgress', (done) => { + component.saveAndSendInProgress$ = of(createCommandStateResource()); - of(step).pipe(component.ifNotLastStep(doIt)).subscribe(); + component.resetSend(); - expect(doIt).toHaveBeenCalled(); + component.saveAndSendInProgress$ + .pipe(first()) + .subscribe((saveAndSendInProgress: StateResource<CommandResource>) => { + expect(saveAndSendInProgress).toEqual(createEmptyStateResource()); + done(); + }); }); - it('should not do it in last step', () => { - const doIt = jest.fn(); + it('should clear sendWithNachricht', () => { + component.sendWithNachricht$.next(createCommandStateResource()); - of(3).pipe(component.ifNotLastStep(doIt)).subscribe(); + component.resetSend(); - expect(doIt).not.toHaveBeenCalled(); + expect(component.sendWithNachricht$.value).toEqual(createEmptyStateResource()); }); }); }); diff --git a/alfa-client/libs/vorgang-detail/src/lib/vorgang-detail-page/vorgang-detail-bescheiden/vorgang-detail-bescheiden-result/vorgang-detail-bescheiden-result.component.ts b/alfa-client/libs/vorgang-detail/src/lib/vorgang-detail-page/vorgang-detail-bescheiden/vorgang-detail-bescheiden-result/vorgang-detail-bescheiden-result.component.ts index 277c06197a06582d354c5f19e4985d97e7cef6c7..c46f6f7dc96be59c98c92990dec4f064045994cc 100644 --- a/alfa-client/libs/vorgang-detail/src/lib/vorgang-detail-page/vorgang-detail-bescheiden/vorgang-detail-bescheiden-result/vorgang-detail-bescheiden-result.component.ts +++ b/alfa-client/libs/vorgang-detail/src/lib/vorgang-detail-page/vorgang-detail-bescheiden/vorgang-detail-bescheiden-result/vorgang-detail-bescheiden-result.component.ts @@ -13,10 +13,10 @@ import { switchMapCommandSuccessfullyDone, tapOnCommandSuccessfullyDone, } from '@alfa-client/command-shared'; -import { createEmptyStateResource, isLoaded, StateResource } from '@alfa-client/tech-shared'; +import { StateResource, createEmptyStateResource, isLoaded } from '@alfa-client/tech-shared'; import { Component, EventEmitter, OnInit, Output } from '@angular/core'; -import { hasLink, Resource } from '@ngxp/rest'; -import { BehaviorSubject, filter, map, Observable, of, OperatorFunction, tap } from 'rxjs'; +import { Resource, hasLink } from '@ngxp/rest'; +import { BehaviorSubject, Observable, OperatorFunction, filter, map, of, tap } from 'rxjs'; import { BescheidenFormService } from '../bescheiden.formservice'; type sendBescheid = ( @@ -28,7 +28,8 @@ type sendBescheid = ( templateUrl: './vorgang-detail-bescheiden-result.component.html', }) export class VorgangDetailBescheidenResultComponent implements OnInit { - private static readonly LAST_STEP: number = 3; + static readonly ADD_DOCUMENTS_STEP: number = 2; + static readonly BESCHEID_VERSENDEN_STEP: number = 3; @Output() closeDialog: EventEmitter<void> = new EventEmitter(); @@ -81,9 +82,7 @@ export class VorgangDetailBescheidenResultComponent implements OnInit { this.bescheidService.getCreateBescheidDocumentInProgress(); this.bescheidDocument$ = this.bescheidService.getBescheidDocument(); - this.activeStep$ = this.formService - .getActiveStep() - .pipe(this.ifNotLastStep(() => this.resetSend())); + this.activeStep$ = this.getActiveStep(); this.bescheid$ = this.formService.getBescheidChanges(); this.sendByManual$ = this.formService.isSendByManual(); @@ -102,16 +101,23 @@ export class VorgangDetailBescheidenResultComponent implements OnInit { this.showMissingBescheidDocumentError$ = this.formService.getShowMissingBescheidDocumentError(); } - ifNotLastStep(doIt: () => void): OperatorFunction<number, number> { - return (source: Observable<number>) => { - return source.pipe( - tap((step: number) => { - if (step < VorgangDetailBescheidenResultComponent.LAST_STEP) { - doIt(); - } - }), - ); - }; + getActiveStep(): Observable<number> { + return this.formService + .getActiveStep() + .pipe(tap((step: number) => this.resetStateOnStepChange(step))); + } + + private resetStateOnStepChange(step: number): void { + if (this.isNotLast(step)) this.resetSend(); + if (this.shouldClearAttachmentInProgress(step)) this.bescheidService.clearAttachmentUpload(); + } + + private isNotLast(step: number): boolean { + return step < VorgangDetailBescheidenResultComponent.BESCHEID_VERSENDEN_STEP; + } + + private shouldClearAttachmentInProgress(step: number): boolean { + return step != VorgangDetailBescheidenResultComponent.ADD_DOCUMENTS_STEP; } resetSend(): void {