Skip to content

Commit 32240db

Browse files
authored
Revert "Tt 289 cannot edit the date of an entry (#708)"
This reverts commit d12ce95.
1 parent d12ce95 commit 32240db

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/app/modules/shared/components/details-fields/details-fields.component.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,19 @@ describe('DetailsFieldsComponent', () => {
418418
expect(component.saveEntry.emit).toHaveBeenCalledWith(data);
419419
});
420420

421+
it('should not modify the start_date when start_hour has not been modified', () => {
422+
const currentDate = moment().format('YYYY-MM-DD');
423+
const startHour = moment().subtract(3, 'hours').format('HH:mm:ss');
424+
const expectedStartDate = new Date(`${currentDate}T${startHour.trim()}`);
425+
426+
component.entryToEdit = { ...entryToEdit, start_date: expectedStartDate };
427+
fixture.componentInstance.ngOnChanges();
428+
429+
component.entryForm.patchValue({ description: 'test' });
430+
431+
expect(component.dateToSubmit('start_date', 'start_hour')).toEqual(expectedStartDate);
432+
});
433+
421434
it('should modify the start_date when start_hour has been modified', () => {
422435
const startDate = new Date(mockCurrentDate);
423436

@@ -432,6 +445,19 @@ describe('DetailsFieldsComponent', () => {
432445
expect(component.dateToSubmit('start_date', 'start_hour')).toEqual(expectedStartDate);
433446
});
434447

448+
it('should not modify the end_date when end_hour has not been modified', () => {
449+
const currentDate = moment().format('YYYY-MM-DD');
450+
const endHour = moment().subtract(3, 'hours').format('HH:mm:ss');
451+
const expectedEndDate = new Date(`${currentDate}T${endHour.trim()}`);
452+
453+
component.entryToEdit = { ...entryToEdit, end_date: expectedEndDate };
454+
fixture.componentInstance.ngOnChanges();
455+
456+
component.entryForm.patchValue({ description: 'test' });
457+
458+
expect(component.dateToSubmit('end_date', 'end_hour')).toEqual(expectedEndDate);
459+
});
460+
435461
it('should modify the end_date when end_hour has been modified', () => {
436462
const endDate = new Date(mockCurrentDate);
437463

src/app/modules/shared/components/details-fields/details-fields.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
269269
const updatedHour = this.entryForm.value[hour];
270270
const updatedDate = new Date(`${entryFormDate}T${updatedHour.trim()}`).toISOString();
271271
const initialDate = get(this.entryToEdit, date, updatedDate);
272-
const dateHasNotChanged = (initialDate === updatedDate);
272+
const initialHour = formatDate(get(this.entryToEdit, date, updatedDate), 'HH:mm', 'en');
273+
const dateHasNotChanged = updatedHour === initialHour;
273274
const result = dateHasNotChanged ? initialDate : updatedDate;
274275
return result;
275276
}

0 commit comments

Comments
 (0)