Skip to content

Commit 8a713d4

Browse files
authored
fix: TT-226 Show user an error message when they try to save a time e… (#674)
* fix: TT-226 Show user an error message when they try to save a time entry * fix: TT-226 solved PR comments * fix: TT-226 bug solved
1 parent 25f6854 commit 8a713d4

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,37 @@ describe('DetailsFieldsComponent', () => {
578578
const foundActivity = component.findInactiveActivity(state.activities.data);
579579
expect(foundActivity).toEqual(expectedActivity);
580580
});
581+
582+
const datesParams = [
583+
{
584+
case: 'should return true when the start time entry is greater than the end time',
585+
entryDates: {
586+
start_date: '2021-04-21',
587+
end_date: '2021-04-21',
588+
start_hour: '20:00',
589+
end_hour: '08:00',
590+
},
591+
expected_result: true,
592+
},
593+
{
594+
case: 'should return false when the start time entry is not greater than the end time',
595+
entryDates: {
596+
start_date: '2021-04-21',
597+
end_date: '2021-04-21',
598+
start_hour: '19:00',
599+
end_hour: '20:00',
600+
},
601+
expected_result: false,
602+
},
603+
];
604+
datesParams.forEach((param) => {
605+
it(`${param.case}`, () => {
606+
component.entryForm.setValue({ ...formValues, ...param.entryDates });
607+
const result = component.isStartTimeEntryAfterEndedEntry();
608+
609+
expect(result).toBe(param.expected_result);
610+
});
611+
});
581612
/*
582613
TODO As part of https://github.com/ioet/time-tracker-ui/issues/424 a new parameter was added to the details-field-component,
583614
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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,12 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
244244
this.closeModal?.nativeElement?.click();
245245
}
246246

247+
isStartTimeEntryAfterEndedEntry(): boolean {
248+
const startDate = moment(`${this.start_date.value} ${this.start_hour.value}`);
249+
const endDate = moment(`${this.end_date.value} ${this.end_hour.value}`);
250+
return startDate >= endDate;
251+
}
252+
247253
dateToSubmit(date, hour) {
248254
const entryFormDate = this.entryForm.value[date];
249255
const updatedHour = this.entryForm.value[hour];
@@ -264,6 +270,11 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
264270
const startDateToSubmit = this.dateToSubmit('start_date', 'start_hour');
265271
const endDateToSubmit = this.dateToSubmit('end_date', 'end_hour');
266272

273+
if (this.isStartTimeEntryAfterEndedEntry()) {
274+
this.toastrService.error('You must end the time entry after it started');
275+
return;
276+
}
277+
267278
const entry = {
268279
project_id: this.entryForm.value.project_id,
269280
activity_id: this.entryForm.value.activity_id,

0 commit comments

Comments
 (0)