From 2ef5fa10c7abc760e3c5c0cca3dabf300caa9241 Mon Sep 17 00:00:00 2001 From: Israel Pasaca Date: Fri, 30 Apr 2021 09:33:03 -0500 Subject: [PATCH 1/3] fix: TT-226 Show user an error message when they try to save a time entry --- .../details-fields/details-fields.component.spec.ts | 6 ++++++ .../details-fields/details-fields.component.ts | 11 +++++++++++ 2 files changed, 17 insertions(+) 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 92f95babc..fe1c98599 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 @@ -576,6 +576,12 @@ describe('DetailsFieldsComponent', () => { const foundActivity = component.findInactiveActivity(state.activities.data); expect(foundActivity).toEqual(expectedActivity); }); + + it('should return false when the start time entry is not greater than the end time', () => { + const result = component.isStartTimeEntryAfterEndedEntry(); + + expect(result).toBeFalse(); + }); /* TODO As part of https://github.com/ioet/time-tracker-ui/issues/424 a new parameter was added to the details-field-component, and now these couple of tests are failing. A solution to this error might be generate a Test Wrapper Component. More details here: 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 a1d920e81..f16f9e7c3 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 @@ -244,6 +244,12 @@ export class DetailsFieldsComponent implements OnChanges, OnInit { this.closeModal?.nativeElement?.click(); } + isStartTimeEntryAfterEndedEntry(): boolean { + const startDate = moment(`${this.start_date.value} ${this.start_hour.value}`); + const endDate = moment(`${this.end_date.value} ${this.end_hour.value}`); + return startDate >= endDate; + } + dateToSubmit(date, hour) { const entryFormDate = this.entryForm.value[date]; const updatedHour = this.entryForm.value[hour]; @@ -264,6 +270,11 @@ export class DetailsFieldsComponent implements OnChanges, OnInit { const startDateToSubmit = this.dateToSubmit('start_date', 'start_hour'); const endDateToSubmit = this.dateToSubmit('end_date', 'end_hour'); + if (this.isStartTimeEntryAfterEndedEntry()) { + this.toastrService.error('You must end the time entry after it started'); + return; + } + const entry = { project_id: this.entryForm.value.project_id, activity_id: this.entryForm.value.activity_id, From e9abab63d71fe30451eab64e3df2d1bf1ee7b24a Mon Sep 17 00:00:00 2001 From: Israel Pasaca Date: Mon, 3 May 2021 14:57:48 -0500 Subject: [PATCH 2/3] fix: TT-226 solved PR comments --- .../details-fields.component.spec.ts | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) 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 fe1c98599..64d46ba8e 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 @@ -577,10 +577,35 @@ describe('DetailsFieldsComponent', () => { expect(foundActivity).toEqual(expectedActivity); }); - it('should return false when the start time entry is not greater than the end time', () => { - const result = component.isStartTimeEntryAfterEndedEntry(); + const datesParams = [ + { + case: 'should return true when the start time entry is greater than the end time', + entryDates: { + start_date: '2021-04-21', + end_date: '2021-04-21', + start_hour: '20:00', + end_hour: '08:00', + }, + expected_result: true, + }, + { + case: 'should return false when the start time entry is not greater than the end time', + entryDates: { + start_date: '2021-04-21', + end_date: '2021-04-21', + start_hour: '19:00', + end_hour: '20:00', + }, + expected_result: false, + }, + ]; + datesParams.map((param) => { + it(`${param.case}`, () => { + component.entryForm.setValue({ ...formValues, ...param.entryDates }); + const result = component.isStartTimeEntryAfterEndedEntry(); - expect(result).toBeFalse(); + expect(result).toBe(param.expected_result); + }); }); /* TODO As part of https://github.com/ioet/time-tracker-ui/issues/424 a new parameter was added to the details-field-component, From 114323cbf91f8668593218c3c723b88854e4f685 Mon Sep 17 00:00:00 2001 From: Israel Pasaca Date: Mon, 3 May 2021 17:11:37 -0500 Subject: [PATCH 3/3] fix: TT-226 bug solved --- .../components/details-fields/details-fields.component.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 64d46ba8e..cfb9c1570 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 @@ -599,7 +599,7 @@ describe('DetailsFieldsComponent', () => { expected_result: false, }, ]; - datesParams.map((param) => { + datesParams.forEach((param) => { it(`${param.case}`, () => { component.entryForm.setValue({ ...formValues, ...param.entryDates }); const result = component.isStartTimeEntryAfterEndedEntry();