Skip to content

Commit

Permalink
fix keyresult-type tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kcinay055679 committed Jan 14, 2025
1 parent b086d5c commit 196b4ea
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
<div class="okr-form-row okr-form-label-input-container">
<label class="okr-form-label okr-form-col" for="unit">Einheit</label>
<div class="okr-form-input">

<select
[ngClass]="formInputCheck(keyResultForm, 'unit')"
formControlName="unit"
Expand Down Expand Up @@ -98,7 +97,7 @@

<div class="col">
<div class="okr-form-row">
<label class="okr-form-label okr-form-col" for="stretch-goal">Target</label>
<label class="okr-form-label okr-form-col" for="target-goal">Target</label>
<div class="col">
<input
[attr.data-testId]="'target-goal'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import { of } from 'rxjs';
import { getKeyResultForm } from '../../shared/constant-library';
import { KeyResultOrdinal } from '../../shared/types/model/key-result-ordinal';
import { getValueOfForm } from '../../shared/common';
import { KeyResultMetric } from '../../shared/types/model/key-result-metric';

describe('KeyResultTypeComponent', () => {
let component: KeyResultTypeComponent;
let fixture: ComponentFixture<KeyResultTypeComponent>;

const formGroupDirective = new FormGroupDirective([], []);
formGroupDirective.form = getKeyResultForm();

describe('Edit Metric', () => {
beforeEach(() => {
Expand All @@ -27,13 +29,16 @@ describe('KeyResultTypeComponent', () => {
de: de
}),
ReactiveFormsModule],
providers: [FormGroupDirective]
providers: [FormGroupDirective,
{ provide: FormGroupDirective,
useValue: formGroupDirective }]
});
fixture = TestBed.createComponent(KeyResultTypeComponent);
component = fixture.componentInstance;
component.keyResultForm = getKeyResultForm();
component.keyResult = keyResultMetric;
component.keyResult = { ...keyResultMetric } as KeyResultMetric;
component.users = of(users);

fixture.detectChanges();
});

Expand Down Expand Up @@ -124,7 +129,9 @@ describe('KeyResultTypeComponent', () => {
}),
MatAutocompleteModule,
ReactiveFormsModule],
providers: [FormGroupDirective]
providers: [FormGroupDirective,
{ provide: FormGroupDirective,
useValue: formGroupDirective }]
});
fixture = TestBed.createComponent(KeyResultTypeComponent);
component = fixture.componentInstance;
Expand Down Expand Up @@ -198,7 +205,9 @@ describe('KeyResultTypeComponent', () => {
de: de
}),
ReactiveFormsModule],
providers: [FormGroupDirective]
providers: [FormGroupDirective,
{ provide: FormGroupDirective,
useValue: formGroupDirective }]
});
fixture = TestBed.createComponent(KeyResultTypeComponent);
component = fixture.componentInstance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ export class KeyResultTypeComponent implements OnInit {
if (!this.keyResult) {
return;
}

this.keyResultForm.patchValue({ ...this.keyResult });

if (this.currentKeyResultType() == 'metric') {
const keyResultMetric = this.castToMetric(this.keyResult);
const krUnit = Unit[keyResultMetric.unit as keyof typeof Unit];
this.keyResultForm.get('metric')
?.patchValue({ ...keyResultMetric,
targetGoal: 70,
unit: krUnit });
}

Expand Down Expand Up @@ -87,7 +90,6 @@ export class KeyResultTypeComponent implements OnInit {
if (newType !== this.currentKeyResultType() && this.isTypeChangeAllowed()) {
this.keyResultForm.get('keyResultType')
?.setValue(newType);
console.log(this.keyResultForm.get('keyResultType')?.value);
}
this.setValidators(newType);
}
Expand All @@ -114,10 +116,6 @@ export class KeyResultTypeComponent implements OnInit {
*/


isTouchedOrDirty(name: string) {
return this.keyResultForm.get(name)?.dirty || this.keyResultForm.get(name)?.touched || false;
}

invalidOwner(): boolean {
// return (this.isTouchedOrDirty('owner') && (typeof this.keyResultForm.value.owner === 'string' || !this.keyResultForm.value.owner));
return false;
Expand All @@ -132,7 +130,7 @@ export class KeyResultTypeComponent implements OnInit {
}

currentKeyResultType(): string {
return this.keyResultForm.get('keyResultType')?.value;
return this.keyResultForm?.get('keyResultType')?.value;
}

protected readonly getFullNameOfUser = getFullNameOfUser;
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/app/shared/constant-library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ export function getKeyResultForm(): FormGroup {
Validators.minLength(2),
Validators.maxLength(250)]),
description: new FormControl('', [Validators.maxLength(4096)]),
owner: new FormControl({} as User, [Validators.required,
owner: new FormControl<User>({} as User, [Validators.required,
Validators.nullValidator]),
actionList: new FormControl([]),
keyResultType: new FormControl('metric'),
metric: new FormGroup({
unit: new FormControl(Unit.NUMBER, [Validators.required]),
unit: new FormControl<Unit>(Unit.NUMBER, [Validators.required]),
baseline: new FormControl(0, [Validators.required,
Validators.pattern('^-?\\d+\\.?\\d*$')]),
targetGoal: new FormControl(0, [Validators.required,
Expand Down

0 comments on commit 196b4ea

Please sign in to comment.