CodeReview changes implemented and add unit tests

Signed-off-by: Dennis Schmitt <dennis.schmitt@pta.de>
diff --git a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure-list-column-definition.ts b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure-list-column-definition.ts
index 0a46ab2..cbc9d8e 100644
--- a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure-list-column-definition.ts
+++ b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure-list-column-definition.ts
@@ -11,6 +11,7 @@
  * SPDX-License-Identifier: EPL-2.0
  ********************************************************************************/
 import { IconCellRendererComponent } from '@grid-failure-information-app/shared/components/cell-renderer/icon-cell-renderer/icon-cell-renderer.component';
+import { valueDateTimeFormatter } from '@grid-failure-information-app/shared/utility/utilityHelpers';
 
 export const GRID_FAILURE_COLDEF = [
   {
@@ -36,7 +37,7 @@
     headerName: 'GridFailure.InternExtern',
     sortable: true,
     filter: 'setFilterComponent',
-    valueGetter: function(params) {
+    valueGetter: function (params) {
       let result = '';
       if (params.data.internExtern === 'I') {
         result = 'intern';
@@ -84,18 +85,7 @@
     sortable: true,
     filter: 'setFilterComponent',
     valueGetter: params => {
-      if (params.data.failureBegin) {
-        const date = new Date(params.data.failureBegin);
-        date.setHours(date.getHours() + date.getTimezoneOffset() / 60);
-        const day = date.getDate() < 10 ? `0${date.getDate()}` : date.getDate();
-        const month = date.getMonth() + 1 < 10 ? `0${date.getMonth() + 1}` : date.getMonth() + 1;
-        const year = date.getFullYear();
-        const hour = date.getHours() < 10 ? `0${date.getHours()}` : date.getHours();
-        const minute = date.getMinutes() < 10 ? `0${date.getMinutes()}` : date.getMinutes();
-        return `${day}.${month}.${year} / ${hour}:${minute}`;
-      } else {
-        return '';
-      }
+      return valueDateTimeFormatter(params.data.failureBegin);
     },
   },
   {
@@ -104,18 +94,7 @@
     sortable: true,
     filter: 'setFilterComponent',
     valueGetter: params => {
-      if (params.data.failureEndPlanned) {
-        const date = new Date(params.data.failureEndPlanned);
-        date.setHours(date.getHours() + date.getTimezoneOffset() / 60);
-        const day = date.getDate() < 10 ? `0${date.getDate()}` : date.getDate();
-        const month = date.getMonth() + 1 < 10 ? `0${date.getMonth() + 1}` : date.getMonth() + 1;
-        const year = date.getFullYear();
-        const hour = date.getHours() < 10 ? `0${date.getHours()}` : date.getHours();
-        const minute = date.getMinutes() < 10 ? `0${date.getMinutes()}` : date.getMinutes();
-        return `${day}.${month}.${year} / ${hour}:${minute}`;
-      } else {
-        return '';
-      }
+      return valueDateTimeFormatter(params.data.failureEndPlanned);
     },
   },
   {
@@ -124,18 +103,7 @@
     sortable: true,
     filter: 'setFilterComponent',
     valueGetter: params => {
-      if (params.data.failureEndResupplied) {
-        const date = new Date(params.data.failureEndResupplied);
-        date.setHours(date.getHours() + date.getTimezoneOffset() / 60);
-        const day = date.getDate() < 10 ? `0${date.getDate()}` : date.getDate();
-        const month = date.getMonth() + 1 < 10 ? `0${date.getMonth() + 1}` : date.getMonth() + 1;
-        const year = date.getFullYear();
-        const hour = date.getHours() < 10 ? `0${date.getHours()}` : date.getHours();
-        const minute = date.getMinutes() < 10 ? `0${date.getMinutes()}` : date.getMinutes();
-        return `${day}.${month}.${year} / ${hour}:${minute}`;
-      } else {
-        return '';
-      }
+      return valueDateTimeFormatter(params.data.failureEndResupplied);
     },
   },
   {
diff --git a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure-list-for-condensation-column-definition.ts b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure-list-for-condensation-column-definition.ts
index 038c358..6ae3057 100644
--- a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure-list-for-condensation-column-definition.ts
+++ b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure-list-for-condensation-column-definition.ts
@@ -11,6 +11,7 @@
  * SPDX-License-Identifier: EPL-2.0
  ********************************************************************************/
 import { IconCellRendererComponent } from '@grid-failure-information-app/shared/components/cell-renderer/icon-cell-renderer/icon-cell-renderer.component';
+import { valueDateTimeFormatter } from '@grid-failure-information-app/shared/utility/utilityHelpers';
 
 export const GRID_FAILURE_FOR_CONDENSATION_COLDEF = [
   {
@@ -36,7 +37,7 @@
     headerName: 'GridFailure.InternExtern',
     sortable: true,
     filter: 'setFilterComponent',
-    valueGetter: function(params) {
+    valueGetter: function (params) {
       let result = '';
       if (params.data.internExtern === 'I') {
         result = 'intern';
@@ -84,18 +85,7 @@
     sortable: true,
     filter: 'setFilterComponent',
     valueGetter: params => {
-      if (params.data.failureBegin) {
-        const date = new Date(params.data.failureBegin);
-        date.setHours(date.getHours() + date.getTimezoneOffset() / 60);
-        const day = date.getDate() < 10 ? `0${date.getDate()}` : date.getDate();
-        const month = date.getMonth() + 1 < 10 ? `0${date.getMonth() + 1}` : date.getMonth() + 1;
-        const year = date.getFullYear();
-        const hour = date.getHours() < 10 ? `0${date.getHours()}` : date.getHours();
-        const minute = date.getMinutes() < 10 ? `0${date.getMinutes()}` : date.getMinutes();
-        return `${day}.${month}.${year} / ${hour}:${minute}`;
-      } else {
-        return '';
-      }
+      return valueDateTimeFormatter(params.data.failureBegin);
     },
   },
   {
@@ -104,18 +94,7 @@
     sortable: true,
     filter: 'setFilterComponent',
     valueGetter: params => {
-      if (params.data.failureEndPlanned) {
-        const date = new Date(params.data.failureEndPlanned);
-        date.setHours(date.getHours() + date.getTimezoneOffset() / 60);
-        const day = date.getDate() < 10 ? `0${date.getDate()}` : date.getDate();
-        const month = date.getMonth() + 1 < 10 ? `0${date.getMonth() + 1}` : date.getMonth() + 1;
-        const year = date.getFullYear();
-        const hour = date.getHours() < 10 ? `0${date.getHours()}` : date.getHours();
-        const minute = date.getMinutes() < 10 ? `0${date.getMinutes()}` : date.getMinutes();
-        return `${day}.${month}.${year} / ${hour}:${minute}`;
-      } else {
-        return '';
-      }
+      return valueDateTimeFormatter(params.data.failureEndPlanned);
     },
   },
   {
@@ -124,18 +103,7 @@
     sortable: true,
     filter: 'setFilterComponent',
     valueGetter: params => {
-      if (params.data.failureEndResupplied) {
-        const date = new Date(params.data.failureEndResupplied);
-        date.setHours(date.getHours() + date.getTimezoneOffset() / 60);
-        const day = date.getDate() < 10 ? `0${date.getDate()}` : date.getDate();
-        const month = date.getMonth() + 1 < 10 ? `0${date.getMonth() + 1}` : date.getMonth() + 1;
-        const year = date.getFullYear();
-        const hour = date.getHours() < 10 ? `0${date.getHours()}` : date.getHours();
-        const minute = date.getMinutes() < 10 ? `0${date.getMinutes()}` : date.getMinutes();
-        return `${day}.${month}.${year} / ${hour}:${minute}`;
-      } else {
-        return '';
-      }
+      return valueDateTimeFormatter(params.data.failureEndResupplied);
     },
   },
   {
diff --git a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure-list.component.ts b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure-list.component.ts
index 7f7d9db..0140d85 100644
--- a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure-list.component.ts
+++ b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure-list.component.ts
@@ -17,7 +17,7 @@
 import { GridFailureSandbox } from '@grid-failure-information-app/pages/grid-failure/grid-failure-list/grid-failure.sandbox';
 import { BaseList } from '@grid-failure-information-app/shared/components/base-components/base.list';
 import { HeaderCellRendererComponent } from '@grid-failure-information-app/shared/components/cell-renderer/header-cell-renderer/header-cell-renderer.component';
-import { ModeEnum } from '@grid-failure-information-app/shared/constants/enums';
+import { ModeEnum, EventTypeEnum } from '@grid-failure-information-app/shared/constants/enums';
 import { SetFilterComponent } from '@grid-failure-information-app/shared/filters/ag-grid/set-filter/set-filter.component';
 import { UtilService } from '@grid-failure-information-app/shared/utility';
 import { GridApi, GridOptions } from 'ag-grid-community';
@@ -46,6 +46,7 @@
 
   private _gridApi: GridApi;
   private _modeEnum = ModeEnum;
+  private _eventTypeEnum = EventTypeEnum;
 
   constructor(public sandbox: GridFailureSandbox, private _router: Router, private _utilService: UtilService) {
     super();
@@ -102,20 +103,20 @@
 
     this.gridOptions.context.eventSubject.pipe(takeUntil(this._endSubscriptions$)).subscribe(event => {
       switch (event.type) {
-        case 'edit' || 'readonly':
+        case this._eventTypeEnum.Edit || this._eventTypeEnum.Readonly:
           this._router.navigate(['/grid-failures', event.data.id]);
           break;
-        case 'add':
+        case this._eventTypeEnum.Add:
           if (this.sandbox.condensationList.length == 0 || event.data.branch === this.sandbox.condensationList[0].branch) {
             this.sandbox.addItemToCondensationList(event.data);
           } else {
             this._utilService.displayNotification('DifferentBranchesError', 'alert');
           }
           break;
-        case 'addAllItems':
+        case this._eventTypeEnum.AddAllItems:
           this.addCompleteTable();
           break;
-        case 'initialLoad':
+        case this._eventTypeEnum.InitialLoad:
           this._changeMode();
           break;
 
@@ -130,7 +131,7 @@
     };
 
     this.gridOptionsCondensation.context.eventSubject.pipe(takeUntil(this._endSubscriptions$)).subscribe(event => {
-      if (event.type === 'remove') {
+      if (event.type === this._eventTypeEnum.Remove) {
         this.sandbox.removeItemFromCondensationList(event.data);
       }
     });
diff --git a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure.sandbox.spec.ts b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure.sandbox.spec.ts
index 2850b1c..c934c48 100644
--- a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure.sandbox.spec.ts
+++ b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure.sandbox.spec.ts
@@ -1,4 +1,3 @@
-import { GridFailure } from './../../../shared/models/grid-failure.model';
 /********************************************************************************
  * Copyright (c) 2020 Contributors to the Eclipse Foundation
  *
@@ -17,6 +16,7 @@
 import { of } from 'rxjs';
 import * as gridFailureActions from '@grid-failure-information-app/shared/store/actions/grid-failures.action';
 import { Router } from '@angular/router';
+import { GridFailure } from '@grid-failure-information-app/shared/models/grid-failure.model';
 
 describe('GridFailureSandbox', () => {
   let service: GridFailureSandbox;
diff --git a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure.sandbox.ts b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure.sandbox.ts
index 7bc44a0..01ab6b5 100644
--- a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure.sandbox.ts
+++ b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure.sandbox.ts
@@ -46,59 +46,15 @@
     this.condensationList = [];
   }
 
-  public addItemToCondensationList(data: any): void {
+  public addItemToCondensationList(data: GridFailure): void {
     if (this.condensationList.find(item => item.id == data.id) != null || data.condensed === true) {
       return;
     } else {
-      const temp: GridFailure = {
-        id: data.id,
-        branch: data.branch,
-        branchColorCode: data.branchColorCode,
-        branchId: data.branchId,
-        condensed: data.condensed,
-        condensedCount: data.condensedCount,
-        city: data.city,
-        district: data.district,
-        failureBegin: data.failureBegin,
-        failureClassification: data.failureClassification,
-        failureClassificationId: data.failureClassificationId,
-        failureEndPlanned: data.failureEndPlanned,
-        failureEndResupplied: data.failureEndResupplied,
-        failureType: data.failureType,
-        failureTypeId: data.failureTypeId,
-        housenumber: data.housenumber,
-        internExtern: data.internExtern,
-        internalRemark: data.internalRemark,
-        postcode: data.postcode,
-        pressureLevel: data.pressureLevel,
-        radius: data.radius,
-        radiusId: data.radiusId,
-        responsibility: data.responsibility,
-        stationDescription: data.stationDescription,
-        statusExtern: data.statusExtern,
-        statusExternId: data.statusExternId,
-        statusIntern: data.statusIntern,
-        statusInternId: data.statusInternId,
-        street: data.street,
-        voltageLevel: data.voltageLevel,
-        createDate: data.createDate,
-        createUser: data.createUser,
-        modDate: data.modDate,
-        modUser: data.modUser,
-        objectReferenceExternalSystem: data.objectReferenceExternalSystem,
-        publicationStatus: data.publicationStatus,
-        publicationFreetext: data.publicationFreetext,
-        longitude: data.longitude,
-        latitude: data.latitude,
-        versionNumber: data.versionNumber,
-        expectedReasonText: data.expectedReasonText,
-        expectedReasonId: data.expectedReasonId,
-      };
-      this.condensationList = [...this.condensationList, temp];
+      this.condensationList = [...this.condensationList, data];
     }
   }
 
-  public removeItemFromCondensationList(data: any): void {
+  public removeItemFromCondensationList(data: GridFailure): void {
     this.condensationList = this.condensationList.filter(item => item.id !== data.id);
   }
 
diff --git a/projects/grid-failure-information-app/src/app/shared/components/cell-renderer/icon-cell-renderer/icon-cell-renderer.component.spec.ts b/projects/grid-failure-information-app/src/app/shared/components/cell-renderer/icon-cell-renderer/icon-cell-renderer.component.spec.ts
index a1d5fbb..c6613f8 100644
--- a/projects/grid-failure-information-app/src/app/shared/components/cell-renderer/icon-cell-renderer/icon-cell-renderer.component.spec.ts
+++ b/projects/grid-failure-information-app/src/app/shared/components/cell-renderer/icon-cell-renderer/icon-cell-renderer.component.spec.ts
@@ -27,21 +27,4 @@
   it('should return false when calling refesh', () => {
     expect(component.refresh()).toBeFalsy();
   });
-
-  // it('should set icon properties appropriate when calling agInit with default params  + icons undefined', () => {
-  //   let p: ICellRendererParams = { data: { editable: true }, context: { icons: {} } } as any;
-  //   // component.params = { context: { eventSubject: { eventType: '' } } };
-  //   component.agInit(p);
-  //   expect(component.editIcon).toBeFalsy();
-  //   expect(component.readonlyIcon).toBeFalsy();
-  //   expect(component.deleteIcon).toBeFalsy();
-  // });
-
-  // it('should set icon properties appropriate when calling agInit with default params + icons true', () => {
-  //   let p: ICellRendererParams = { data: { editable: true }, context: { icons: { edit: true, readonly: true, delete: true } } } as any;
-  //   component.agInit(p);
-  //   expect(component.editIcon).toBeTruthy();
-  //   expect(component.readonlyIcon).toBeTruthy();
-  //   expect(component.deleteIcon).toBeTruthy();
-  // });
 });
diff --git a/projects/grid-failure-information-app/src/app/shared/constants/enums.ts b/projects/grid-failure-information-app/src/app/shared/constants/enums.ts
index 239509f..351d988 100644
--- a/projects/grid-failure-information-app/src/app/shared/constants/enums.ts
+++ b/projects/grid-failure-information-app/src/app/shared/constants/enums.ts
@@ -38,3 +38,12 @@
   OverviewTableSelectionMode = 'overviewTableSelectionMode',
   CondensationTableSelectionMode = 'condensationTableSelectionMode',
 }
+
+export enum EventTypeEnum {
+  Edit = 'edit',
+  Readonly = 'readonly',
+  Add = 'add',
+  AddAllItems = 'addAllItems',
+  InitialLoad = 'initialLoad',
+  Remove = 'remove',
+}
diff --git a/projects/grid-failure-information-app/src/app/shared/utility/utilityHelpers.spec.ts b/projects/grid-failure-information-app/src/app/shared/utility/utilityHelpers.spec.ts
index bbeb8f9..b733299 100644
--- a/projects/grid-failure-information-app/src/app/shared/utility/utilityHelpers.spec.ts
+++ b/projects/grid-failure-information-app/src/app/shared/utility/utilityHelpers.spec.ts
@@ -50,4 +50,10 @@
     let testValue = utilityHelpers.localeDateString(dateString);
     expect(testValue).toBe('1.12.2020');
   });
+
+  it('should convert a string date with time to right format', () => {
+    const dateTimeString: string = '2021-01-19T00:00:00.000Z';
+    let testValue = utilityHelpers.valueDateTimeFormatter(dateTimeString);
+    expect(testValue).toBe('19.01.2021 / 00:00');
+  });
 });
diff --git a/projects/grid-failure-information-app/src/app/shared/utility/utilityHelpers.ts b/projects/grid-failure-information-app/src/app/shared/utility/utilityHelpers.ts
index d845f3b..59deca7 100644
--- a/projects/grid-failure-information-app/src/app/shared/utility/utilityHelpers.ts
+++ b/projects/grid-failure-information-app/src/app/shared/utility/utilityHelpers.ts
@@ -67,3 +67,18 @@
     return '';
   }
 }
+
+export function valueDateTimeFormatter(params: any) {
+  if (params) {
+    const date = new Date(params);
+    date.setHours(date.getHours() + date.getTimezoneOffset() / 60);
+    const day = date.getDate() < 10 ? `0${date.getDate()}` : date.getDate();
+    const month = date.getMonth() + 1 < 10 ? `0${date.getMonth() + 1}` : date.getMonth() + 1;
+    const year = date.getFullYear();
+    const hour = date.getHours() < 10 ? `0${date.getHours()}` : date.getHours();
+    const minute = date.getMinutes() < 10 ? `0${date.getMinutes()}` : date.getMinutes();
+    return `${day}.${month}.${year} / ${hour}:${minute}`;
+  } else {
+    return '';
+  }
+}