diff --git a/src/app/modules/shared/components/details-fields/details-fields.component.spec.ts b/src/app/modules/shared/components/details-fields/details-fields.component.spec.ts index d41f565a8..60139632f 100644 --- a/src/app/modules/shared/components/details-fields/details-fields.component.spec.ts +++ b/src/app/modules/shared/components/details-fields/details-fields.component.spec.ts @@ -128,14 +128,14 @@ describe('DetailsFieldsComponent', () => { expect(component).toBeTruthy(); }); - it('onClearedComponent project id and name it is set to empty', () => { + it('onClearedComponent project id and name are set to empty', () => { component.onClearedComponent(null); expect(component.project_id.value).toBe(''); expect(component.project_name.value).toBe(''); }); - it('onSelectedProject project id and name it is set using event data', () => { + it('onSelectedProject project id and name are set using event data', () => { spyOn(component.entryForm, 'patchValue'); component.onSelectedProject( {id: 'id', search_field: 'foo'} ); @@ -143,7 +143,7 @@ describe('DetailsFieldsComponent', () => { expect(component.entryForm.patchValue).toHaveBeenCalledWith( { project_id: 'id', project_name: 'foo', } ); }); - it('if form is invalid then no save is emited', () => { + it('if form is invalid then saveEntry is not emited', () => { spyOn(component.saveEntry, 'emit'); component.onSubmit(); @@ -172,6 +172,7 @@ describe('DetailsFieldsComponent', () => { it('should emit ngOnChange without data', () => { component.entryToEdit = null; component.ngOnChanges(); + expect(component.shouldRestartEntry).toBeFalse(); expect(component.entryForm.value).toEqual(initialData); }); @@ -243,6 +244,7 @@ describe('DetailsFieldsComponent', () => { }, shouldRestartEntry: false }; + expect(component.saveEntry.emit).toHaveBeenCalledWith(data); }); @@ -298,14 +300,23 @@ describe('DetailsFieldsComponent', () => { fixture.componentInstance.ngOnChanges(); expect(component.goingToWorkOnThis).toBeFalse(); + expect(component.shouldRestartEntry).toBeFalse(); }); - it('when editing entry that already finished, then the entry should not be marked as running', () => { - component.entryToEdit = { ...entryToEdit, running: false }; + it('when editing entry is running, shouldRestartEntry should be false', () => { + component.entryToEdit = { ...entryToEdit, running: true }; fixture.componentInstance.ngOnChanges(); - expect(component.goingToWorkOnThis).toBeFalse(); + expect(component.goingToWorkOnThis).toBeTrue(); + expect(component.shouldRestartEntry).toBeFalse(); + }); + + it('when editing entry change to going to work on this shouldRestartEntry should be true', () => { + component.onGoingToWorkOnThisChange({ currentTarget: { checked: true } }); + + expect(component.goingToWorkOnThis).toBeTrue(); + expect(component.shouldRestartEntry).toBeTrue(); }); it('when submitting a entry that is currently running, the end date should not be sent ', () => { @@ -328,6 +339,7 @@ describe('DetailsFieldsComponent', () => { }, shouldRestartEntry: false }; + expect(component.saveEntry.emit).toHaveBeenCalledWith(data); }); diff --git a/src/app/modules/shared/components/details-fields/details-fields.component.ts b/src/app/modules/shared/components/details-fields/details-fields.component.ts index 566960acc..5bc62652d 100644 --- a/src/app/modules/shared/components/details-fields/details-fields.component.ts +++ b/src/app/modules/shared/components/details-fields/details-fields.component.ts @@ -126,6 +126,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit { ngOnChanges(): void { this.goingToWorkOnThis = this.entryToEdit ? this.entryToEdit.running : false; + this.shouldRestartEntry = false; if (this.entryToEdit) { this.selectedTechnologies = this.entryToEdit.technologies; const projectFound = this.listProjects.find((project) => project.id === this.entryToEdit.project_id);