Skip to content

Commit 2a9ee38

Browse files
PaulRC-ioetjosepato87
authored andcommitted
TT-85 fix: fix overlapping seconds on time entries
1 parent 2e23d02 commit 2a9ee38

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ describe('DetailsFieldsComponent', () => {
7676
description: '',
7777
technology: '',
7878
};
79+
const dateTest = moment().format('YYYY-MM-DD');
80+
const endHourTest = moment().format('HH:mm:ss');
81+
const endDateTest = new Date(`${dateTest}T${endHourTest.trim()}`);
82+
const startHourTest = moment().subtract(3, 'hours').format('HH:mm:ss');
83+
const startDateTest = new Date(`${dateTest}T${startHourTest.trim()}`);
7984

8085
beforeEach(waitForAsync(() => {
8186
TestBed.configureTestingModule({
@@ -101,8 +106,8 @@ describe('DetailsFieldsComponent', () => {
101106
project_id: 'id',
102107
activity_id: '',
103108
uri: 'ticketUri',
104-
start_date: null,
105-
end_date: null,
109+
start_date: startDateTest,
110+
end_date: endDateTest,
106111
description: '',
107112
technologies: [],
108113
id: 'xyz'
@@ -314,6 +319,19 @@ describe('DetailsFieldsComponent', () => {
314319
expect(component.saveEntry.emit).toHaveBeenCalledWith(data);
315320
});
316321

322+
fit('onSubmit an entry without change hours, should not modify the start_date and end_date ', () => {
323+
component.entryToEdit = {...entryToEdit, description: 'test', };
324+
fixture.componentInstance.ngOnChanges();
325+
326+
const startHourValue = moment().subtract(3, 'hours').format('HH:mm');
327+
const endHourValue = moment().format('HH:mm');
328+
329+
component.onSubmit();
330+
331+
expect(component.starDateValue).toEqual(startHourValue);
332+
expect(component.endDateValue).toEqual(endHourValue);
333+
});
334+
317335
it('displays error message when the date selected is in the future', () => {
318336
spyOn(toastrServiceStub, 'error');
319337

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
4242
activities: Activity[] = [];
4343
goingToWorkOnThis = false;
4444
shouldRestartEntry = false;
45+
starDateValue;
46+
endDateValue;
4547

4648
constructor(private formBuilder: FormBuilder, private store: Store<Merged>,
4749
private actionsSubject$: ActionsSubject, private toastrService: ToastrService) {
@@ -139,6 +141,8 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
139141
uri: this.entryToEdit.uri,
140142
technology: '',
141143
});
144+
this.starDateValue = formatDate(get(this.entryToEdit, 'start_date', '00:00'), 'HH:mm', 'en');
145+
this.endDateValue = formatDate(get(this.entryToEdit, 'end_date', '00:00'), 'HH:mm', 'en');
142146
} else {
143147
this.cleanForm();
144148
}
@@ -204,13 +208,20 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
204208
}
205209
const startDate = this.entryForm.value.start_date;
206210
const endDate = this.entryForm.value.end_date;
211+
this.starDateValue = this.entryForm.value.start_hour === this.starDateValue ?
212+
this.entryToEdit.start_date :
213+
new Date(`${startDate}T${this.entryForm.value.start_hour.trim()}`).toISOString();
214+
this.endDateValue = this.entryForm.value.end_hour === this.endDateValue ?
215+
this.entryToEdit.end_date :
216+
new Date(`${endDate}T${this.entryForm.value.end_hour.trim()}`).toISOString();
217+
207218
const entry = {
208219
project_id: this.entryForm.value.project_id,
209220
activity_id: this.entryForm.value.activity_id,
210221
technologies: get(this, 'selectedTechnologies', []),
211222
description: this.entryForm.value.description,
212-
start_date: new Date(`${startDate}T${this.entryForm.value.start_hour.trim()}`).toISOString(),
213-
end_date: new Date(`${endDate}T${this.entryForm.value.end_hour.trim()}`).toISOString(),
223+
start_date: this.starDateValue,
224+
end_date: this.endDateValue,
214225
uri: this.entryForm.value.uri,
215226
timezone_offset: new Date().getTimezoneOffset(),
216227
};

0 commit comments

Comments
 (0)