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

OZG-6185 implement update bescheid, fix state, rename function

parent e62a846c
No related branches found
No related tags found
No related merge requests found
...@@ -58,6 +58,7 @@ describe('BescheidWizardContainerComponent', () => { ...@@ -58,6 +58,7 @@ describe('BescheidWizardContainerComponent', () => {
bescheidService = mock(BescheidService); bescheidService = mock(BescheidService);
ozgcloudDialogService = mock(OzgcloudDialogService); ozgcloudDialogService = mock(OzgcloudDialogService);
formService = new BescheidFormService(new UntypedFormBuilder(), useFromMock(bescheidService)); formService = new BescheidFormService(new UntypedFormBuilder(), useFromMock(bescheidService));
formService.patchValues = jest.fn();
wizardDialogRef = new DialogRefMock(); wizardDialogRef = new DialogRefMock();
}); });
...@@ -118,6 +119,12 @@ describe('BescheidWizardContainerComponent', () => { ...@@ -118,6 +119,12 @@ describe('BescheidWizardContainerComponent', () => {
}); });
describe('ngOnInit', () => { describe('ngOnInit', () => {
it('should init bescheid service', () => {
component.ngOnInit();
expect(bescheidService.init).toHaveBeenCalled();
});
it('should set vorgang with eingang on form service', () => { it('should set vorgang with eingang on form service', () => {
formService.setVorgangWithEingangResource = jest.fn(); formService.setVorgangWithEingangResource = jest.fn();
...@@ -174,9 +181,15 @@ describe('BescheidWizardContainerComponent', () => { ...@@ -174,9 +181,15 @@ describe('BescheidWizardContainerComponent', () => {
); );
}); });
it('should patch form values', () => { it('should set bescheid state resource', () => {
formService.patchValues = jest.fn(); component.subscribeToBescheidResource();
component.bescheidDraftStateResource$.subscribe();
expect(component.bescheidStateResource).toEqual(bescheidDraftStateResource);
});
it('should patch form values', () => {
component.subscribeToBescheidResource(); component.subscribeToBescheidResource();
component.bescheidDraftStateResource$.subscribe(); component.bescheidDraftStateResource$.subscribe();
...@@ -204,8 +217,6 @@ describe('BescheidWizardContainerComponent', () => { ...@@ -204,8 +217,6 @@ describe('BescheidWizardContainerComponent', () => {
}); });
it('should not patch form values', () => { it('should not patch form values', () => {
formService.patchValues = jest.fn();
component.subscribeToBescheidResource(); component.subscribeToBescheidResource();
expect(formService.patchValues).not.toHaveBeenCalled(); expect(formService.patchValues).not.toHaveBeenCalled();
...@@ -318,7 +329,7 @@ describe('BescheidWizardContainerComponent', () => { ...@@ -318,7 +329,7 @@ describe('BescheidWizardContainerComponent', () => {
}); });
}); });
describe('dialog canceled', () => { describe('dialog cancelled', () => {
beforeEach(() => { beforeEach(() => {
cancelDialogRef = new DialogRefMock(); cancelDialogRef = new DialogRefMock();
const value = createDialogCancelResult(); const value = createDialogCancelResult();
...@@ -358,9 +369,9 @@ describe('BescheidWizardContainerComponent', () => { ...@@ -358,9 +369,9 @@ describe('BescheidWizardContainerComponent', () => {
component.cancelWizard = jest.fn(); component.cancelWizard = jest.fn();
}); });
it('should close wizard if bescheid resource loaded', () => { it('should cancel wizard if bescheid resource loaded', () => {
const bescheidResource: BescheidResource = createBescheidResource(); const bescheidResource: BescheidResource = createBescheidResource();
component.bescheidDraftStateResource$ = of(createStateResource(bescheidResource)); component.bescheidStateResource = createStateResource(bescheidResource);
wizardDialogRef.keydownEvents = of(createKeydownKeyboardEvent(ESCAPE_KEY)); wizardDialogRef.keydownEvents = of(createKeydownKeyboardEvent(ESCAPE_KEY));
component.handleEscapeKey(); component.handleEscapeKey();
...@@ -368,7 +379,7 @@ describe('BescheidWizardContainerComponent', () => { ...@@ -368,7 +379,7 @@ describe('BescheidWizardContainerComponent', () => {
expect(component.cancelWizard).toHaveBeenCalledWith(bescheidResource); 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>()); component.bescheidDraftStateResource$ = of(createEmptyStateResource<BescheidResource>());
wizardDialogRef.keydownEvents = of(createKeydownKeyboardEvent(ESCAPE_KEY)); wizardDialogRef.keydownEvents = of(createKeydownKeyboardEvent(ESCAPE_KEY));
...@@ -377,7 +388,7 @@ describe('BescheidWizardContainerComponent', () => { ...@@ -377,7 +388,7 @@ describe('BescheidWizardContainerComponent', () => {
expect(component.cancelWizard).toHaveBeenCalledWith(null); 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(); const bescheidResource: BescheidResource = createBescheidResource();
component.bescheidDraftStateResource$ = of(createStateResource(bescheidResource)); component.bescheidDraftStateResource$ = of(createStateResource(bescheidResource));
wizardDialogRef.keydownEvents = of(createKeydownKeyboardEvent('a')); wizardDialogRef.keydownEvents = of(createKeydownKeyboardEvent('a'));
...@@ -387,9 +398,9 @@ describe('BescheidWizardContainerComponent', () => { ...@@ -387,9 +398,9 @@ describe('BescheidWizardContainerComponent', () => {
expect(component.cancelWizard).not.toHaveBeenCalled(); 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(); const bescheidResource: BescheidResource = createBescheidResource();
component.bescheidDraftStateResource$ = of(createStateResource(bescheidResource, true)); component.bescheidStateResource = createStateResource(bescheidResource, true);
wizardDialogRef.keydownEvents = of(createKeydownKeyboardEvent(ESCAPE_KEY)); wizardDialogRef.keydownEvents = of(createKeydownKeyboardEvent(ESCAPE_KEY));
component.handleEscapeKey(); component.handleEscapeKey();
......
...@@ -11,10 +11,10 @@ import { VorgangWithEingangLinkRel, VorgangWithEingangResource } from '@alfa-cli ...@@ -11,10 +11,10 @@ import { VorgangWithEingangLinkRel, VorgangWithEingangResource } from '@alfa-cli
import { DIALOG_DATA, DialogRef } from '@angular/cdk/dialog'; import { DIALOG_DATA, DialogRef } from '@angular/cdk/dialog';
import { Component, Inject, OnDestroy, OnInit, ViewContainerRef } from '@angular/core'; import { Component, Inject, OnDestroy, OnInit, ViewContainerRef } from '@angular/core';
import { hasLink } from '@ngxp/rest'; 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 { import {
OzgcloudDialogCommandResult, OzgcloudDialogCommandResult,
isDialogCanceled, isDialogCancelled,
isDialogSuccessfullyCompleted, isDialogSuccessfullyCompleted,
} from '../../../../ui/src/lib/ui/ozgcloud-dialog/ozgcloud-dialog.result'; } from '../../../../ui/src/lib/ui/ozgcloud-dialog/ozgcloud-dialog.result';
import { import {
...@@ -38,6 +38,7 @@ export class BescheidWizardContainerComponent implements OnInit, OnDestroy { ...@@ -38,6 +38,7 @@ export class BescheidWizardContainerComponent implements OnInit, OnDestroy {
); );
public activeStep: number = 1; public activeStep: number = 1;
bescheidStateResource: StateResource<BescheidResource> = createEmptyStateResource();
isCancelDialogOpen: boolean = false; isCancelDialogOpen: boolean = false;
vorgangWithEingangResource: VorgangWithEingangResource; vorgangWithEingangResource: VorgangWithEingangResource;
keydownEventsSubscription: Subscription; keydownEventsSubscription: Subscription;
...@@ -54,6 +55,7 @@ export class BescheidWizardContainerComponent implements OnInit, OnDestroy { ...@@ -54,6 +55,7 @@ export class BescheidWizardContainerComponent implements OnInit, OnDestroy {
} }
ngOnInit(): void { ngOnInit(): void {
this.bescheidService.init();
this.formService.setVorgangWithEingangResource(this.vorgangWithEingangResource); this.formService.setVorgangWithEingangResource(this.vorgangWithEingangResource);
this.subscribeToBescheidResource(); this.subscribeToBescheidResource();
this.handleEscapeKey(); this.handleEscapeKey();
...@@ -67,6 +69,7 @@ export class BescheidWizardContainerComponent implements OnInit, OnDestroy { ...@@ -67,6 +69,7 @@ export class BescheidWizardContainerComponent implements OnInit, OnDestroy {
if (hasLink(this.vorgangWithEingangResource, VorgangWithEingangLinkRel.BESCHEID_DRAFT)) { if (hasLink(this.vorgangWithEingangResource, VorgangWithEingangLinkRel.BESCHEID_DRAFT)) {
this.bescheidDraftStateResource$ = this.bescheidService.getBescheidDraft().pipe( this.bescheidDraftStateResource$ = this.bescheidService.getBescheidDraft().pipe(
tap((bescheidDraftStateResource: StateResource<BescheidResource>) => { tap((bescheidDraftStateResource: StateResource<BescheidResource>) => {
this.bescheidStateResource = bescheidDraftStateResource;
if (isLoaded(bescheidDraftStateResource)) { if (isLoaded(bescheidDraftStateResource)) {
this.formService.patchValues(bescheidDraftStateResource.resource); this.formService.patchValues(bescheidDraftStateResource.resource);
} }
...@@ -79,7 +82,7 @@ export class BescheidWizardContainerComponent implements OnInit, OnDestroy { ...@@ -79,7 +82,7 @@ export class BescheidWizardContainerComponent implements OnInit, OnDestroy {
this.keydownEventsSubscription = this.dialogRef.keydownEvents this.keydownEventsSubscription = this.dialogRef.keydownEvents
.pipe( .pipe(
filter(isEscapeKey), filter(isEscapeKey),
switchMap(() => this.bescheidDraftStateResource$), map(() => this.bescheidStateResource),
filter(isNotLoading), filter(isNotLoading),
) )
.subscribe((bescheidStateResource: StateResource<BescheidResource>) => { .subscribe((bescheidStateResource: StateResource<BescheidResource>) => {
...@@ -120,7 +123,7 @@ export class BescheidWizardContainerComponent implements OnInit, OnDestroy { ...@@ -120,7 +123,7 @@ export class BescheidWizardContainerComponent implements OnInit, OnDestroy {
this.bescheidService.reloadDependentResources(); this.bescheidService.reloadDependentResources();
this.dialogRef.close(); this.dialogRef.close();
} }
if (isDialogCanceled(result)) { if (isDialogCancelled(result)) {
this.dialogRef.close(); this.dialogRef.close();
} }
}); });
......
...@@ -34,6 +34,7 @@ describe('BescheidFormService', () => { ...@@ -34,6 +34,7 @@ describe('BescheidFormService', () => {
beforeEach(() => { beforeEach(() => {
bescheidService = mock(BescheidService); bescheidService = mock(BescheidService);
bescheidService.createBescheid.mockReturnValue(of(EMPTY)); bescheidService.createBescheid.mockReturnValue(of(EMPTY));
bescheidService.updateBescheid.mockReturnValue(of(EMPTY));
service = new BescheidFormService(new UntypedFormBuilder(), useFromMock(bescheidService)); service = new BescheidFormService(new UntypedFormBuilder(), useFromMock(bescheidService));
service.setVorgangWithEingangResource(vorgangWithEingangResource); service.setVorgangWithEingangResource(vorgangWithEingangResource);
}); });
...@@ -46,6 +47,8 @@ describe('BescheidFormService', () => { ...@@ -46,6 +47,8 @@ describe('BescheidFormService', () => {
}); });
it('should create bescheid', () => { it('should create bescheid', () => {
service.isPatch = jest.fn().mockReturnValue(false);
bescheidService.existBescheid.mockReturnValue(false);
const formValue: Bescheid = createBescheid(); const formValue: Bescheid = createBescheid();
service.getBescheidFormValue = jest.fn().mockReturnValue(formValue); service.getBescheidFormValue = jest.fn().mockReturnValue(formValue);
...@@ -56,6 +59,27 @@ describe('BescheidFormService', () => { ...@@ -56,6 +59,27 @@ describe('BescheidFormService', () => {
formValue, 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', () => { describe('patchValues', () => {
......
...@@ -64,6 +64,9 @@ export class BescheidFormService extends AbstractFormService { ...@@ -64,6 +64,9 @@ export class BescheidFormService extends AbstractFormService {
`Can't submit because ${this.constructor.name} is missing vorgang with eingang resource`, `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( return this.bescheidService.createBescheid(
this.vorgangWithEingangResource, this.vorgangWithEingangResource,
this.getBescheidFormValue(), this.getBescheidFormValue(),
......
...@@ -3,27 +3,27 @@ import { createSuccessfullyDoneCommandStateResource } from '../../../../../comma ...@@ -3,27 +3,27 @@ import { createSuccessfullyDoneCommandStateResource } from '../../../../../comma
import { import {
createDialogCancelResult, createDialogCancelResult,
createDialogResult, createDialogResult,
isDialogCanceled, isDialogCancelled,
isDialogSuccessfullyCompleted, isDialogSuccessfullyCompleted,
} from './ozgcloud-dialog.result'; } from './ozgcloud-dialog.result';
describe('ozgcloud-dialog.result', () => { describe('ozgcloud-dialog.result', () => {
describe('isDialogCanceled', () => { describe('isDialogCancelled', () => {
it('should return true', () => { it('should return true', () => {
expect(isDialogCanceled({ stateResource: createEmptyStateResource() })).toBeTruthy(); expect(isDialogCancelled({ stateResource: createEmptyStateResource() })).toBeTruthy();
}); });
it('should return false for null result', () => { it('should return false for null result', () => {
expect(isDialogCanceled(null)).toBeFalsy(); expect(isDialogCancelled(null)).toBeFalsy();
}); });
it('should return false for null state resource', () => { 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', () => { it('should return false for non empty state resource', () => {
expect( expect(
isDialogCanceled({ stateResource: createSuccessfullyDoneCommandStateResource() }), isDialogCancelled({ stateResource: createSuccessfullyDoneCommandStateResource() }),
).toBeFalsy(); ).toBeFalsy();
}); });
}); });
......
...@@ -20,7 +20,7 @@ export function createDialogResult( ...@@ -20,7 +20,7 @@ export function createDialogResult(
return { stateResource }; return { stateResource };
} }
export function isDialogCanceled(dialogResult?: OzgcloudDialogCommandResult): boolean { export function isDialogCancelled(dialogResult?: OzgcloudDialogCommandResult): boolean {
return dialogResult && isEmptyStateResource(dialogResult.stateResource); return dialogResult && isEmptyStateResource(dialogResult.stateResource);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment