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
TT-69 fix: adding or editing an entry must not overlap the date of an…
… active entry
  • Loading branch information
Guido Quezada committed Dec 10, 2020
commit ffb67e59ba9a726888e3d1b00d887e20e7a1c917
21 changes: 21 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 @@ -240,6 +240,27 @@ describe('TimeEntriesComponent', () => {
entry: {
project_id: 'p-id',
start_date: '2020-05-05T10:04',
end_date: '2020-05-05T11:04',
description: 'description',
technologies: [],
uri: 'abc',
}, shouldRestartEntry: false
};
component.entryId = 'new-entry';
spyOn(injectedToastrService, 'error');

component.saveEntry(newEntry);

expect(injectedToastrService.error).toHaveBeenCalled();
});

it('displays an error when end date of entry is > than active entry start date', async () => {
component.activeTimeEntry = entry;
const newEntry = {
entry: {
project_id: 'p-id',
start_date: '2020-01-05T10:04',
end_date: '2020-03-05T11:04',
description: 'description',
technologies: [],
uri: 'abc',
Expand Down
6 changes: 3 additions & 3 deletions src/app/modules/time-entries/pages/time-entries.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {

saveEntry(event: SaveEntryEvent): void {
if (this.activeTimeEntry !== null && this.activeTimeEntry !== undefined) {
const entryDateAsIso = new Date(event.entry.start_date).toISOString();
const entryDateAsLocalDate = new Date(entryDateAsIso);
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 && entryDateAsLocalDate > activeEntryAsLocalDate) {
if (!isEditingActiveEntry && (startDateAsLocalDate > activeEntryAsLocalDate || endDateAsLocalDate > activeEntryAsLocalDate)) {
this.toastrService.error('You are on the clock and this entry overlaps it, try with earlier times.');
} else {
this.doSave(event);
Expand Down