Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,37 @@ describe('DetailsFieldsComponent', () => {
const foundActivity = component.findInactiveActivity(state.activities.data);
expect(foundActivity).toEqual(expectedActivity);
});

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.forEach((param) => {
it(`${param.case}`, () => {
component.entryForm.setValue({ ...formValues, ...param.entryDates });
const result = component.isStartTimeEntryAfterEndedEntry();

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,
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