From bbe5d3fc3ad1189400c73dcbae349be07642b9fc Mon Sep 17 00:00:00 2001 From: SahilK-027 Date: Thu, 2 May 2024 14:40:00 +0530 Subject: [PATCH] minor --- .../fy-select-project.component.spec.ts | 17 +++++++++-------- .../fy-select-project.component.ts | 16 ++++++++-------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/app/shared/components/fy-select-project/fy-select-project.component.spec.ts b/src/app/shared/components/fy-select-project/fy-select-project.component.spec.ts index 9d51f092e3..10046a185b 100644 --- a/src/app/shared/components/fy-select-project/fy-select-project.component.spec.ts +++ b/src/app/shared/components/fy-select-project/fy-select-project.component.spec.ts @@ -9,6 +9,7 @@ import { FormsModule, NG_VALUE_ACCESSOR, ReactiveFormsModule } from '@angular/fo import { MatIconModule } from '@angular/material/icon'; import { MatIconTestingModule } from '@angular/material/icon/testing'; import { click, getElementBySelector, getTextContent } from 'src/app/core/dom-helpers'; +import { testProjectV2 } from 'src/app/core/test-data/projects.spec.data'; describe('FySelectProjectComponent', () => { let component: FySelectProjectComponent; @@ -48,8 +49,8 @@ describe('FySelectProjectComponent', () => { expect(component).toBeTruthy(); }); - it('value(): should set display value to empty string if value is undefined', () => { - component.innerValue = 'value'; + it('value(): should set display value to empty string if value is null', () => { + component.innerValue = null; component.value = undefined; fixture.detectChanges(); expect(component.displayValue).toEqual(''); @@ -78,7 +79,7 @@ describe('FySelectProjectComponent', () => { projectModalSpy.onWillDismiss.and.returnValue( Promise.resolve({ data: { - value: 'value1', + value: testProjectV2, }, }) ); @@ -108,7 +109,7 @@ describe('FySelectProjectComponent', () => { handle: false, }); expect(modalProperties.getModalDefaultProperties).toHaveBeenCalledTimes(1); - expect(component.value).toEqual('value1'); + expect(component.value).toEqual(testProjectV2); }); it('onBlur(): should call a function when onBlur fires and registerOnTouched to trigger', () => { @@ -126,15 +127,15 @@ describe('FySelectProjectComponent', () => { describe('writeValue():', () => { it('should overwrite value', () => { - component.innerValue = 'value2'; + component.innerValue = undefined; fixture.detectChanges(); - component.writeValue(['value']); - expect(component.innerValue).toEqual(['value']); + component.writeValue(testProjectV2); + expect(component.innerValue).toEqual(testProjectV2); }); it('should set display value to empty', () => { - component.innerValue = 'value'; + component.innerValue = null; fixture.detectChanges(); component.writeValue(undefined); diff --git a/src/app/shared/components/fy-select-project/fy-select-project.component.ts b/src/app/shared/components/fy-select-project/fy-select-project.component.ts index 1f852810a1..ce8e07b1c6 100644 --- a/src/app/shared/components/fy-select-project/fy-select-project.component.ts +++ b/src/app/shared/components/fy-select-project/fy-select-project.component.ts @@ -39,9 +39,9 @@ export class FySelectProjectComponent implements ControlValueAccessor, OnDestroy @Input() validInParent: boolean; - displayValue; + displayValue: string; - innerValue: ExtendedProject | string; + innerValue: ExtendedProject; onTouchedCallback: () => void = noop; @@ -57,21 +57,21 @@ export class FySelectProjectComponent implements ControlValueAccessor, OnDestroy } } - get value(): ExtendedProject | string { + get value(): ExtendedProject { return this.innerValue; } - set value(v: ExtendedProject | string) { + set value(v: ExtendedProject) { if (v !== this.innerValue) { this.innerValue = v; const selectedOption = this.innerValue; if (selectedOption) { - this.displayValue = (selectedOption as ExtendedProject).project_name; + this.displayValue = selectedOption.project_name; } else { this.displayValue = ''; } - this.onChangeCallback(v as ExtendedProject); + this.onChangeCallback(v); } } @@ -109,9 +109,9 @@ export class FySelectProjectComponent implements ControlValueAccessor, OnDestroy this.onTouchedCallback(); } - writeValue(value: ExtendedProject | string[]): void { + writeValue(value: ExtendedProject): void { if (value !== this.innerValue) { - this.innerValue = value as ExtendedProject; + this.innerValue = value; const selectedOption = this.innerValue; if (selectedOption) { this.displayValue = selectedOption.project_name;