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

OZG-7974 test improvements

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