[SI-536]: total commit

Signed-off-by: Dennis Schmitt <dennis.schmitt@pta.de>
diff --git a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.component.html b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.component.html
index 020c494..ac73a97 100644
--- a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.component.html
+++ b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.component.html
@@ -415,7 +415,7 @@
                   (click)="
                     mapInteractionMode = false;
                     failureLocationView = 'NS';
-                    saveWithoutHideRequiredProperties();
+                    disableUnnescessaryRequiredProperties();
                     gridFailureDetailsSandbox.resetFailureLocationValues()
                   "
                   [class.active]="failureLocationView === 'NS'"
@@ -427,7 +427,7 @@
                   (click)="
                     mapInteractionMode = false;
                     failureLocationView = 'MS';
-                    saveWithoutHideRequiredProperties();
+                    disableUnnescessaryRequiredProperties();
                     gridFailureDetailsSandbox.resetFailureLocationValues()
                   "
                   [class.active]="failureLocationView === 'MS'"
@@ -439,7 +439,7 @@
                   (click)="
                     mapInteractionMode = true;
                     failureLocationView = 'map';
-                    saveWithoutHideRequiredProperties();
+                    disableUnnescessaryRequiredProperties();
                     gridFailureDetailsSandbox.resetFailureLocationValues()
                   "
                   [class.active]="failureLocationView === 'map'"
diff --git a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.component.spec.ts b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.component.spec.ts
index 9ace7a4..9d29b68 100644
--- a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.component.spec.ts
+++ b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.component.spec.ts
@@ -11,11 +11,13 @@
  * SPDX-License-Identifier: EPL-2.0
  ********************************************************************************/
 import { GridFailureDetailsComponent } from '@grid-failure-information-app/pages/grid-failure/grid-failure-details/grid-failure-details.component';
-import { State } from '@grid-failure-information-app/shared/store';
-import { Store } from '@ngrx/store';
 import { of } from 'rxjs';
+import { Store } from '@ngrx/store';
+import { State } from '@grid-failure-information-app/shared/store';
+import { async } from '@angular/core/testing';
+import { GridFailure } from '@grid-failure-information-app/shared/models';
 
