Skip to content
Snippets Groups Projects

OZG-7974-Validierung-onSubmit

Merged Albert Bruns requested to merge OZG-7974-Validierung-onSubmit into main
Files
24
@@ -21,9 +21,16 @@
* Die sprachspezifischen Genehmigungen und Beschränkungen
* unter der Lizenz sind dem Lizenztext zu entnehmen.
*/
import { createEmptyStateResource, createStateResource, EMPTY_STRING, InvalidParam, setInvalidParamValidationError, StateResource, } from '@alfa-client/tech-shared';
import {
createEmptyStateResource,
createStateResource,
EMPTY_STRING,
InvalidParam,
setInvalidParamValidationError,
StateResource,
} from '@alfa-client/tech-shared';
import { Injectable } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { fakeAsync, TestBed, tick } from '@angular/core/testing';
import { AbstractControl, FormArray, FormBuilder, FormControl, FormGroup, UntypedFormGroup, Validators } from '@angular/forms';
import { ActivatedRoute, UrlSegment } from '@angular/router';
import { faker } from '@faker-js/faker/.';
@@ -173,6 +180,7 @@ describe('KeycloakFormService', () => {
service._patchConfig = patchConfig;
service._load = jest.fn().mockReturnValue(singleHot(dummyStateResource));
service._patchIfLoaded = jest.fn();
service._doAfterPatch = jest.fn();
});
it('should call load', () => {
@@ -189,6 +197,14 @@ describe('KeycloakFormService', () => {
expect(service._patchIfLoaded).toHaveBeenCalledWith(dummyStateResource);
});
it('should call do after patch', () => {
service._load = jest.fn().mockReturnValue(of(dummyStateResource));
service._initLoading().subscribe();
expect(service._doAfterPatch).toHaveBeenCalledWith(dummyStateResource);
});
it('should return loaded value', () => {
const loadedDummyStateResource: Observable<StateResource<Dummy>> = service._initLoading();
@@ -276,9 +292,16 @@ describe('KeycloakFormService', () => {
expect(service._showValidationErrorForAllInvalidControls).toHaveBeenCalledWith(service.form);
});
it('should return emit state resource', () => {
expect(service._processInvalidForm()).toBeObservable(singleColdCompleted(createEmptyStateResource()));
});
it('should return delayed empty state resource', fakeAsync(() => {
const expectedEmits: StateResource<unknown>[] = [];
service._processInvalidForm().subscribe((value: StateResource<unknown>) => {
expectedEmits.push(value);
});
tick(200);
expect(expectedEmits).toEqual([createEmptyStateResource(true), createEmptyStateResource()]);
}));
});
describe('process response validation errors', () => {
@@ -763,6 +786,8 @@ export class TestKeycloakFormService extends KeycloakFormService<Dummy> {
return TestKeycloakFormService.LOAD_OBSERVABLE();
}
_doAfterPatch(stateResource: StateResource<Dummy>) {}
_doSubmit(): Observable<StateResource<Dummy>> {
return TestKeycloakFormService.SUBMIT_OBSERVABLE();
}
Loading