From c24420e3a051115a45bc377b059ab46258278ffb Mon Sep 17 00:00:00 2001 From: Albert <Albert.Bruns@mgm-tp.com> Date: Thu, 10 Apr 2025 16:48:28 +0200 Subject: [PATCH] OZG-7974 test improvements --- ...mcontrol-editor.abstract.component.spec.ts | 26 +++++++++---------- .../formcontrol-editor.abstract.component.ts | 16 +++++++----- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/alfa-client/libs/design-component/src/lib/form/formcontrol-editor.abstract.component.spec.ts b/alfa-client/libs/design-component/src/lib/form/formcontrol-editor.abstract.component.spec.ts index c12275820f..d27faa3632 100644 --- a/alfa-client/libs/design-component/src/lib/form/formcontrol-editor.abstract.component.spec.ts +++ b/alfa-client/libs/design-component/src/lib/form/formcontrol-editor.abstract.component.spec.ts @@ -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(); diff --git a/alfa-client/libs/design-component/src/lib/form/formcontrol-editor.abstract.component.ts b/alfa-client/libs/design-component/src/lib/form/formcontrol-editor.abstract.component.ts index 17f8e71999..02760de100 100644 --- a/alfa-client/libs/design-component/src/lib/form/formcontrol-editor.abstract.component.ts +++ b/alfa-client/libs/design-component/src/lib/form/formcontrol-editor.abstract.component.ts @@ -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 { -- GitLab