Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ describe('DetailsFieldsComponent', () => {

it('should emit saveEntry event', () => {
spyOn(component.saveEntry, 'emit');
component.entryToEdit = { ...entryToEdit };
component.entryForm.setValue({
project_id: 'p1',
project_name: 'p-name',
Expand Down Expand Up @@ -311,7 +310,6 @@ describe('DetailsFieldsComponent', () => {
component.goingToWorkOnThis = true;
spyOn(component.saveEntry, 'emit');

component.entryToEdit = { ...entryToEdit };
component.entryForm.setValue({ ...formValues, start_date: '2020-06-11', end_date: '2020-06-11' });

component.onSubmit();
Expand Down Expand Up @@ -392,7 +390,6 @@ describe('DetailsFieldsComponent', () => {
it('displays error message when the date selected is in the future', () => {
spyOn(toastrServiceStub, 'error');

component.entryToEdit = { ...entryToEdit };
const futureDate = moment().add(1, 'days').format(DATE_FORMAT_YEAR);
component.entryForm.setValue({ ...formValues, start_date: futureDate, end_date: futureDate });
component.onSubmit();
Expand All @@ -403,7 +400,6 @@ describe('DetailsFieldsComponent', () => {
it('when start_date is in the future and end_date is OK then throws an error', () => {
spyOn(toastrServiceStub, 'error');

component.entryToEdit = { ...entryToEdit };
const futureDate = moment().add(1, 'days').format(DATE_FORMAT_YEAR);
const currentDate = moment().format(DATE_FORMAT_YEAR);
component.entryForm.setValue({ ...formValues, start_date: futureDate, end_date: currentDate });
Expand All @@ -415,7 +411,6 @@ describe('DetailsFieldsComponent', () => {
it('when start_date is OK and end_date is in the future then throws an error future', () => {
spyOn(toastrServiceStub, 'error');

component.entryToEdit = { ...entryToEdit };
const futureDate = moment().add(1, 'days').format(DATE_FORMAT_YEAR);
const currentDate = moment().format(DATE_FORMAT_YEAR);
component.entryForm.setValue({ ...formValues, start_date: currentDate, end_date: futureDate });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
dateToSubmit(date, hour) {
const entryFormDate = this.entryForm.value[date];
const updatedHour = this.entryForm.value[hour];
const initialDate = this.entryToEdit[date];
const updatedDate = new Date(`${entryFormDate}T${updatedHour.trim()}`).toISOString();
const initialHour = formatDate(get(this.entryToEdit, date, '00:00'), 'HH:mm', 'en');
const initialDate = get(this.entryToEdit, date, updatedDate);
const initialHour = formatDate(get(this.entryToEdit, date, updatedDate), 'HH:mm', 'en');
const dateHasNotChanged = updatedHour === initialHour;
const result = dateHasNotChanged ? initialDate : updatedDate;
return result;
Expand Down