Skip to content

Commit 2ef5fa1

Browse files
committed
fix: TT-226 Show user an error message when they try to save a time entry
1 parent 5b2126f commit 2ef5fa1

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,12 @@ describe('DetailsFieldsComponent', () => {
576576
const foundActivity = component.findInactiveActivity(state.activities.data);
577577
expect(foundActivity).toEqual(expectedActivity);
578578
});
579+
580+
it('should return false when the start time entry is not greater than the end time', () => {
581+
const result = component.isStartTimeEntryAfterEndedEntry();
582+
583+
expect(result).toBeFalse();
584+
});
579585
/*
580586
TODO As part of https://github.com/ioet/time-tracker-ui/issues/424 a new parameter was added to the details-field-component,
581587
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)