Skip to content
Snippets Groups Projects
Commit c24420e3 authored by Albert Bruns's avatar Albert Bruns
Browse files

OZG-7974 test improvements

parent e31c6b27
Branches
Tags
1 merge request!116OZG-7974-Validierung-onSubmit
...@@ -21,29 +21,29 @@ describe('FormControlEditorAbstractComponent', () => { ...@@ -21,29 +21,29 @@ describe('FormControlEditorAbstractComponent', () => {
fixture.detectChanges(); fixture.detectChanges();
}); });
describe('ng on init', () => { describe('ngOnInit', () => {
it('should set valueChange subscription', () => { it('should set subscription', () => {
component.ngOnInit(); component.ngOnInit();
expect(component._changesSubscr).toBeDefined(); expect(component._changesSubscription).toBeDefined();
}); });
it('should call field control on change handler when fieldControl value changes ', () => { it('should handle field control value changes ', () => {
component._fieldControlOnChangeHandler = jest.fn(); component.handleFieldControlValueChange = jest.fn();
component.ngOnInit(); component.ngOnInit();
component.fieldControl.setValue('testValue'); component.fieldControl.setValue('testValue');
expect(component._fieldControlOnChangeHandler).toHaveBeenCalledWith('testValue'); expect(component.handleFieldControlValueChange).toHaveBeenCalledWith('testValue');
}); });
it('should set statusChange subscription', () => { it('should set subscription', () => {
component.ngOnInit(); component.ngOnInit();
expect(component._statusSubscr).toBeDefined(); expect(component._statusSubscription).toBeDefined();
}); });
it('should call setErrors on statusChange', () => { it('should set errors on statusChange', () => {
component.setErrors = jest.fn(); component.setErrors = jest.fn();
component.ngOnInit(); component.ngOnInit();
...@@ -54,7 +54,7 @@ describe('FormControlEditorAbstractComponent', () => { ...@@ -54,7 +54,7 @@ describe('FormControlEditorAbstractComponent', () => {
}); });
describe('writeValue', () => { describe('writeValue', () => {
it('should set value to fieldControl', () => { it('should set fieldControl value', () => {
const value = 'testValue'; const value = 'testValue';
component.writeValue(value); component.writeValue(value);
...@@ -72,7 +72,7 @@ describe('FormControlEditorAbstractComponent', () => { ...@@ -72,7 +72,7 @@ describe('FormControlEditorAbstractComponent', () => {
expect(component.fieldControl.errors).toEqual(errors); expect(component.fieldControl.errors).toEqual(errors);
}); });
it('should call update invalid params', () => { it('should update invalid params', () => {
component._updateInvalidParams = jest.fn(); component._updateInvalidParams = jest.fn();
component.setErrors(); component.setErrors();
...@@ -81,7 +81,7 @@ describe('FormControlEditorAbstractComponent', () => { ...@@ -81,7 +81,7 @@ describe('FormControlEditorAbstractComponent', () => {
}); });
}); });
describe('remove errors', () => { describe('removeErrors', () => {
it('should remove fieldControl errors', () => { it('should remove fieldControl errors', () => {
component.fieldControl.setErrors({ fehler: 'this is an validation error' }); component.fieldControl.setErrors({ fehler: 'this is an validation error' });
...@@ -90,7 +90,7 @@ describe('FormControlEditorAbstractComponent', () => { ...@@ -90,7 +90,7 @@ describe('FormControlEditorAbstractComponent', () => {
expect(component.fieldControl.errors).toBeNull(); expect(component.fieldControl.errors).toBeNull();
}); });
it('should call update invalid params', () => { it('should update invalid params', () => {
component._updateInvalidParams = jest.fn(); component._updateInvalidParams = jest.fn();
component._removeErrors(); component._removeErrors();
......
...@@ -35,8 +35,8 @@ export abstract class FormControlEditorAbstractComponent implements ControlValue ...@@ -35,8 +35,8 @@ export abstract class FormControlEditorAbstractComponent implements ControlValue
public onTouched = () => undefined; public onTouched = () => undefined;
public invalidParams: InvalidParam[] = []; public invalidParams: InvalidParam[] = [];
_changesSubscr: Subscription; _changesSubscription: Subscription;
_statusSubscr: Subscription; _statusSubscription: Subscription;
disabled: boolean = false; disabled: boolean = false;
...@@ -45,16 +45,18 @@ export abstract class FormControlEditorAbstractComponent implements ControlValue ...@@ -45,16 +45,18 @@ export abstract class FormControlEditorAbstractComponent implements ControlValue
} }
ngOnInit(): void { ngOnInit(): void {
this._changesSubscr = this.fieldControl.valueChanges.subscribe((value: unknown) => this._fieldControlOnChangeHandler(value)); this._changesSubscription = this.fieldControl.valueChanges.subscribe((value: unknown) =>
this.handleFieldControlValueChange(value),
);
if (this.control) { if (this.control) {
this._statusSubscr = this.control.statusChanges.subscribe(() => { this._statusSubscription = this.control.statusChanges.subscribe(() => {
this.setErrors(); this.setErrors();
}); });
} }
} }
_fieldControlOnChangeHandler(value: unknown): void { handleFieldControlValueChange(value: unknown): void {
this.onChange(value); this.onChange(value);
this._removeErrors(); this._removeErrors();
} }
...@@ -80,8 +82,8 @@ export abstract class FormControlEditorAbstractComponent implements ControlValue ...@@ -80,8 +82,8 @@ export abstract class FormControlEditorAbstractComponent implements ControlValue
} }
ngOnDestroy(): void { ngOnDestroy(): void {
if (this._changesSubscr) this._changesSubscr.unsubscribe(); if (this._changesSubscription) this._changesSubscription.unsubscribe();
if (this._statusSubscr) this._statusSubscr.unsubscribe(); if (this._statusSubscription) this._statusSubscription.unsubscribe();
} }
setErrors(): void { setErrors(): void {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment