Skip to content

Commit 46be8e9

Browse files
feat: TT-141 Create test to validate the isEdit flag of the DetailsFields component
1 parent 9e20d6e commit 46be8e9

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/app/modules/shared/components/details-fields/details-fields.component.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ describe('DetailsFieldsComponent', () => {
171171

172172
it('should emit ngOnChange without data', () => {
173173
component.entryToEdit = null;
174+
component.isEdit = true;
174175
component.ngOnChanges();
175176
expect(component.shouldRestartEntry).toBeFalse();
176177
expect(component.entryForm.value).toEqual(initialData);
@@ -192,6 +193,7 @@ describe('DetailsFieldsComponent', () => {
192193
technology: '',
193194
};
194195
component.entryToEdit = null;
196+
component.isEdit = true;
195197
component.ngOnChanges();
196198
expect(component.entryForm.value).toEqual(formValue);
197199
});
@@ -443,6 +445,20 @@ describe('DetailsFieldsComponent', () => {
443445
expect(component.projectSelected.emit).toHaveBeenCalledWith(data);
444446
});
445447

448+
it('should clear the form fields', () => {
449+
spyOn(component, 'cleanForm');
450+
component.isEdit = true;
451+
component.ngOnChanges();
452+
expect(component.cleanForm).toHaveBeenCalled();
453+
});
454+
455+
it('should persist entry form value', () => {
456+
spyOn(component, 'cleanForm');
457+
component.isEdit = false;
458+
component.ngOnChanges();
459+
expect(component.cleanForm).toHaveBeenCalledTimes(0);
460+
});
461+
446462
/*
447463
TODO As part of https://github.com/ioet/time-tracker-ui/issues/424 a new parameter was added to the details-field-component,
448464
and now these couple of tests are failing. A solution to this error might be generate a Test Wrapper Component. More details here:

src/app/modules/shared/components/details-fields/details-fields.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
145145
});
146146
} else {
147147
if (this.isEdit) {
148-
this.cleanForm();
148+
this.cleanForm();
149149
}
150150
}
151151
}

0 commit comments

Comments
 (0)