SI-425 unitests added validation.service.ts and date pipes removed Signed-off-by: Dimitrios Chalepakis <dimitrios.chalepakis@pta.de>
diff --git a/angular.json b/angular.json index f0029a8..7d1fdda 100644 --- a/angular.json +++ b/angular.json
@@ -139,6 +139,7 @@ "e2e/*.ts", "**/*.action.*", "**/*.model.*", + "**/*.constants.*", "**/*.module.*", "**/*column-definition*", "**/*api-client.*", @@ -275,6 +276,7 @@ "e2e/*.ts", "**/*.action.*", "**/*.model.*", + "**/*.constants.*", "**/*.module.*", "**/*column-definition*", "**/*api-client.*", @@ -335,6 +337,7 @@ "e2e/*.ts", "**/*.action.*", "**/*.model.*", + "**/*.constants.*", "**/*.module.*", "**/*column-definition*", "**/*api-client.*",
diff --git a/package.json b/package.json index a3ce0ab..3ae73d5 100644 --- a/package.json +++ b/package.json
@@ -12,7 +12,7 @@ "start-map-app": "npm run build-map-library && ng serve grid-failure-information-map-app", "start-main-app": "npm run build-map-library && npm run sy-pre-start && ng serve --proxy-config proxy.conf.json", "start-integration": "npm run sy-pre-start && npm run build-map-library && ng serve --proxy-config proxy.conf-integration.json", - "start-local": "npm run sy-pre-start && ng serve --proxy-config proxy.conf-local.json", + "start-local": "npm run sy-pre-start && npm run build-map-library && ng serve --proxy-config proxy.conf.json", "test": "npm run sy-pre-test && ng test grid-failure-information-app", "test-single-run": "npm run sy-pre-test && ng test grid-failure-information-app --watch=false", "test-openk": "npm run sy-pre-test && ng test openk-grid-failure-information-map-lib", @@ -31,7 +31,9 @@ "start-in-docker-feature-be": "npm run build-map-library && npm run sy-pre-start && ng serve --optimization=false --vendor-chunk --common-chunk --host=0.0.0.0 --disableHostCheck=true --proxy-config proxy-docker-feature-be.conf.json", "start-elements-app": "http-server ./dist/grid-failure-information-app", "create-map-output-elements-windows": "create-map-output-elements.sh", - "create-map-output-elements-linux": "./create-map-output-elements.sh" + "create-map-output-elements-linux": "./create-map-output-elements.sh", + "si": "npm run start-integration", + "sl": "npm run start-local" }, "private": true, "dependencies": {
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 50ac9bb..545dc1f 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
@@ -203,7 +203,7 @@ }); it('should show qualify button state is applied', () => { - const state = StateEnum.APPLIED; + const state = StateEnum.CREATED; (service as any)._showButtonsByState(state); expect(service.showQualifyButton).toBeTruthy(); }); @@ -215,13 +215,13 @@ }); it('should show qualify button state is scheduled', () => { - const state = StateEnum.SCHEDULED; + const state = StateEnum.PLANNED; (service as any)._showButtonsByState(state); expect(service.showQualifyButton).toBeTruthy(); }); it('should show storno button state is applied', () => { - const state = StateEnum.APPLIED; + const state = StateEnum.CREATED; (service as any)._showButtonsByState(state); expect(service.showStornoButton).toBeTruthy(); }); @@ -233,7 +233,7 @@ }); it('should show storno button state is scheduled', () => { - const state = StateEnum.SCHEDULED; + const state = StateEnum.PLANNED; (service as any)._showButtonsByState(state); expect(service.showStornoButton).toBeTruthy(); });
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 5f38bd7..aedcb9c 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
@@ -236,9 +236,9 @@ private _showButtonsByState(state: string): void { switch (state) { - case StateEnum.APPLIED: + case StateEnum.CREATED: case StateEnum.UPDATED: - case StateEnum.SCHEDULED: + case StateEnum.PLANNED: this.showQualifyButton = true; this.showStornoButton = true; break;
diff --git a/projects/grid-failure-information-app/src/app/shared/async-services/http/http.decorator.ts b/projects/grid-failure-information-app/src/app/shared/async-services/http/http.decorator.ts index a6afe78..31b9822 100644 --- a/projects/grid-failure-information-app/src/app/shared/async-services/http/http.decorator.ts +++ b/projects/grid-failure-information-app/src/app/shared/async-services/http/http.decorator.ts
@@ -1,4 +1,4 @@ - /******************************************************************************** +/******************************************************************************** * Copyright (c) 2020 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional @@ -11,8 +11,8 @@ * SPDX-License-Identifier: EPL-2.0 ********************************************************************************/ import { RequestMethod } from '@angular/http'; -import { HttpService, MediaType } from './http.service'; -import { methodBuilder, paramBuilder } from './utils.service'; +import { HttpService, MediaType } from '@grid-failure-information-app/shared/async-services/http/http.service'; +import { methodBuilder, paramBuilder } from '@grid-failure-information-app/shared/async-services/http/utils.service'; /* ********************************************* * Class decorators
diff --git a/projects/grid-failure-information-app/src/app/shared/async-services/http/http.decorators.spec.ts b/projects/grid-failure-information-app/src/app/shared/async-services/http/http.decorators.spec.ts new file mode 100644 index 0000000..1c54343 --- /dev/null +++ b/projects/grid-failure-information-app/src/app/shared/async-services/http/http.decorators.spec.ts
@@ -0,0 +1,101 @@ +/******************************************************************************** + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + ********************************************************************************/ +import * as decorators from '@grid-failure-information-app/shared/async-services/http/http.decorator'; +import { MediaType } from '@grid-failure-information-app/shared/async-services/http/http.service'; + +describe('Http Decorators', () => { + it('should return the given url in target if call BaseUrl decorator', () => { + const url = '/test'; + const targetFunction: any = { + prototype: { + getBaseUrl() { + url; + }, + }, + }; + const methodObject = decorators.BaseUrl(url)(targetFunction); + expect(methodObject).toBe(targetFunction); + expect(methodObject.prototype.getBaseUrl()).toBe(url); + }); + + it('should return the given url in target if call DefaultHeaders decorator', () => { + const headers: any = { test: 'test', property: 'property' }; + const targetFunction: any = { + prototype: { + getDefaultHeaders() { + headers; + }, + }, + }; + const methodObject = decorators.DefaultHeaders(headers)(targetFunction); + expect(methodObject).toBe(targetFunction); + expect(methodObject.prototype.getDefaultHeaders()).toBe(headers); + }); + + it('should build the descriptor headers as the headersDef if calling Headers decorator', () => { + const headersDef: any = { test: 'test', property: 'property' }; + const target: any = {}; + const propertyKey = 'key'; + const descriptor: any = { headers: undefined }; + + const methodObject = decorators.Headers(headersDef)(target, propertyKey, descriptor); + expect(methodObject).toBe(descriptor); + expect(methodObject.headers).toBe(headersDef); + }); + + it('should build the descriptor and assign the JSON flag if calling Produces decorator with a JSON media type', () => { + const producesDef: any = MediaType.JSON; + const target: any = {}; + const propertyKey = 'key'; + const descriptor: any = { isJSON: false, isFormData: false }; + + const methodObject = decorators.Produces(producesDef)(target, propertyKey, descriptor); + expect(methodObject).toBe(descriptor); + expect(methodObject.isJSON).toBeTruthy(); + expect(methodObject.isFormData).toBeFalsy(); + }); + + it('should build the descriptor and assign the FORM_DATA flag if calling Produces decorator with a FORM_DATA media type', () => { + const producesDef: any = MediaType.FORM_DATA; + const target: any = {}; + const propertyKey = 'key'; + const descriptor: any = { isJSON: false, isFormData: false }; + + const methodObject = decorators.Produces(producesDef)(target, propertyKey, descriptor); + expect(methodObject).toBe(descriptor); + expect(methodObject.isJSON).toBeFalsy(); + expect(methodObject.isFormData).toBeTruthy(); + }); + + it('should build the descriptor and assign him the given adapter if calling Adapter decorator', () => { + const adapterFn: Function = new Function(); + const target: any = {}; + const propertyKey = 'key'; + const descriptor: any = { adapter: undefined }; + + const methodObject = decorators.Adapter(adapterFn)(target, propertyKey, descriptor); + expect(methodObject).toBe(descriptor); + expect(methodObject.adapter).toBe(adapterFn); + }); + + it('should build the descriptor and assign him null if calling Adapter decorator without a function', () => { + const adapterFn: any = undefined; + const target: any = {}; + const propertyKey = 'key'; + const descriptor: any = { adapter: undefined }; + + const methodObject = decorators.Adapter(adapterFn)(target, propertyKey, descriptor); + expect(methodObject).toBe(descriptor); + expect(methodObject.adapter).toBe(null); + }); +});
diff --git a/projects/grid-failure-information-app/src/app/shared/async-services/http/utils.service.spec.ts b/projects/grid-failure-information-app/src/app/shared/async-services/http/utils.service.spec.ts index 22c66c1..f180e1a 100644 --- a/projects/grid-failure-information-app/src/app/shared/async-services/http/utils.service.spec.ts +++ b/projects/grid-failure-information-app/src/app/shared/async-services/http/utils.service.spec.ts
@@ -22,10 +22,13 @@ test_property_Header_parameters: 'test_header', }; - const descriptor = { value: function({}) {}, adapter: {} }; + const descriptor = { value: () => {}, adapter: {} }; + // 0->GET const methodObject = utils.methodBuilder(0)('/testurl')(target, propertyKey, descriptor); + expect(methodObject).toBe(descriptor); + expect(typeof methodObject.value === 'function').toBe(true); }); it('should call paramBuilder and return a descriptor', () => {
diff --git a/projects/grid-failure-information-app/src/app/shared/components/cell-renderer/date-cell-renderer/date-cell-renderer.component.spec.ts b/projects/grid-failure-information-app/src/app/shared/components/cell-renderer/date-cell-renderer/date-cell-renderer.component.spec.ts index 666a261..b7f5db1 100644 --- a/projects/grid-failure-information-app/src/app/shared/components/cell-renderer/date-cell-renderer/date-cell-renderer.component.spec.ts +++ b/projects/grid-failure-information-app/src/app/shared/components/cell-renderer/date-cell-renderer/date-cell-renderer.component.spec.ts
@@ -40,9 +40,22 @@ expect(component.date).toEqual('test'); }); + it('agInit sets date to value property of its parameter and sets isDate true if its a parsable number', () => { + component.agInit({ value: '5' }); + expect(component.date).toEqual('5'); + expect(component.isDate).toBeTruthy(); + }); + it('refresh sets date to value property of its parameter', () => { const returnValue = component.refresh({ value: 'test' }); expect(component.date).toEqual('test'); expect(returnValue).toBe(true); }); + + it('refresh sets date to value property of its parameter and sets isDate true if its a parsable number', () => { + const returnValue = component.refresh({ value: '5' }); + expect(component.date).toEqual('5'); + expect(returnValue).toBe(true); + expect(component.isDate).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 2b81402..08b4c8b 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
@@ -43,12 +43,10 @@ export enum StateEnum { NEW = 'neu', - CONFIRMED = 'bestätigt', - ACTIVE = 'aktiv', - CLOSED = 'geschlossen', + PLANNED = 'geplant', + CREATED = 'angelegt', CANCELED = 'storniert', QUALIFIED = 'qualifiziert', - APPLIED = 'angelegt', UPDATED = 'aktualisiert', - SCHEDULED = 'geplant', + COMPLETED = 'abgeschlossen', }
diff --git a/projects/grid-failure-information-app/src/app/shared/models/grid-failure.model.ts b/projects/grid-failure-information-app/src/app/shared/models/grid-failure.model.ts index cfef922..d419695 100644 --- a/projects/grid-failure-information-app/src/app/shared/models/grid-failure.model.ts +++ b/projects/grid-failure-information-app/src/app/shared/models/grid-failure.model.ts
@@ -29,7 +29,6 @@ public internalRemark: string = null; public postcode: string = null; public pressureLevel: string = null; - public probableReason: string = null; public radius: string = null; public radiusId: string = null; public responsibility: string = null;
diff --git a/projects/grid-failure-information-app/src/app/shared/pipes/formatted-date.pipe.spec.ts b/projects/grid-failure-information-app/src/app/shared/pipes/formatted-date.pipe.spec.ts deleted file mode 100644 index 2c3c65f..0000000 --- a/projects/grid-failure-information-app/src/app/shared/pipes/formatted-date.pipe.spec.ts +++ /dev/null
@@ -1,29 +0,0 @@ - /******************************************************************************** - * Copyright (c) 2020 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - ********************************************************************************/ - -import { FormattedDatePipe } from './formatted-date.pipe'; - -describe('Test FormattedDatePipe ', () => { - const pipe = new FormattedDatePipe(); - - it('should perform correct with different inputs ', () => { - expect(pipe.transform('xxx')).toBe('xxx'); - expect(pipe.transform(null)).toBe(null); - expect(pipe.transform('')).toBe(''); - expect(pipe.transform(undefined)).toBeNull(); - - const dateTest = pipe.transform('19.11.2017 13:16'); - expect(dateTest.match('[0-3][0-9]\.[0-1][0-9]\.[0-9]{4}')).toBeTruthy(); - - }); -});
diff --git a/projects/grid-failure-information-app/src/app/shared/pipes/formatted-date.pipe.ts b/projects/grid-failure-information-app/src/app/shared/pipes/formatted-date.pipe.ts deleted file mode 100644 index ba9c355..0000000 --- a/projects/grid-failure-information-app/src/app/shared/pipes/formatted-date.pipe.ts +++ /dev/null
@@ -1,49 +0,0 @@ - /******************************************************************************** - * Copyright (c) 2020 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - ********************************************************************************/ - -import {Pipe, PipeTransform} from '@angular/core'; -import * as moment from 'moment'; -/** - * Pipe to transform a string to a date - */ -@Pipe({name: 'formattedDate'}) -export class FormattedDatePipe implements PipeTransform { - /** - * Constructor - */ - constructor() { - } - /** - * Transform a date that is passed as string into a date - * @param value The date passed as string - * @param format The date passed as string - */ - transform(value: any, format: string = ''): string { - // Try and parse the passed value. - if ( value === undefined) { - return null; - } - const momentDate = moment(value, 'DD.MM.YYYY'); - - // If moment didn't understand the value, return it unformatted. - if (!momentDate.isValid()) { - return value; - } - - // Otherwise, return the date formatted as requested. - if (format) { - return momentDate.format(format); - } - return momentDate.format('DD.MM.YYYY'); - } -}
diff --git a/projects/grid-failure-information-app/src/app/shared/pipes/formatted-timestamp.pipe.spec.ts b/projects/grid-failure-information-app/src/app/shared/pipes/formatted-timestamp.pipe.spec.ts deleted file mode 100644 index 6152753..0000000 --- a/projects/grid-failure-information-app/src/app/shared/pipes/formatted-timestamp.pipe.spec.ts +++ /dev/null
@@ -1,31 +0,0 @@ - /******************************************************************************** - * Copyright (c) 2020 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - ********************************************************************************/ - -import { FormattedTimestampPipe } from './formatted-timestamp.pipe'; - -describe('Test FormattedTimestampPipe ', () => { - const pipe = new FormattedTimestampPipe(); - - it('should perform correct with different inputs ', () => { - expect(pipe.transform('xxx')).toBeNull(); - expect(pipe.transform(null)).toBe(''); - expect(pipe.transform('')).toBe(''); - expect(pipe.transform(undefined)).toBe(''); - - expect(pipe.transform('19.11.2017 13:16', 'DD.MM.YYYY HH:mm')).toBe('19.11.2017 13:16'); - - const dateTest = pipe.transform('19.11.2017 13:16'); - expect(dateTest.match('[0-3][0-9]\.[0-1][0-9]\.[0-9]{4} [0-2][0-9]:[0-5][0-9]')).toBeTruthy(); - - }); -});
diff --git a/projects/grid-failure-information-app/src/app/shared/pipes/formatted-timestamp.pipe.ts b/projects/grid-failure-information-app/src/app/shared/pipes/formatted-timestamp.pipe.ts deleted file mode 100644 index c3ac374..0000000 --- a/projects/grid-failure-information-app/src/app/shared/pipes/formatted-timestamp.pipe.ts +++ /dev/null
@@ -1,53 +0,0 @@ - /******************************************************************************** - * Copyright (c) 2020 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - ********************************************************************************/ - -import { Pipe, PipeTransform } from '@angular/core'; -import * as moment from 'moment'; - -@Pipe({ - name: 'formattedTimestamp' -}) -export class FormattedTimestampPipe implements PipeTransform { - transform(value: any, format: string = ''): string { - - if (value === '') { - return ''; - } - - if (value === 'xxx') { - return null; - } - - if (value === null) { - return ''; - } - - if (value === undefined) { - return ''; - } - - // Try and parse the passed value. - const momentDate = moment(value); - - // If moment didn't understand the value, return it unformatted. - if (!momentDate.isValid()) { - return value; - } - - // Otherwise, return the date formatted as requested. - if (format) { - return momentDate.format(format); - } - return momentDate.format('DD.MM.YYYY HH:mm'); - } -}
diff --git a/projects/grid-failure-information-app/src/app/shared/pipes/pipes.module.ts b/projects/grid-failure-information-app/src/app/shared/pipes/pipes.module.ts index e6d29ea..b909054 100644 --- a/projects/grid-failure-information-app/src/app/shared/pipes/pipes.module.ts +++ b/projects/grid-failure-information-app/src/app/shared/pipes/pipes.module.ts
@@ -11,14 +11,12 @@ * SPDX-License-Identifier: EPL-2.0 ********************************************************************************/ import { NgModule } from '@angular/core'; +import { NgbDateCustomParserFormatter } from '@grid-failure-information-app/shared/pipes/ngb-date-custom-parser-formatter'; import { SanitizeHtmlPipe } from '@grid-failure-information-app/shared/pipes/sanitizeHtml.pipe'; import { StringToDatePipe } from '@grid-failure-information-app/shared/pipes/string-to-date.pipe'; -import { FormattedTimestampPipe } from '@grid-failure-information-app/shared/pipes/formatted-timestamp.pipe'; import { UniquePipe } from '@grid-failure-information-app/shared/pipes/unique.pipe'; -import { FormattedDatePipe } from '@grid-failure-information-app/shared/pipes/formatted-date.pipe'; -import { NgbDateCustomParserFormatter } from '@grid-failure-information-app/shared/pipes/ngb-date-custom-parser-formatter'; -export const PIPES = [UniquePipe, SanitizeHtmlPipe, StringToDatePipe, StringToDatePipe, FormattedDatePipe, FormattedTimestampPipe]; +export const PIPES = [UniquePipe, SanitizeHtmlPipe, StringToDatePipe, StringToDatePipe]; @NgModule({ imports: [],
diff --git a/projects/grid-failure-information-app/src/app/shared/store/effects/grid-failures.effect.spec.ts b/projects/grid-failure-information-app/src/app/shared/store/effects/grid-failures.effect.spec.ts index 7e6f2e4..5657891 100644 --- a/projects/grid-failure-information-app/src/app/shared/store/effects/grid-failures.effect.spec.ts +++ b/projects/grid-failure-information-app/src/app/shared/store/effects/grid-failures.effect.spec.ts
@@ -164,6 +164,15 @@ actions$.next(gridFailureActions.loadGridFailureBranches()); }); + it('should equal loadGridFailureBranchesFail in response to getGridFailureBranches Error', done => { + spyOn(apiClient, 'getGridFailureBranches').and.returnValue(throwError('x')); + effects.getGridFailureBranches$.pipe(take(1)).subscribe(result => { + expect(result).toEqual(gridFailureActions.loadGridFailureBranchesFail({ payload: 'x' })); + }); + done(); + actions$.next(gridFailureActions.loadGridFailureBranches()); + }); + it('should equal loadGridFailureClassifications after getGridFailureClassifications', done => { apiResponse = [new FailureClassification({ id: '1' })]; spyOn(apiClient, 'getGridFailureClassifications').and.returnValue(of(apiResponse)); @@ -174,6 +183,15 @@ actions$.next(gridFailureActions.loadGridFailureClassifications()); }); + it('should equal loadGridFailureClassificationsFail in response to getGridFailureClassifications Error', done => { + spyOn(apiClient, 'getGridFailureClassifications').and.returnValue(throwError('x')); + effects.getGridFailureClassifications$.pipe(take(1)).subscribe(result => { + expect(result).toEqual(gridFailureActions.loadGridFailureClassificationsFail({ payload: 'x' })); + }); + done(); + actions$.next(gridFailureActions.loadGridFailureClassifications()); + }); + it('should equal loadGridFailureTypes after getGridFailureTypes', done => { apiResponse = [new FailureType({ id: '1' })]; spyOn(apiClient, 'getGridFailureTypes').and.returnValue(of(apiResponse)); @@ -184,6 +202,15 @@ actions$.next(gridFailureActions.loadGridFailureTypes()); }); + it('should equal loadGridFailureTypesFail in response to getGridFailureTypes Error', done => { + spyOn(apiClient, 'getGridFailureTypes').and.returnValue(throwError('x')); + effects.getGridFailureTypes$.pipe(take(1)).subscribe(result => { + expect(result).toEqual(gridFailureActions.loadGridFailureTypesFail({ payload: 'x' })); + }); + done(); + actions$.next(gridFailureActions.loadGridFailureTypes()); + }); + it('should equal loadGridFailureStates after getGridFailureStates', done => { apiResponse = [new FailureState({ id: '1' })]; spyOn(apiClient, 'getGridFailureStates').and.returnValue(of(apiResponse)); @@ -194,6 +221,15 @@ actions$.next(gridFailureActions.loadGridFailureStates()); }); + it('should equal loadGridFailureStatesFail in response to getGridFailureStates Error', done => { + spyOn(apiClient, 'getGridFailureStates').and.returnValue(throwError('x')); + effects.getGridFailureStates$.pipe(take(1)).subscribe(result => { + expect(result).toEqual(gridFailureActions.loadGridFailureStatesFail({ payload: 'x' })); + }); + done(); + actions$.next(gridFailureActions.loadGridFailureStates()); + }); + it('should equal loadGridFailureRadii after getGridFailureRadii', done => { apiResponse = [new FailureRadius({ id: '1' })]; spyOn(apiClient, 'getGridFailureRadii').and.returnValue(of(apiResponse)); @@ -204,6 +240,15 @@ actions$.next(gridFailureActions.loadGridFailureRadii()); }); + it('should equal loadGridFailureRadiiFail in response to getGridFailureRadii Error', done => { + spyOn(apiClient, 'getGridFailureRadii').and.returnValue(throwError('x')); + effects.getGridFailureRadii$.pipe(take(1)).subscribe(result => { + expect(result).toEqual(gridFailureActions.loadGridFailureRadiiFail({ payload: 'x' })); + }); + done(); + actions$.next(gridFailureActions.loadGridFailureRadii()); + }); + it('should equal loadGridFailureExpectedReasons after getGridFailureExpectedReasons', done => { apiResponse = [new FailureExpectedReason({ id: '1' })]; spyOn(apiClient, 'getGridFailureExpectedReasons').and.returnValue(of(apiResponse)); @@ -213,4 +258,13 @@ done(); actions$.next(gridFailureActions.loadGridFailureExpectedReasons()); }); + + it('should equal loadGridFailureExpectedReasonsFail in response to getGridFailureExpectedReasons Error', done => { + spyOn(apiClient, 'getGridFailureExpectedReasons').and.returnValue(throwError('x')); + effects.getGridFailureExpectedReasons$.pipe(take(1)).subscribe(result => { + expect(result).toEqual(gridFailureActions.loadGridFailureExpectedReasonsFail({ payload: 'x' })); + }); + done(); + actions$.next(gridFailureActions.loadGridFailureExpectedReasons()); + }); });
diff --git a/projects/grid-failure-information-app/src/app/shared/utility/index.ts b/projects/grid-failure-information-app/src/app/shared/utility/index.ts index ea0bb05..00cdf25 100644 --- a/projects/grid-failure-information-app/src/app/shared/utility/index.ts +++ b/projects/grid-failure-information-app/src/app/shared/utility/index.ts
@@ -13,4 +13,3 @@ export * from './utility.module'; export * from './utility.service'; export * from './utilityHelpers'; -export * from './validation.service';
diff --git a/projects/grid-failure-information-app/src/app/shared/utility/utility.module.ts b/projects/grid-failure-information-app/src/app/shared/utility/utility.module.ts index 8ef4046..bcdc4f2 100644 --- a/projects/grid-failure-information-app/src/app/shared/utility/utility.module.ts +++ b/projects/grid-failure-information-app/src/app/shared/utility/utility.module.ts
@@ -11,7 +11,6 @@ * SPDX-License-Identifier: EPL-2.0 ********************************************************************************/ import { NgModule, ModuleWithProviders } from '@angular/core'; -import { ValidationService } from '@grid-failure-information-app/shared/utility/validation.service'; import { UtilService } from '@grid-failure-information-app/shared/utility/utility.service'; @NgModule() @@ -20,7 +19,7 @@ return { ngModule: UtilityModule, - providers: [UtilService, ValidationService], + providers: [UtilService], }; } }
diff --git a/projects/grid-failure-information-app/src/app/shared/utility/utility.service.spec.ts b/projects/grid-failure-information-app/src/app/shared/utility/utility.service.spec.ts index cd957d2..e6b5a0a 100644 --- a/projects/grid-failure-information-app/src/app/shared/utility/utility.service.spec.ts +++ b/projects/grid-failure-information-app/src/app/shared/utility/utility.service.spec.ts
@@ -93,4 +93,28 @@ component.displayNotification(messageTranslationCode, type, titleTranslationCode); expect(spyTranslation).toHaveBeenCalledWith(messageTranslationCode); }); + + it('should set the lookup name with the lookup code if exists and call instant an many times the length of the data', () => { + const data = [ + { name: 'danny', code: '123' }, + { name: 'manny', code: '456' }, + ]; + const spyTranslation = spyOn(translateService, 'instant').and.returnValue({ '123': 'message 123', '456': 'message 456' }); + + const res = component.translateLookupData(data); + expect(spyTranslation).toHaveBeenCalledTimes(data.length); + expect(res).toEqual([ + { name: 'message 123', code: '123' }, + { name: 'message 456', code: '456' }, + ]); + }); + + it('should dont set the lookup name if code not exists and should not call instant', () => { + const data = [{ name: 'danny' }, { name: 'manny' }]; + const spyTranslation = spyOn(translateService, 'instant').and.returnValue({ '123': 'message 123', '456': 'message 456' }); + + const res = component.translateLookupData(data); + expect(spyTranslation).not.toHaveBeenCalled(); + expect(res).toEqual(data); + }); });
diff --git a/projects/grid-failure-information-app/src/app/shared/utility/validation.service.spec.ts b/projects/grid-failure-information-app/src/app/shared/utility/validation.service.spec.ts deleted file mode 100644 index 935344b..0000000 --- a/projects/grid-failure-information-app/src/app/shared/utility/validation.service.spec.ts +++ /dev/null
@@ -1,60 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2020 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - ********************************************************************************/ -import { async } from '@angular/core/testing'; -import { ValidationService } from '@grid-failure-information-app/shared/utility'; - -describe('ValidationService', () => { - let component: ValidationService; - - beforeEach(async(() => {})); - - beforeEach(() => { - component = new ValidationService(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); - - it('should return null if the mail is valid', () => { - let formControl: any; - formControl = { value: 'test@test.de' }; - - const retsult = component.validateEmail(formControl); - expect(retsult).toBe(null); - }); - - it('should return error message if the mail is not valid', () => { - let formControl: any; - formControl = { value: 'test&test.de' }; - - const retsult = component.validateEmail(formControl); - expect(retsult).not.toBe(null); - }); - - it('should return null if the value is numeric', () => { - let formControl: any; - formControl = { value: 222 }; - - const retsult = component.numericRequired(formControl); - expect(retsult).toBe(null); - }); - - it('should return error message if the value is not numeric', () => { - let formControl: any; - formControl = { value: 'test' }; - - const retsult = component.numericRequired(formControl); - expect(retsult).not.toBe(null); - }); -});
diff --git a/projects/grid-failure-information-app/src/app/shared/utility/validation.service.ts b/projects/grid-failure-information-app/src/app/shared/utility/validation.service.ts deleted file mode 100644 index ec93ea7..0000000 --- a/projects/grid-failure-information-app/src/app/shared/utility/validation.service.ts +++ /dev/null
@@ -1,53 +0,0 @@ - /******************************************************************************** - * Copyright (c) 2020 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - ********************************************************************************/ -import { Injectable } from '@angular/core'; -import { - FormControl, - FormGroup -} from '@angular/forms'; -@Injectable() -export class ValidationService { - - /** - * Validates email address - * - * @param formControl - */ - public validateEmail(formControl: FormControl): {[error: string]: any} { - let EMAIL_REGEXP = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; - return EMAIL_REGEXP.test(formControl.value) ? null : { validateEmail: { valid: false } }; - } - - /** - * Validates required numeric values - * - * @param formControl - */ - public numericRequired(formControl: FormControl): {[error: string]: any} { - return (formControl.value && formControl.value > 0) ? null : { numericRequired: { valid: false } }; - } - - /** - * Validates matching string values - * - * @param controlKey - * @param matchingControlKey - */ - public matchingPasswords(controlKey: string, matchingControlKey: string): {[error: string]: any} { - return (group: FormGroup): {[key: string]: any} => { - if (group.controls[controlKey].value !== group.controls[matchingControlKey].value) { - return { mismatch: { valid: false } }; - } - } - } -}
diff --git a/sonar-project.properties b/sonar-project.properties index 5d483ef..597f300 100644 --- a/sonar-project.properties +++ b/sonar-project.properties
@@ -10,7 +10,7 @@ sonar.sourceEncoding=UTF-8 sonar.sources=projects/grid-failure-information-app/src, projects/openk/grid-failure-information-map/src -sonar.exclusions=**/node_modules/**,**/environments/**,e2e/*.ts,**/*.spec.ts,**/test-data/*.ts,**/testing/*.ts,**/assets/**/*,**/*.model.*,**/*.action.*,**/*.module.*,**/*column-definition*,**/*animation*,**/*api-client.*,**/styles.scss +sonar.exclusions=**/node_modules/**,**/environments/**,e2e/*.ts,**/*.spec.ts,**/test-data/*.ts,**/testing/*.ts,**/assets/**/*,**/*.model.*,**/*.constants.*,**/*.action.*,**/*.module.*,**/*column-definition*,**/*animation*,**/*api-client.*,**/styles.scss sonar.tests=projects/grid-failure-information-app/src, projects/openk/grid-failure-information-map/src sonar.test.inclusions=**/*.spec.ts sonar.test.exclusions=