[SI-2773] total commit

Signed-off-by: Peter Buschmann <peter.buschmann@pta.de>
diff --git a/projects/grid-failure-information-app/src/app/shared/store/reducers/grid-failures/grid-failure-details-form.reducer.spec.ts b/projects/grid-failure-information-app/src/app/shared/store/reducers/grid-failures/grid-failure-details-form.reducer.spec.ts
index 4d8ab12..28d5421 100644
--- a/projects/grid-failure-information-app/src/app/shared/store/reducers/grid-failures/grid-failure-details-form.reducer.spec.ts
+++ b/projects/grid-failure-information-app/src/app/shared/store/reducers/grid-failures/grid-failure-details-form.reducer.spec.ts
@@ -62,6 +62,7 @@
 
   it('should set FormState in response to gridFailureActions.loadAddressCommunitiesSuccess', () => {
     const action: Action = { type: gridFailureActions.loadAllAddressCommunitiesSuccess.type };
+    action['payload'] = [];
     const state: FormGroupState<GridFailure> = formReducer.reducer(INITIAL_STATE, action);
     const formState = formReducer.getFormState(state);
     expect(formState).toEqual(state);
@@ -69,18 +70,21 @@
 
   it('should set FormState in response to gridFailureActions.loadAddressDistrictsSuccess', () => {
     const action: Action = { type: gridFailureActions.loadAddressDistrictsOfCommunitySuccess.type };
+    action['payload'] = [];
     const state: FormGroupState<GridFailure> = formReducer.reducer(INITIAL_STATE, action);
     expect(formReducer.getFormState(state)).toEqual(state);
   });
 
   it('should set FormState in response to gridFailureActions.loadAddressStreetsSuccess', () => {
     const action: Action = { type: gridFailureActions.loadAddressStreetsSuccess.type };
+    action['payload'] = [];
     const state: FormGroupState<GridFailure> = formReducer.reducer(INITIAL_STATE, action);
     expect(formReducer.getFormState(state)).toEqual(state);
   });
 
   it('should set FormState in response to gridFailureActions.loadAddressHouseNumbersSuccess', () => {
     const action: Action = { type: gridFailureActions.loadAddressHouseNumbersSuccess.type };
+    action['payload'] = [];
     const state: FormGroupState<GridFailure> = formReducer.reducer(INITIAL_STATE, action);
     expect(formReducer.getFormState(state)).toEqual(state);
   });
diff --git a/projects/grid-failure-information-app/src/app/shared/store/reducers/grid-failures/grid-failure-details-form.reducer.ts b/projects/grid-failure-information-app/src/app/shared/store/reducers/grid-failures/grid-failure-details-form.reducer.ts
index debbebc..05a629c 100644
--- a/projects/grid-failure-information-app/src/app/shared/store/reducers/grid-failures/grid-failure-details-form.reducer.ts
+++ b/projects/grid-failure-information-app/src/app/shared/store/reducers/grid-failures/grid-failure-details-form.reducer.ts
@@ -21,7 +21,6 @@
   enable,
   FormGroupState,
   FormState,
-  MarkAsTouchedAction,
   setUserDefinedProperty,
   setValue,
   SetValueAction,
@@ -83,7 +82,9 @@
 }
 
 /**
- * Checks wheather the succes respones has an array with only one item and sets the value in form model
+ * Checks wheather the succes respones has an array with only one item and sets the value in form model.
+ * If not it chekcs additionally, whether the (imported) control value is avaiable in the list values (action payload).
+ * If not, the control value is set to null (so the user has to choose a correct value manually)
  *
  * @author Martin Gardyan <martin.gardyan@pta.de>
  * @export
@@ -92,12 +93,14 @@
  * @param {string} controlId
  * @returns {FormGroupState<GridFailure>}
  */
-export function getDependentSingleValue(state: FormGroupState<GridFailure> = INITIAL_STATE, action: Action, controlId: string): FormGroupState<GridFailure> {
+export function getSingleValue(state: FormGroupState<GridFailure> = INITIAL_STATE, action: Action, controlId: string): FormGroupState<GridFailure> {
   const data: Array<string> = <Array<string>>action['payload'];
 
   const controlName: string = controlId.substring(controlId.indexOf('.') + 1, controlId.length);
   const isSingleValue: boolean = !!data && data.length <= 1 && data[0] !== state.controls[controlName].value;
-  let currentAction: Action = isSingleValue ? new SetValueAction<any>(controlId, data[0] || null) : new MarkAsTouchedAction(controlId);
+  let currentAction: Action = isSingleValue
+    ? new SetValueAction<any>(controlId, data[0] || null)
+    : new SetValueAction<any>(controlId, data.find(d => d === state.controls[controlName].value) || null);
 
   let formState = setUserDefinedProperty(state, DEPENDENT_FIELD_KEY, isSingleValue ? controlId : null);
   return validateForm(formState, currentAction);
@@ -170,9 +173,7 @@
         return setControlEditState(propState, formState, [FORM_CONTROLS.postcode.id]);
       },
       housenumber: (propState, formState): any => {
-        return setControlEditState(propState, formState, [
-          FORM_CONTROLS.street.id,
-        ]);
+        return setControlEditState(propState, formState, [FORM_CONTROLS.street.id]);
       },
     },
     {
@@ -233,20 +234,20 @@
       return setUserDefinedProperty(formState, DEPENDENT_FIELD_KEY, FORM_ID);
     }
     case gridFailureActions.loadAllAddressCommunitiesSuccess.type: {
-      return getDependentSingleValue(state, action, FORM_CONTROLS.city.id);
+      return getSingleValue(state, action, FORM_CONTROLS.city.id);
     }
     case gridFailureActions.loadAddressPostalcodesSuccess.type: {
-      return getDependentSingleValue(state, action, FORM_CONTROLS.postcode.id);
+      return getSingleValue(state, action, FORM_CONTROLS.postcode.id);
     }
     case gridFailureActions.loadAddressDistrictsOfCommunitySuccess.type: {
-      return getDependentSingleValue(state, action, FORM_CONTROLS.district.id);
+      return getSingleValue(state, action, FORM_CONTROLS.district.id);
     }
     case gridFailureActions.loadAddressStreetsSuccess.type: {
-      return getDependentSingleValue(state, action, FORM_CONTROLS.street.id);
+      return getSingleValue(state, action, FORM_CONTROLS.street.id);
     }
     case gridFailureActions.loadAddressHouseNumbersSuccess.type: {
       const ac = { payload: !!action['payload'] && action['payload'].map((houseNumber: FailureHousenumber) => houseNumber.housenumber) } as any;
-      return getDependentSingleValue(state, ac, FORM_CONTROLS.housenumber.id);
+      return getSingleValue(state, ac, FORM_CONTROLS.housenumber.id);
     }
     case SetValueAction.TYPE: {
       let formState = setUserDefinedProperty(state, DEPENDENT_FIELD_KEY, action[DEPENDENT_FIELD_KEY]);