Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
SahilK-027 committed May 2, 2024
1 parent 7f2c5f2 commit bbe5d3f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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('');
Expand Down Expand Up @@ -78,7 +79,7 @@ describe('FySelectProjectComponent', () => {
projectModalSpy.onWillDismiss.and.returnValue(
Promise.resolve({
data: {
value: 'value1',
value: testProjectV2,
},
})
);
Expand Down Expand Up @@ -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', () => {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ export class FySelectProjectComponent implements ControlValueAccessor, OnDestroy

@Input() validInParent: boolean;

displayValue;
displayValue: string;

innerValue: ExtendedProject | string;
innerValue: ExtendedProject;

onTouchedCallback: () => void = noop;

Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit bbe5d3f

Please sign in to comment.