-fdescribe('GridFailureDetailsComponent', () => {
+describe('GridFailureDetailsComponent', () => {
   let component: GridFailureDetailsComponent;
   let gridFailureSandbox: any;
   let gridFailureDetailsFormResponse: any = {
@@ -24,22 +26,30 @@
       failureEndPlanned: 'test2',
       failureEndResupplied: 'test3',
     },
+    controls: {
+      postcode: { value: null },
+      stationDescription: { value: null },
+      latitude: { value: null },
+    } as any,
   };
   let appState: Store<State>;
 
   beforeEach(() => {
     appState = { dispatch: () => {}, pipe: () => of(true), select: () => of(true) } as any;
-    const gridFailureDetailsFormState = { value: { postcode: 67854 } },
-      gridFailureSandbox = {
-        clearGridFailureData() {},
-        setGridFailureDateTime(dateISOString: string, actionType: string) {},
-        registerEvents() {},
-        endSubscriptions() {},
-        resetCoords() {},
-        resetStationId() {},
-        resetPostCode() {},
-        gridFailureDetailsFormState$: of(gridFailureDetailsFormResponse),
-      } as any;
+    gridFailureSandbox = {
+      clearGridFailureData() {},
+      setGridFailureDateTime(dateISOString: string, actionType: string) {},
+      registerEvents() {},
+      endSubscriptions() {},
+      resetCoords() {},
+      resetStationId() {},
+      resetPostCode() {},
+      disableUnnecessaryRequiredProperties() {},
+      gridFailureDetailsFormState$: of(gridFailureDetailsFormResponse as any),
+      isAdressLoaded() {
+        return of(true);
+      },
+    } as any;
     component = new GridFailureDetailsComponent(gridFailureSandbox, appState);
   });
 
@@ -47,12 +57,12 @@
     expect(component).toBeTruthy();
   });
 
-  it('should end subscriptions in Sandbox bevore the component going away ', () => {
+  it('should end subscriptions in Sandbox before the component going away ', async(() => {
     let component = new GridFailureDetailsComponent(gridFailureSandbox, appState);
     let spy = spyOn(gridFailureSandbox, 'endSubscriptions');
     component.ngOnDestroy();
     expect(spy).toHaveBeenCalled();
-  });
+  }));
 
   it('should registerEvents OnInit', () => {
     let spy = spyOn(gridFailureSandbox, 'registerEvents');
@@ -61,20 +71,20 @@
     expect(spy).toHaveBeenCalled();
   });
 
-  it('should call "clearGridFailureData()" in Sandbox if "resetGridFailureDateTime()" is called', () => {
+  it('should call "clearGridFailureData()" in Sandbox if "resetGridFailureDateTime()" is called', async(() => {
     const spy = spyOn(gridFailureSandbox, 'clearGridFailureData');
     component.resetGridFailureDateTime('test');
     expect(spy).toHaveBeenCalled();
-  });
+  }));
 
-  it('should call "setGridFailureDateTime()" in Sandbox if "setGridFailureDateTime()" is called', () => {
+  it('should call "setGridFailureDateTime()" in Sandbox if "setGridFailureDateTime()" is called', async(() => {
     const spy = spyOn(gridFailureSandbox, 'setGridFailureDateTime');
     const event = { year: 2020, month: 3, day: 27, hour: 4, minute: 0, second: 0 };
     component.setGridFailureDateTime(event, 'test');
     expect(spy).toHaveBeenCalled();
-  });
+  }));
 
-  it('checks if _createDateTime(event: any) works fine', () => {
+  it('checks if _createDateTime(event: any) works fine', async(() => {
     const expectedResult = new Date();
     expectedResult.setDate(27);
     expectedResult.setMonth(3 - 1); //index starts by 0
@@ -85,9 +95,9 @@
     const event = { year: 2020, month: 3, day: 27, hour: 4, minute: 0, second: 0 };
     const result: Date = (component as any)._createDateTime(event);
     expect(expectedResult.toISOString).toBe(result.toISOString);
-  });
+  }));
 
-  it('checks if resetCoords(value: string) works fine', () => {
+  it('checks if resetCoords(value: string) works fine', async(() => {
     let spy1 = spyOn(gridFailureSandbox, 'resetCoords');
     let spy2 = spyOn(gridFailureSandbox, 'resetStationId');
 
@@ -98,12 +108,60 @@
     component.resetCoords(null);
     expect(spy1).toHaveBeenCalled();
     expect(spy2).toHaveBeenCalled();
-  });
+  }));
 
-  // it('checks if saveWithoutRequiredProperties()-function works fine', () => {
-  //   let spy1 = spyOn(gridFailureSandbox, 'saveFailureLocationSpecificParts');
-  //   component.failureLocationView = 'MS';
-  //   component.saveWithoutHideRequiredProperties();
-  //   expect(spy1).toHaveBeenCalled();
-  // });
+  it('checks if disableUnnescessaryRequiredProperties works fine', async(() => {
+    component.failureLocationView = 'MS';
+    const spy = spyOn(gridFailureSandbox, 'disableUnnecessaryRequiredProperties');
+    component.disableUnnescessaryRequiredProperties();
+    expect(spy).toHaveBeenCalled();
+  }));
+
+  it('checks if _initialFailureLocationState works fine', async(() => {
+    component.mapInteractionMode = true;
+
+    component.gridFailureDetailsSandbox.currentFormState = {
+      ...component.gridFailureDetailsSandbox.currentFormState,
+      controls: {
+        postcode: { value: null } as any,
+        stationDescription: { value: null } as any,
+        latitude: { value: null } as any,
+      } as any,
+    };
+    (component as any)._initialFailureLocationState();
+    expect(component.mapInteractionMode).toBeFalsy();
+
+    component.gridFailureDetailsSandbox.currentFormState = {
+      ...component.gridFailureDetailsSandbox.currentFormState,
+      controls: {
+        postcode: { value: null } as any,
+        stationDescription: { value: null } as any,
+        latitude: { value: 1.24 } as any,
+      } as any,
+    };
+    (component as any)._initialFailureLocationState();
+    expect(component.mapInteractionMode).toBeTruthy();
+
+    component.gridFailureDetailsSandbox.currentFormState = {
+      ...component.gridFailureDetailsSandbox.currentFormState,
+      controls: {
+        postcode: { value: null } as any,
+        stationDescription: { value: 'test' } as any,
+        latitude: { value: 1.24 } as any,
+      } as any,
+    };
+    (component as any)._initialFailureLocationState();
+    expect(component.mapInteractionMode).toBeFalsy();
+
+    component.gridFailureDetailsSandbox.currentFormState = {
+      ...component.gridFailureDetailsSandbox.currentFormState,
+      controls: {
+        postcode: { value: '00000' } as any,
+        stationDescription: { value: 'test' } as any,
+        latitude: { value: 1.24 } as any,
+      } as any,
+    };
+    (component as any)._initialFailureLocationState();
+    expect(component.mapInteractionMode).toBeFalsy();
+  }));
 });
