diff --git a/alfa-client/libs/bescheid/src/lib/bescheid-wizard-container/bescheid-wizard-container.component.spec.ts b/alfa-client/libs/bescheid/src/lib/bescheid-wizard-container/bescheid-wizard-container.component.spec.ts index 0df9793aaeeb7ce841140f74b7bfd14b11e8a507..f66a3d6c7ae58141aefeaa88d342e2e06b0a0109 100644 --- a/alfa-client/libs/bescheid/src/lib/bescheid-wizard-container/bescheid-wizard-container.component.spec.ts +++ b/alfa-client/libs/bescheid/src/lib/bescheid-wizard-container/bescheid-wizard-container.component.spec.ts @@ -58,6 +58,7 @@ describe('BescheidWizardContainerComponent', () => { bescheidService = mock(BescheidService); ozgcloudDialogService = mock(OzgcloudDialogService); formService = new BescheidFormService(new UntypedFormBuilder(), useFromMock(bescheidService)); + formService.patchValues = jest.fn(); wizardDialogRef = new DialogRefMock(); }); @@ -118,6 +119,12 @@ describe('BescheidWizardContainerComponent', () => { }); describe('ngOnInit', () => { + it('should init bescheid service', () => { + component.ngOnInit(); + + expect(bescheidService.init).toHaveBeenCalled(); + }); + it('should set vorgang with eingang on form service', () => { formService.setVorgangWithEingangResource = jest.fn(); @@ -174,9 +181,15 @@ describe('BescheidWizardContainerComponent', () => { ); }); - it('should patch form values', () => { - formService.patchValues = jest.fn(); + it('should set bescheid state resource', () => { + component.subscribeToBescheidResource(); + component.bescheidDraftStateResource$.subscribe(); + + expect(component.bescheidStateResource).toEqual(bescheidDraftStateResource); + }); + + it('should patch form values', () => { component.subscribeToBescheidResource(); component.bescheidDraftStateResource$.subscribe(); @@ -204,8 +217,6 @@ describe('BescheidWizardContainerComponent', () => { }); it('should not patch form values', () => { - formService.patchValues = jest.fn(); - component.subscribeToBescheidResource(); expect(formService.patchValues).not.toHaveBeenCalled(); @@ -318,7 +329,7 @@ describe('BescheidWizardContainerComponent', () => { }); }); - describe('dialog canceled', () => { + describe('dialog cancelled', () => { beforeEach(() => { cancelDialogRef = new DialogRefMock(); const value = createDialogCancelResult(); @@ -358,9 +369,9 @@ describe('BescheidWizardContainerComponent', () => { component.cancelWizard = jest.fn(); }); - it('should close wizard if bescheid resource loaded', () => { + it('should cancel wizard if bescheid resource loaded', () => { const bescheidResource: BescheidResource = createBescheidResource(); - component.bescheidDraftStateResource$ = of(createStateResource(bescheidResource)); + component.bescheidStateResource = createStateResource(bescheidResource); wizardDialogRef.keydownEvents = of(createKeydownKeyboardEvent(ESCAPE_KEY)); component.handleEscapeKey(); @@ -368,7 +379,7 @@ describe('BescheidWizardContainerComponent', () => { expect(component.cancelWizard).toHaveBeenCalledWith(bescheidResource); }); - it('should close wizard if bescheid resource not exists', () => { + it('should cancel wizard if bescheid resource not exists', () => { component.bescheidDraftStateResource$ = of(createEmptyStateResource<BescheidResource>()); wizardDialogRef.keydownEvents = of(createKeydownKeyboardEvent(ESCAPE_KEY)); @@ -377,7 +388,7 @@ describe('BescheidWizardContainerComponent', () => { expect(component.cancelWizard).toHaveBeenCalledWith(null); }); - it('should not close if no escape key pressed', () => { + it('should not cancel if no escape key pressed', () => { const bescheidResource: BescheidResource = createBescheidResource(); component.bescheidDraftStateResource$ = of(createStateResource(bescheidResource)); wizardDialogRef.keydownEvents = of(createKeydownKeyboardEvent('a')); @@ -387,9 +398,9 @@ describe('BescheidWizardContainerComponent', () => { expect(component.cancelWizard).not.toHaveBeenCalled(); }); - it('should not close if bescheid resource loading', () => { + it('should not cancel if bescheid resource loading', () => { const bescheidResource: BescheidResource = createBescheidResource(); - component.bescheidDraftStateResource$ = of(createStateResource(bescheidResource, true)); + component.bescheidStateResource = createStateResource(bescheidResource, true); wizardDialogRef.keydownEvents = of(createKeydownKeyboardEvent(ESCAPE_KEY)); component.handleEscapeKey(); diff --git a/alfa-client/libs/bescheid/src/lib/bescheid-wizard-container/bescheid-wizard-container.component.ts b/alfa-client/libs/bescheid/src/lib/bescheid-wizard-container/bescheid-wizard-container.component.ts index fb336bac999e9e0a6e7ce799a060f60cdcedafef..acdcd13501fda10ff1f4ed22dc6750ba5293ce26 100644 --- a/alfa-client/libs/bescheid/src/lib/bescheid-wizard-container/bescheid-wizard-container.component.ts +++ b/alfa-client/libs/bescheid/src/lib/bescheid-wizard-container/bescheid-wizard-container.component.ts @@ -11,10 +11,10 @@ import { VorgangWithEingangLinkRel, VorgangWithEingangResource } from '@alfa-cli import { DIALOG_DATA, DialogRef } from '@angular/cdk/dialog'; import { Component, Inject, OnDestroy, OnInit, ViewContainerRef } from '@angular/core'; import { hasLink } from '@ngxp/rest'; -import { Observable, Subscription, filter, first, of, switchMap, tap } from 'rxjs'; +import { Observable, Subscription, filter, first, map, of, tap } from 'rxjs'; import { OzgcloudDialogCommandResult, - isDialogCanceled, + isDialogCancelled, isDialogSuccessfullyCompleted, } from '../../../../ui/src/lib/ui/ozgcloud-dialog/ozgcloud-dialog.result'; import { @@ -38,6 +38,7 @@ export class BescheidWizardContainerComponent implements OnInit, OnDestroy { ); public activeStep: number = 1; + bescheidStateResource: StateResource<BescheidResource> = createEmptyStateResource(); isCancelDialogOpen: boolean = false; vorgangWithEingangResource: VorgangWithEingangResource; keydownEventsSubscription: Subscription; @@ -54,6 +55,7 @@ export class BescheidWizardContainerComponent implements OnInit, OnDestroy { } ngOnInit(): void { + this.bescheidService.init(); this.formService.setVorgangWithEingangResource(this.vorgangWithEingangResource); this.subscribeToBescheidResource(); this.handleEscapeKey(); @@ -67,6 +69,7 @@ export class BescheidWizardContainerComponent implements OnInit, OnDestroy { if (hasLink(this.vorgangWithEingangResource, VorgangWithEingangLinkRel.BESCHEID_DRAFT)) { this.bescheidDraftStateResource$ = this.bescheidService.getBescheidDraft().pipe( tap((bescheidDraftStateResource: StateResource<BescheidResource>) => { + this.bescheidStateResource = bescheidDraftStateResource; if (isLoaded(bescheidDraftStateResource)) { this.formService.patchValues(bescheidDraftStateResource.resource); } @@ -79,7 +82,7 @@ export class BescheidWizardContainerComponent implements OnInit, OnDestroy { this.keydownEventsSubscription = this.dialogRef.keydownEvents .pipe( filter(isEscapeKey), - switchMap(() => this.bescheidDraftStateResource$), + map(() => this.bescheidStateResource), filter(isNotLoading), ) .subscribe((bescheidStateResource: StateResource<BescheidResource>) => { @@ -120,7 +123,7 @@ export class BescheidWizardContainerComponent implements OnInit, OnDestroy { this.bescheidService.reloadDependentResources(); this.dialogRef.close(); } - if (isDialogCanceled(result)) { + if (isDialogCancelled(result)) { this.dialogRef.close(); } }); diff --git a/alfa-client/libs/bescheid/src/lib/bescheid-wizard-container/bescheid.formservice.spec.ts b/alfa-client/libs/bescheid/src/lib/bescheid-wizard-container/bescheid.formservice.spec.ts index f0ab24a4e53d0d57472b9c126218b2b7501df54c..16e1a03f93b28f6e7562dab279b37680cad42282 100644 --- a/alfa-client/libs/bescheid/src/lib/bescheid-wizard-container/bescheid.formservice.spec.ts +++ b/alfa-client/libs/bescheid/src/lib/bescheid-wizard-container/bescheid.formservice.spec.ts @@ -34,6 +34,7 @@ describe('BescheidFormService', () => { beforeEach(() => { bescheidService = mock(BescheidService); bescheidService.createBescheid.mockReturnValue(of(EMPTY)); + bescheidService.updateBescheid.mockReturnValue(of(EMPTY)); service = new BescheidFormService(new UntypedFormBuilder(), useFromMock(bescheidService)); service.setVorgangWithEingangResource(vorgangWithEingangResource); }); @@ -46,6 +47,8 @@ describe('BescheidFormService', () => { }); it('should create bescheid', () => { + service.isPatch = jest.fn().mockReturnValue(false); + bescheidService.existBescheid.mockReturnValue(false); const formValue: Bescheid = createBescheid(); service.getBescheidFormValue = jest.fn().mockReturnValue(formValue); @@ -56,6 +59,27 @@ describe('BescheidFormService', () => { formValue, ); }); + + it('should update bescheid if patched', () => { + service.isPatch = jest.fn().mockReturnValue(true); + const formValue: Bescheid = createBescheid(); + service.getBescheidFormValue = jest.fn().mockReturnValue(formValue); + + service.submit(); + + expect(bescheidService.updateBescheid).toHaveBeenCalledWith(formValue); + }); + + it('should update bescheid if exists', () => { + service.isPatch = jest.fn().mockReturnValue(false); + bescheidService.existsBescheidDraft.mockReturnValue(true); + const formValue: Bescheid = createBescheid(); + service.getBescheidFormValue = jest.fn().mockReturnValue(formValue); + + service.submit(); + + expect(bescheidService.updateBescheid).toHaveBeenCalledWith(formValue); + }); }); describe('patchValues', () => { diff --git a/alfa-client/libs/bescheid/src/lib/bescheid-wizard-container/bescheid.formservice.ts b/alfa-client/libs/bescheid/src/lib/bescheid-wizard-container/bescheid.formservice.ts index a2eb4446959dc9ca0f968ae5e2e00fd062d8ae0f..31696be2b3e2dc22b17bd7820b937a5f6ce4e52c 100644 --- a/alfa-client/libs/bescheid/src/lib/bescheid-wizard-container/bescheid.formservice.ts +++ b/alfa-client/libs/bescheid/src/lib/bescheid-wizard-container/bescheid.formservice.ts @@ -64,6 +64,9 @@ export class BescheidFormService extends AbstractFormService { `Can't submit because ${this.constructor.name} is missing vorgang with eingang resource`, ); } + if (this.isPatch() || this.bescheidService.existsBescheidDraft()) { + return this.bescheidService.updateBescheid(this.getBescheidFormValue()); + } return this.bescheidService.createBescheid( this.vorgangWithEingangResource, this.getBescheidFormValue(), diff --git a/alfa-client/libs/ui/src/lib/ui/ozgcloud-dialog/ozgcloud-dialog.result.spec.ts b/alfa-client/libs/ui/src/lib/ui/ozgcloud-dialog/ozgcloud-dialog.result.spec.ts index c61d6c912edf74690f50da2a1296a35a8dd60a22..20199d8ca1e8574e517352ba6d6e0542d62c4e57 100644 --- a/alfa-client/libs/ui/src/lib/ui/ozgcloud-dialog/ozgcloud-dialog.result.spec.ts +++ b/alfa-client/libs/ui/src/lib/ui/ozgcloud-dialog/ozgcloud-dialog.result.spec.ts @@ -3,27 +3,27 @@ import { createSuccessfullyDoneCommandStateResource } from '../../../../../comma import { createDialogCancelResult, createDialogResult, - isDialogCanceled, + isDialogCancelled, isDialogSuccessfullyCompleted, } from './ozgcloud-dialog.result'; describe('ozgcloud-dialog.result', () => { - describe('isDialogCanceled', () => { + describe('isDialogCancelled', () => { it('should return true', () => { - expect(isDialogCanceled({ stateResource: createEmptyStateResource() })).toBeTruthy(); + expect(isDialogCancelled({ stateResource: createEmptyStateResource() })).toBeTruthy(); }); it('should return false for null result', () => { - expect(isDialogCanceled(null)).toBeFalsy(); + expect(isDialogCancelled(null)).toBeFalsy(); }); it('should return false for null state resource', () => { - expect(isDialogCanceled({ stateResource: null })).toBeFalsy(); + expect(isDialogCancelled({ stateResource: null })).toBeFalsy(); }); it('should return false for non empty state resource', () => { expect( - isDialogCanceled({ stateResource: createSuccessfullyDoneCommandStateResource() }), + isDialogCancelled({ stateResource: createSuccessfullyDoneCommandStateResource() }), ).toBeFalsy(); }); }); diff --git a/alfa-client/libs/ui/src/lib/ui/ozgcloud-dialog/ozgcloud-dialog.result.ts b/alfa-client/libs/ui/src/lib/ui/ozgcloud-dialog/ozgcloud-dialog.result.ts index 7404c7632d1965e81e92933aa4c68f18017cc1ad..8e73b9aaf92a1b9b9e9d66a94c6689525fc0cfd1 100644 --- a/alfa-client/libs/ui/src/lib/ui/ozgcloud-dialog/ozgcloud-dialog.result.ts +++ b/alfa-client/libs/ui/src/lib/ui/ozgcloud-dialog/ozgcloud-dialog.result.ts @@ -20,7 +20,7 @@ export function createDialogResult( return { stateResource }; } -export function isDialogCanceled(dialogResult?: OzgcloudDialogCommandResult): boolean { +export function isDialogCancelled(dialogResult?: OzgcloudDialogCommandResult): boolean { return dialogResult && isEmptyStateResource(dialogResult.stateResource); }