Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Linting errors from fy-select-project.component #2936

Merged
merged 4 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -25,7 +25,7 @@ export class FySelectProjectComponent implements ControlValueAccessor, OnDestroy

@Input() placeholder: string;

@Input() cacheName;
@Input() cacheName: string;

@Input() selectionElement: TemplateRef<ElementRef>;

Expand All @@ -39,29 +39,29 @@ export class FySelectProjectComponent implements ControlValueAccessor, OnDestroy

@Input() validInParent: boolean;

displayValue;
displayValue: string;

innerValue;
innerValue: ExtendedProject;

onTouchedCallback: () => void = noop;

onChangeCallback: (_: any) => void = noop;
onChangeCallback: (value: ExtendedProject) => void = noop;

constructor(private modalController: ModalController, private modalProperties: ModalPropertiesService) {}

get valid() {
get valid(): boolean {
if (this.touchedInParent) {
return this.touchedInParent;
} else {
return true;
}
}

get value(): any {
get value(): ExtendedProject {
return this.innerValue;
}

set value(v: any) {
set value(v: ExtendedProject) {
if (v !== this.innerValue) {
this.innerValue = v;
const selectedOption = this.innerValue;
Expand All @@ -75,9 +75,11 @@ export class FySelectProjectComponent implements ControlValueAccessor, OnDestroy
}
}

ngOnDestroy(): void {}
ngOnDestroy(): void {
return;
}

async openModal() {
async openModal(): Promise<void> {
const projectModal = await this.modalController.create({
component: FyProjectSelectModalComponent,
componentProps: {
Expand All @@ -95,18 +97,19 @@ export class FySelectProjectComponent implements ControlValueAccessor, OnDestroy

await projectModal.present();

const { data } = await projectModal.onWillDismiss();
const { data }: { data?: { label: string; value: ExtendedProject; selected?: boolean } } =
SahilK-027 marked this conversation as resolved.
Show resolved Hide resolved
await projectModal.onWillDismiss();

if (data) {
this.value = data.value;
}
}

onBlur() {
onBlur(): void {
this.onTouchedCallback();
}

writeValue(value: any): void {
writeValue(value: ExtendedProject): void {
if (value !== this.innerValue) {
this.innerValue = value;
const selectedOption = this.innerValue;
Expand All @@ -118,11 +121,11 @@ export class FySelectProjectComponent implements ControlValueAccessor, OnDestroy
}
}

registerOnChange(fn: any) {
registerOnChange(fn: (newValue: ExtendedProject) => void): void {
this.onChangeCallback = fn;
}

registerOnTouched(fn: any) {
registerOnTouched(fn: () => void): void {
this.onTouchedCallback = fn;
}
}
Loading