diff --git a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.component.ts b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.component.ts
index f935225..6fcbe6c 100644
--- a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.component.ts
+++ b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.component.ts
@@ -1,4 +1,3 @@
-import { AfterViewInit } from '@angular/core';
 /********************************************************************************
  * Copyright (c) 2020 Contributors to the Eclipse Foundation
  *
@@ -57,8 +56,8 @@
     }
   }
 
-  public saveWithoutHideRequiredProperties() {
-    this.gridFailureDetailsSandbox.saveFailureLocationSpecificParts(this.failureLocationView);
+  public disableUnnescessaryRequiredProperties() {
+    this.gridFailureDetailsSandbox.disableUnnecessaryRequiredProperties(this.failureLocationView);
   }
 
   private _createDateTime(dateTime: any): Date {
@@ -74,26 +73,29 @@
 
   private _initialFailureLocationState() {
     this.gridFailureDetailsSandbox.isAdressLoaded().subscribe(() => {
-      if (!!this.gridFailureDetailsSandbox.currentFormState.controls.postcode.value) {
-        this.failureLocationView = Globals.FAILURE_LOCATION_NS;
-        this.gridFailureDetailsSandbox.saveFailureLocationSpecificParts(this.failureLocationView);
-        this.mapInteractionMode = false;
-      } else if (!!this.gridFailureDetailsSandbox.currentFormState.controls.stationDescription.value) {
-        this.failureLocationView = Globals.FAILURE_LOCATION_MS;
-        this.gridFailureDetailsSandbox.saveFailureLocationSpecificParts(this.failureLocationView);
-        this.mapInteractionMode = false;
-      } else if (
-        !this.gridFailureDetailsSandbox.currentFormState.controls.postcode.value &&
-        !this.gridFailureDetailsSandbox.currentFormState.controls.stationDescription.value &&
-        this.gridFailureDetailsSandbox.currentFormState.controls.latitude.value
-      ) {
-        this.failureLocationView = Globals.FAILURE_LOCATION_MAP;
-        this.gridFailureDetailsSandbox.saveFailureLocationSpecificParts(this.failureLocationView);
-        this.mapInteractionMode = true;
-      } else {
-        this.failureLocationView = Globals.FAILURE_LOCATION_NS;
-        this.gridFailureDetailsSandbox.saveFailureLocationSpecificParts(this.failureLocationView);
-        this.mapInteractionMode = false;
+      const currentFormState = this.gridFailureDetailsSandbox.currentFormState;
+      if (!!currentFormState && !!currentFormState.controls) {
+        if (!!currentFormState.controls.postcode.value) {
+          this.failureLocationView = Globals.FAILURE_LOCATION_NS;
+          this.gridFailureDetailsSandbox.disableUnnecessaryRequiredProperties(this.failureLocationView);
+          this.mapInteractionMode = false;
+        } else if (!!currentFormState.controls.stationDescription.value) {
+          this.failureLocationView = Globals.FAILURE_LOCATION_MS;
+          this.gridFailureDetailsSandbox.disableUnnecessaryRequiredProperties(this.failureLocationView);
+          this.mapInteractionMode = false;
+        } else if (
+          !currentFormState.controls.postcode.value &&
+          !currentFormState.controls.stationDescription.value &&
+          currentFormState.controls.latitude.value
+        ) {
+          this.failureLocationView = Globals.FAILURE_LOCATION_MAP;
+          this.gridFailureDetailsSandbox.disableUnnecessaryRequiredProperties(this.failureLocationView);
+          this.mapInteractionMode = true;
+        } else {
+          this.failureLocationView = Globals.FAILURE_LOCATION_NS;
+          this.gridFailureDetailsSandbox.disableUnnecessaryRequiredProperties(this.failureLocationView);
+          this.mapInteractionMode = false;
+        }
       }
     });
   }
diff --git a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.sandbox.spec.ts b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.sandbox.spec.ts
index 5b2b9cf..c095b7a 100644
--- a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.sandbox.spec.ts
+++ b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.sandbox.spec.ts
@@ -1,4 +1,3 @@
-import { SetValueAction } from 'ngrx-forms';
 /********************************************************************************
  * Copyright (c) 2020 Contributors to the Eclipse Foundation
  *
@@ -601,22 +600,22 @@
   it('should call saveFailureLocationSpecificParts', () => {
     service.saveEnabled = false;
     let part: string = 'NS';
-    service.saveFailureLocationSpecificParts(part);
+    service.disableUnnecessaryRequiredProperties(part);
     expect(service.saveEnabled).toBeTruthy();
 
     service.saveEnabled = false;
     part = 'MS';
-    service.saveFailureLocationSpecificParts(part);
+    service.disableUnnecessaryRequiredProperties(part);
     expect(service.saveEnabled).toBeTruthy();
 
     service.saveEnabled = false;
     part = 'map';
-    service.saveFailureLocationSpecificParts(part);
+    service.disableUnnecessaryRequiredProperties(part);
     expect(service.saveEnabled).toBeTruthy();
 
     service.saveEnabled = false;
     part = 'test';
-    service.saveFailureLocationSpecificParts(part);
+    service.disableUnnecessaryRequiredProperties(part);
     expect(service.saveEnabled).toBeFalsy();
   });
 
diff --git a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.sandbox.ts b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.sandbox.ts
index 4c49391..d518ff0 100644
--- a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.sandbox.ts
+++ b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.sandbox.ts
@@ -10,7 +10,7 @@
  *
  * SPDX-License-Identifier: EPL-2.0
  ********************************************************************************/
