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

OZG-5009 encapsulate state and add missing test

parent ad6d51cc
Branches
Tags
No related merge requests found
import { Bescheid, BescheidService } from '@alfa-client/bescheid-shared'; import { Bescheid, BescheidService } from '@alfa-client/bescheid-shared';
import { import {
AbstractFormService, AbstractFormService,
StateResource,
asBoolean, asBoolean,
formatForDatabase, formatForDatabase,
StateResource,
} from '@alfa-client/tech-shared'; } from '@alfa-client/tech-shared';
import { VorgangWithEingangResource } from '@alfa-client/vorgang-shared'; import { VorgangWithEingangResource } from '@alfa-client/vorgang-shared';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { UntypedFormBuilder, UntypedFormControl, UntypedFormGroup } from '@angular/forms'; import { UntypedFormBuilder, UntypedFormControl, UntypedFormGroup } from '@angular/forms';
import { isNil } from 'lodash-es'; import { isNil } from 'lodash-es';
import { BehaviorSubject, Observable, map, startWith } from 'rxjs'; import { BehaviorSubject, map, Observable, startWith } from 'rxjs';
@Injectable() @Injectable()
export class BescheidenFormService extends AbstractFormService { export class BescheidenFormService extends AbstractFormService {
...@@ -19,7 +19,7 @@ export class BescheidenFormService extends AbstractFormService { ...@@ -19,7 +19,7 @@ export class BescheidenFormService extends AbstractFormService {
public readonly bescheidChanges$: BehaviorSubject<Bescheid>; public readonly bescheidChanges$: BehaviorSubject<Bescheid>;
public vorgang: VorgangWithEingangResource; private vorgangWithEingangResource: VorgangWithEingangResource;
constructor( constructor(
formBuilder: UntypedFormBuilder, formBuilder: UntypedFormBuilder,
...@@ -65,7 +65,10 @@ export class BescheidenFormService extends AbstractFormService { ...@@ -65,7 +65,10 @@ export class BescheidenFormService extends AbstractFormService {
} }
protected doSubmit(): Observable<StateResource<any>> { protected doSubmit(): Observable<StateResource<any>> {
return this.bescheidService.createBescheidDraft(this.vorgang, this.getValue()); return this.bescheidService.createBescheidDraft(
this.vorgangWithEingangResource,
this.getValue(),
);
} }
public getValue(): Bescheid { public getValue(): Bescheid {
...@@ -79,4 +82,10 @@ export class BescheidenFormService extends AbstractFormService { ...@@ -79,4 +82,10 @@ export class BescheidenFormService extends AbstractFormService {
public getBescheidChanges(): Observable<Bescheid> { public getBescheidChanges(): Observable<Bescheid> {
return this.bescheidChanges$.asObservable(); return this.bescheidChanges$.asObservable();
} }
public setVorgangWithEingangResource(
vorgangWithEingangResource: VorgangWithEingangResource,
): void {
this.vorgangWithEingangResource = vorgangWithEingangResource;
}
} }
...@@ -75,12 +75,20 @@ describe('VorgangDetailBescheidenComponent', () => { ...@@ -75,12 +75,20 @@ describe('VorgangDetailBescheidenComponent', () => {
}); });
describe('ngOnInit', () => { describe('ngOnInit', () => {
it('should set vorgang on form service', () => {
const setVorgangWithEingangResource = (formService.setVorgangWithEingangResource = jest.fn());
component.ngOnInit();
expect(setVorgangWithEingangResource).toBeCalledWith(vorgangWithEingangResource);
});
it('should patch values', () => { it('should patch values', () => {
const mock = (formService.patchValues = jest.fn()); const patchValues = (formService.patchValues = jest.fn());
component.ngOnInit(); component.ngOnInit();
expect(mock).toBeCalledWith(bescheidDraftResource); expect(patchValues).toBeCalledWith(bescheidDraftResource);
}); });
}); });
......
...@@ -24,7 +24,9 @@ export class VorgangDetailBescheidenComponent implements OnInit { ...@@ -24,7 +24,9 @@ export class VorgangDetailBescheidenComponent implements OnInit {
} }
ngOnInit(): void { ngOnInit(): void {
this.formService.vorgang = this.dialogRef.config.data.vorgangWithEingangResource; this.formService.setVorgangWithEingangResource(
this.dialogRef.config.data.vorgangWithEingangResource,
);
this.formService.patchValues(this.bescheidDraftResource); this.formService.patchValues(this.bescheidDraftResource);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment