Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: TT-226 Show user an error message when they try to save a time e…
…ntry
  • Loading branch information
eduardisrael committed Apr 30, 2021
commit 2ef5fa10c7abc760e3c5c0cca3dabf300caa9241
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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,
Expand Down