[BP-841] Add error message to error component
Signed-off-by: Christopher Keim <keim@develop-group.de>
diff --git a/src/app/shared/components/error/error.component.spec.ts b/src/app/shared/components/error/error.component.spec.ts
index f34794b..76d0ee0 100644
--- a/src/app/shared/components/error/error.component.spec.ts
+++ b/src/app/shared/components/error/error.component.spec.ts
@@ -1,16 +1,20 @@
/********************************************************************************
- * Copyright © 2018 Mettenmeier GmbH.
+ * Copyright © 2018 Mettenmeier GmbH and others.
*
* 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
+ *
+ * Contributors:
+ * Mettenmeier GmbH - initial implementation
+ * Basys GmbH - automatic report generation implementation
********************************************************************************/
-import { async, ComponentFixture, TestBed } from '@angular/core/testing';
-import { ErrorComponent } from '@shared/components/error/error.component';
-import { FormControl, Validators } from '@angular/forms';
+import {async, ComponentFixture, TestBed} from '@angular/core/testing';
+import {ErrorComponent} from '@shared/components/error/error.component';
+import {FormControl, Validators} from '@angular/forms';
describe('ErrorComponent', () => {
let component: ErrorComponent;
@@ -19,8 +23,7 @@
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ErrorComponent]
- })
- .compileComponents();
+ }).compileComponents();
}));
beforeEach(() => {
@@ -83,5 +86,10 @@
expect(component.listOfErrors()[0]).toEqual('Die Eingabe entspricht nicht dem Muster: ^abc$');
});
+ it('should return an Array with an error for email error', () => {
+ (component as any).control = new FormControl('abc', Validators.email);
+ expect(component.listOfErrors()[0]).toEqual('Die Eingabe enthält keine gültige Emailadresse.');
+ });
+
});
});
diff --git a/src/app/shared/components/error/error.component.ts b/src/app/shared/components/error/error.component.ts
index 737594f..cdaff71 100644
--- a/src/app/shared/components/error/error.component.ts
+++ b/src/app/shared/components/error/error.component.ts
@@ -1,44 +1,46 @@
/********************************************************************************
- * Copyright © 2018 Mettenmeier GmbH.
+ * Copyright © 2018 Mettenmeier GmbH and others.
*
* 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
+ *
+ * Contributors:
+ * Mettenmeier GmbH - initial implementation
+ * Basys GmbH - automatic report generation implementation
********************************************************************************/
-import { Component, OnInit, Input } from '@angular/core';
-import { AbstractControlDirective, AbstractControl } from '@angular/forms';
+
+import {Component, Input} from '@angular/core';
+import {AbstractControl, AbstractControlDirective} from '@angular/forms';
@Component({
selector: 'ok-error',
templateUrl: './error.component.html',
styleUrls: ['./error.component.scss']
})
-export class ErrorComponent implements OnInit {
+export class ErrorComponent {
+
private static readonly errorMessages = {
- 'required': () => 'Dieses Feld muss ausgefüllt werden.',
- 'minlength': (params) => `Es müssen mindestens ${params.requiredLength} Zeichen eingegeben werden`,
- 'maxlength': (params) => `Es dürfen maximal ${params.requiredLength} Zeichen eingegeben werden`,
- 'pattern': (params) => `Die Eingabe entspricht nicht dem Muster: ${params.requiredPattern}`,
- 'invalidDate': () => `Das "von"-Datum muss vor dem "bis"-Datum liegen.`
+ required: () => 'Dieses Feld muss ausgefüllt werden.',
+ minlength: (params) => `Es müssen mindestens ${params.requiredLength} Zeichen eingegeben werden`,
+ maxlength: (params) => `Es dürfen maximal ${params.requiredLength} Zeichen eingegeben werden`,
+ pattern: (params) => `Die Eingabe entspricht nicht dem Muster: ${params.requiredPattern}`,
+ invalidDate: () => `Das "von"-Datum muss vor dem "bis"-Datum liegen.`,
+ email: () => `Die Eingabe enthält keine gültige Emailadresse.`
};
@Input()
private control: AbstractControlDirective | AbstractControl;
- constructor() { }
-
- ngOnInit() {
- }
-
- shouldShowErrors(): boolean {
+ public shouldShowErrors(): boolean {
return this.control &&
this.control.errors &&
(this.control.dirty || this.control.touched);
}
- listOfErrors(): string[] {
+ public listOfErrors(): string[] {
if (!this.control.errors) {
return [];
}