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
Prev Previous commit
TT-69 fix: refactor variables and conidtions
  • Loading branch information
Guido Quezada committed Dec 10, 2020
commit 2540f9c24ba57ba02e2d8c01bb99a2e54066b417
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ describe('TimeEntriesComponent', () => {
expect(component.canMarkEntryAsWIP).toBe(true);
});

it('displays an error when start date of entry is > than active entry start date', async () => {
it('displays an error when start date of entry is greater than active entry start date', async () => {
component.activeTimeEntry = entry;
const newEntry = {
entry: {
Expand All @@ -254,7 +254,7 @@ describe('TimeEntriesComponent', () => {
expect(injectedToastrService.error).toHaveBeenCalled();
});

it('displays an error when end date of entry is > than active entry start date', async () => {
it('displays an error when end date of entry is greater than active entry start date', async () => {
component.activeTimeEntry = entry;
const newEntry = {
entry: {
Expand Down
12 changes: 7 additions & 5 deletions src/app/modules/time-entries/pages/time-entries.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,17 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
}

saveEntry(event: SaveEntryEvent): void {
if (this.activeTimeEntry !== null && this.activeTimeEntry !== undefined) {
if (this.activeTimeEntry) {
const startDateAsLocalDate = new Date(event.entry.start_date);
const endDateAsLocalDate = new Date(event.entry.end_date);
const activeEntryAsLocalDate = new Date(this.activeTimeEntry.start_date);
const isEditingActiveEntry = this.entryId === this.activeTimeEntry.id;
if (!isEditingActiveEntry && (startDateAsLocalDate > activeEntryAsLocalDate || endDateAsLocalDate > activeEntryAsLocalDate)) {
this.toastrService.error('You are on the clock and this entry overlaps it, try with earlier times.');
} else {
const isEditingEntryEqualToActiveEntry = this.entryId === this.activeTimeEntry.id;
const isStartDateLowerThanActiveEntry = startDateAsLocalDate < activeEntryAsLocalDate;
const isEndDateLowerThanActiveEntry = endDateAsLocalDate < activeEntryAsLocalDate;
if(isEditingEntryEqualToActiveEntry && (isStartDateLowerThanActiveEntry || isEndDateLowerThanActiveEntry)){
this.doSave(event);
} else {
this.toastrService.error('You are on the clock and this entry overlaps it, try with earlier times.');
}
} else {
this.doSave(event);
Expand Down