-import { loadAddressCommunities } from './../../../shared/store/actions/grid-failures.action';
+import { loadAddressCommunities } from '@grid-failure-information-app/shared/store/actions/grid-failures.action';
 import { Injectable } from '@angular/core';
 import { Router } from '@angular/router';
 import { SafetyQueryDialogComponent } from '@grid-failure-information-app/shared/components/dialogs/safety-query-dialog/safety-query-dialog.component';
@@ -480,8 +480,7 @@
     );
   }
 
-  public saveFailureLocationSpecificParts(part: string): void {
-    //disable required proteries that are not needed
+  public disableUnnecessaryRequiredProperties(part: string): void {
     switch (part) {
       case Globals.FAILURE_LOCATION_NS:
         this.appState$.dispatch(new EnableAction(fromGridFailuresDetailFormReducer.INITIAL_STATE.controls.postcode.id));
@@ -502,9 +501,7 @@
         break;
     }
   }
-  /**
-   * isAdressLoaded
-   */
+
   public isAdressLoaded(): Observable<boolean> {
     return this.actionsSubject.pipe(
       ofType(loadAddressCommunities.type),
diff --git a/projects/openk/grid-failure-information-map/src/lib/grid-failure-information-map.component.spec.ts b/projects/openk/grid-failure-information-map/src/lib/grid-failure-information-map.component.spec.ts
index a862a64..4fb19ce 100644
--- a/projects/openk/grid-failure-information-map/src/lib/grid-failure-information-map.component.spec.ts
+++ b/projects/openk/grid-failure-information-map/src/lib/grid-failure-information-map.component.spec.ts
@@ -19,6 +19,7 @@
 
   beforeEach(() => {
     component = new GridFailureInformationMapComponent();
+    component.setInteractionMode = true;
   });
 
   it('should create', () => {
@@ -30,7 +31,7 @@
     const radius: any = 100;
     const marker: any = {};
     component.mapData = [{ latitude: latitude, longitude: longitude, radius: radius }];
-    let spyMap: any = spyOn(L, 'map').and.returnValue({ remove() {} });
+    let spyMap: any = spyOn(L, 'map').and.returnValue({ remove() {}, on() {} });
     let spyTileLayer: any = spyOn(L, 'tileLayer').and.returnValue({ addTo() {} });
     let spyMarker: any = spyOn(L, 'marker').and.returnValue({
       addTo() {
@@ -67,4 +68,11 @@
     (component as any)._drawPolygonOrCircle(data2);
     expect(spyPolygon).toHaveBeenCalledWith(polygon, { color: '#204d74', fillColor: '#337ab7', fillOpacity: 0.3 });
   }));
+
+  it('should call _emitLatLongValues and emit latlon-values', async(() => {
+    let spy: any = spyOn(component.latLong, 'emit');
+    const event = { latlng: { lat: 1.24, lng: 1.24 } };
+    (component as any)._emitLatLongValues(event);
+    expect(spy).toHaveBeenCalledWith({ latitude: 1.24, longitude: 1.24 });
+  }));
 });
diff --git a/projects/openk/grid-failure-information-map/src/lib/grid-failure-information-map.component.ts b/projects/openk/grid-failure-information-map/src/lib/grid-failure-information-map.component.ts
index cc785d3..2e2e8e1 100644
--- a/projects/openk/grid-failure-information-map/src/lib/grid-failure-information-map.component.ts
+++ b/projects/openk/grid-failure-information-map/src/lib/grid-failure-information-map.component.ts
@@ -1,4 +1,3 @@
-import { on } from '@ngrx/store';
 /********************************************************************************
  * Copyright (c) 2020 Contributors to the Eclipse Foundation
  *
@@ -16,8 +15,6 @@
 import { Globals } from '@openk-libs/grid-failure-information-map/constants/globals';
 import { GridFailureMapInformation } from '@openk-libs/grid-failure-information-map/shared/models/grid-failure-coordinates.model';
 import { convertISOToLocalDateTime } from '@openk-libs/grid-failure-information-map/shared/utility/utilityHelpers';
-import { unbox } from 'ngrx-forms';
-import { ofType } from '@ngrx/effects';
 
 @Component({
   selector: 'openk-grid-failure-information-map',