From 32240db0fc641109abd6fa1b35e3ce5fe2f48192 Mon Sep 17 00:00:00 2001 From: Santiago Pozo Ruiz <38196801+DrFreud1@users.noreply.github.com> Date: Fri, 23 Jul 2021 14:54:12 -0500 Subject: [PATCH] Revert "Tt 289 cannot edit the date of an entry (#708)" This reverts commit d12ce958e974b4407ef9f77a53eff5e4a0362bd8. --- .../details-fields.component.spec.ts | 26 +++++++++++++++++++ .../details-fields.component.ts | 3 ++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/app/modules/shared/components/details-fields/details-fields.component.spec.ts b/src/app/modules/shared/components/details-fields/details-fields.component.spec.ts index 2fa11b8af..42f6e2263 100644 --- a/src/app/modules/shared/components/details-fields/details-fields.component.spec.ts +++ b/src/app/modules/shared/components/details-fields/details-fields.component.spec.ts @@ -418,6 +418,19 @@ describe('DetailsFieldsComponent', () => { expect(component.saveEntry.emit).toHaveBeenCalledWith(data); }); + it('should not modify the start_date when start_hour has not been modified', () => { + const currentDate = moment().format('YYYY-MM-DD'); + const startHour = moment().subtract(3, 'hours').format('HH:mm:ss'); + const expectedStartDate = new Date(`${currentDate}T${startHour.trim()}`); + + component.entryToEdit = { ...entryToEdit, start_date: expectedStartDate }; + fixture.componentInstance.ngOnChanges(); + + component.entryForm.patchValue({ description: 'test' }); + + expect(component.dateToSubmit('start_date', 'start_hour')).toEqual(expectedStartDate); + }); + it('should modify the start_date when start_hour has been modified', () => { const startDate = new Date(mockCurrentDate); @@ -432,6 +445,19 @@ describe('DetailsFieldsComponent', () => { expect(component.dateToSubmit('start_date', 'start_hour')).toEqual(expectedStartDate); }); + it('should not modify the end_date when end_hour has not been modified', () => { + const currentDate = moment().format('YYYY-MM-DD'); + const endHour = moment().subtract(3, 'hours').format('HH:mm:ss'); + const expectedEndDate = new Date(`${currentDate}T${endHour.trim()}`); + + component.entryToEdit = { ...entryToEdit, end_date: expectedEndDate }; + fixture.componentInstance.ngOnChanges(); + + component.entryForm.patchValue({ description: 'test' }); + + expect(component.dateToSubmit('end_date', 'end_hour')).toEqual(expectedEndDate); + }); + it('should modify the end_date when end_hour has been modified', () => { const endDate = new Date(mockCurrentDate); diff --git a/src/app/modules/shared/components/details-fields/details-fields.component.ts b/src/app/modules/shared/components/details-fields/details-fields.component.ts index e36b97433..82b99a121 100644 --- a/src/app/modules/shared/components/details-fields/details-fields.component.ts +++ b/src/app/modules/shared/components/details-fields/details-fields.component.ts @@ -269,7 +269,8 @@ export class DetailsFieldsComponent implements OnChanges, OnInit { const updatedHour = this.entryForm.value[hour]; const updatedDate = new Date(`${entryFormDate}T${updatedHour.trim()}`).toISOString(); const initialDate = get(this.entryToEdit, date, updatedDate); - const dateHasNotChanged = (initialDate === updatedDate); + const initialHour = formatDate(get(this.entryToEdit, date, updatedDate), 'HH:mm', 'en'); + const dateHasNotChanged = updatedHour === initialHour; const result = dateHasNotChanged ? initialDate : updatedDate; return result; }