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-91 The time out of the penultimate time entry overlaps the ti…
…me entry that is running
  • Loading branch information
lenshinoda committed Jun 3, 2021
commit 48246a4c58cdf949cb74bad538d8242d9e1fd47d
26 changes: 26 additions & 0 deletions src/app/modules/time-entries/pages/time-entries.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,4 +455,30 @@ describe('TimeEntriesComponent', () => {
component.resetDraggablePosition(dragEndEventStub);
expect(dragEndEventStub.source._dragRef.reset).toHaveBeenCalled();
});

it('component.doSave shouldn´t be called when saving the runningEntry with start_date overlapped', () => {
const startDate = new Date(2021, 6, 1, 10, 0);
const endDate = new Date(2021, 6, 1, 10, 55);
const newRunningEntry = { start_date: endDate, id: '1234', technologies: [], project_name: 'time-tracker', running: true };
const newEntry = { start_date: startDate, end_date: endDate, id: '4321', technologies: [], project_name: 'time-tracker'};

state.timeEntriesDataSource.data = [newRunningEntry, newEntry];
component.activeTimeEntry = newRunningEntry;
component.entryId = newRunningEntry.id;
spyOn(component, 'doSave');

const startDateModified = new Date(2021, 6, 1, 10, 50);
Copy link
Collaborator

@scastillo-jp scastillo-jp Jun 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is correct this format?

const RunningEntryModified = {
entry: {
start_date: startDateModified,
id: '1234',
technologies: ['py'],
project_name: 'time-tracker',
running: true
}, shouldRestartEntry: false
};
component.saveEntry(RunningEntryModified);

expect(component.doSave).toHaveBeenCalledTimes(0);
});
});
17 changes: 15 additions & 2 deletions src/app/modules/time-entries/pages/time-entries.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
selectedMonth: number;
selectedYear: number;
selectedMonthAsText: string;
isActiveEntryOverlapping = false;
constructor(private store: Store<EntryState>, private toastrService: ToastrService, private actionsSubject$: ActionsSubject) {
this.timeEntriesDataSource$ = this.store.pipe(delay(0), select(getTimeEntriesDataSource));
}
Expand Down Expand Up @@ -104,8 +105,20 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
const isStartDateGreaterThanActiveEntry = startDateAsLocalDate > activeEntryAsLocalDate;
const isEndDateGreaterThanActiveEntry = endDateAsLocalDate > activeEntryAsLocalDate;
const isTimeEntryOverlapping = isStartDateGreaterThanActiveEntry || isEndDateGreaterThanActiveEntry;
if (!isEditingEntryEqualToActiveEntry && isTimeEntryOverlapping) {
this.toastrService.error('You are on the clock and this entry overlaps it, try with earlier times.');

if (isEditingEntryEqualToActiveEntry) {
this.store.pipe(select(getTimeEntriesDataSource)).subscribe(ds => {
const overlappingEntry = ds.data.find((item) => {
const itemEndDate = new Date(item.end_date);
return startDateAsLocalDate < itemEndDate;
});
this.isActiveEntryOverlapping = overlappingEntry ? true : false;
});
}
if (!isEditingEntryEqualToActiveEntry && isTimeEntryOverlapping || this.isActiveEntryOverlapping ) {
const message = this.isActiveEntryOverlapping ? 'try another "Time in"' : 'try with earlier times';
this.toastrService.error(`You are on the clock and this entry overlaps it, ${message}.`);
this.isActiveEntryOverlapping = false;
} else {
this.doSave(event);
}
Expand Down