Skip to content
Snippets Groups Projects
Commit b74d6c93 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-6002 OZG-6018 clear stateresource on step change

parent dadcc4fb
No related branches found
No related tags found
No related merge requests found
...@@ -1520,4 +1520,14 @@ describe('BescheidService', () => { ...@@ -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());
});
});
}); });
...@@ -589,4 +589,8 @@ export class BescheidService { ...@@ -589,4 +589,8 @@ export class BescheidService {
public getUploadedAttachment(): Observable<StateResource<BinaryFileResource>> { public getUploadedAttachment(): Observable<StateResource<BinaryFileResource>> {
return this.uploadedAttachment$.asObservable(); return this.uploadedAttachment$.asObservable();
} }
public clearAttachmentUpload(): void {
this.uploadAttachmentInProgress$.next(createEmptyStateResource());
}
} }
import { BescheidLinkRel, BescheidResource, BescheidService } from '@alfa-client/bescheid-shared'; import { BescheidLinkRel, BescheidResource, BescheidService } from '@alfa-client/bescheid-shared';
import { CommandOrder, CommandResource } from '@alfa-client/command-shared'; import { CommandOrder, CommandResource } from '@alfa-client/command-shared';
import { import {
StateResource,
createEmptyStateResource, createEmptyStateResource,
createStateResource, createStateResource,
StateResource,
} from '@alfa-client/tech-shared'; } from '@alfa-client/tech-shared';
import { import {
Mock,
dispatchEventFromFixture, dispatchEventFromFixture,
existsAsHtmlElement, existsAsHtmlElement,
getElementFromFixture, getElementFromFixture,
Mock,
mock, mock,
notExistsAsHtmlElement, notExistsAsHtmlElement,
} from '@alfa-client/test-utils'; } from '@alfa-client/test-utils';
...@@ -213,32 +213,6 @@ describe('VorgangDetailBescheidenResultComponent', () => { ...@@ -213,32 +213,6 @@ describe('VorgangDetailBescheidenResultComponent', () => {
expect(bescheidService.getBescheidDocument).toHaveBeenCalled(); 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', () => { it('should call formservice to get current bescheid/formular', () => {
component.ngOnInit(); component.ngOnInit();
...@@ -263,6 +237,14 @@ describe('VorgangDetailBescheidenResultComponent', () => { ...@@ -263,6 +237,14 @@ describe('VorgangDetailBescheidenResultComponent', () => {
expect(bescheidService.getCreateBescheidDocumentInProgress).toHaveBeenCalled(); expect(bescheidService.getCreateBescheidDocumentInProgress).toHaveBeenCalled();
}); });
it('should get active step', () => {
component.getActiveStep = jest.fn();
component.ngOnInit();
expect(component.getActiveStep).toHaveBeenCalled();
});
describe('canSave$', () => { describe('canSave$', () => {
it('should emit true', () => { it('should emit true', () => {
bescheidService.getBescheidDraft.mockReturnValue( bescheidService.getBescheidDraft.mockReturnValue(
...@@ -620,21 +602,67 @@ describe('VorgangDetailBescheidenResultComponent', () => { ...@@ -620,21 +602,67 @@ describe('VorgangDetailBescheidenResultComponent', () => {
}); });
}); });
describe('ifNotLastStep', () => { describe('get active step', () => {
it.each([1, 2])('should do it in step %d', (step: number) => { it('should call formService', () => {
const doIt = jest.fn(); component.getActiveStep().pipe(first()).subscribe();
of(step).pipe(component.ifNotLastStep(doIt)).subscribe(); expect(formService.getActiveStep).toHaveBeenCalled();
});
it.each([1, 3])(
'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, 2])('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));
expect(doIt).toHaveBeenCalled(); component.getActiveStep().pipe(first()).subscribe();
expect(component.resetSend).not.toHaveBeenCalled();
});
});
}); });
it('should not do it in last step', () => { describe('reset send', () => {
const doIt = jest.fn(); it('should clear saveAndSendInProgress', (done) => {
component.saveAndSendInProgress$ = of(createCommandStateResource());
of(3).pipe(component.ifNotLastStep(doIt)).subscribe(); component.resetSend();
component.saveAndSendInProgress$
.pipe(first())
.subscribe((saveAndSendInProgress: StateResource<CommandResource>) => {
expect(saveAndSendInProgress).toEqual(createEmptyStateResource());
done();
});
});
it('should clear sendWithNachricht', () => {
component.sendWithNachricht$.next(createCommandStateResource());
component.resetSend();
expect(doIt).not.toHaveBeenCalled(); expect(component.sendWithNachricht$.value).toEqual(createEmptyStateResource());
}); });
}); });
}); });
...@@ -13,10 +13,10 @@ import { ...@@ -13,10 +13,10 @@ import {
switchMapCommandSuccessfullyDone, switchMapCommandSuccessfullyDone,
tapOnCommandSuccessfullyDone, tapOnCommandSuccessfullyDone,
} from '@alfa-client/command-shared'; } 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 { Component, EventEmitter, OnInit, Output } from '@angular/core';
import { hasLink, Resource } from '@ngxp/rest'; import { Resource, hasLink } from '@ngxp/rest';
import { BehaviorSubject, filter, map, Observable, of, OperatorFunction, tap } from 'rxjs'; import { BehaviorSubject, Observable, OperatorFunction, filter, map, of, tap } from 'rxjs';
import { BescheidenFormService } from '../bescheiden.formservice'; import { BescheidenFormService } from '../bescheiden.formservice';
type sendBescheid = ( type sendBescheid = (
...@@ -81,9 +81,7 @@ export class VorgangDetailBescheidenResultComponent implements OnInit { ...@@ -81,9 +81,7 @@ export class VorgangDetailBescheidenResultComponent implements OnInit {
this.bescheidService.getCreateBescheidDocumentInProgress(); this.bescheidService.getCreateBescheidDocumentInProgress();
this.bescheidDocument$ = this.bescheidService.getBescheidDocument(); this.bescheidDocument$ = this.bescheidService.getBescheidDocument();
this.activeStep$ = this.formService this.activeStep$ = this.getActiveStep();
.getActiveStep()
.pipe(this.ifNotLastStep(() => this.resetSend()));
this.bescheid$ = this.formService.getBescheidChanges(); this.bescheid$ = this.formService.getBescheidChanges();
this.sendByManual$ = this.formService.isSendByManual(); this.sendByManual$ = this.formService.isSendByManual();
...@@ -102,16 +100,22 @@ export class VorgangDetailBescheidenResultComponent implements OnInit { ...@@ -102,16 +100,22 @@ export class VorgangDetailBescheidenResultComponent implements OnInit {
this.showMissingBescheidDocumentError$ = this.formService.getShowMissingBescheidDocumentError(); this.showMissingBescheidDocumentError$ = this.formService.getShowMissingBescheidDocumentError();
} }
ifNotLastStep(doIt: () => void): OperatorFunction<number, number> { getActiveStep(): Observable<number> {
return (source: Observable<number>) => { return this.formService.getActiveStep().pipe(
return source.pipe(
tap((step: number) => { tap((step: number) => {
if (step < VorgangDetailBescheidenResultComponent.LAST_STEP) { if (this.isNotLast(step)) this.resetSend();
doIt(); if (this.shouldClearAttachmentInProgress(step))
} this.bescheidService.clearAttachmentUpload();
}), }),
); );
}; }
private isNotLast(step: number): boolean {
return step < VorgangDetailBescheidenResultComponent.LAST_STEP;
}
private shouldClearAttachmentInProgress(step: number): boolean {
return step != 2;
} }
resetSend(): void { resetSend(): void {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment