diff --git a/src/app/modules/shared/components/details-fields/details-fields.component.html b/src/app/modules/shared/components/details-fields/details-fields.component.html index dc9b43965..d3dd2cd6a 100644 --- a/src/app/modules/shared/components/details-fields/details-fields.component.html +++ b/src/app/modules/shared/components/details-fields/details-fields.component.html @@ -137,6 +137,17 @@ +
+ +
+ + {{ this.getTimeDifference() }} + +
+
+ { expect(endDateInput.id).toEqual('end_date'); expect(endDateInput.max).toEqual(expectedDate); }); + + const diffParams = [ + { + case: 'positive should return correctly diff', + entryDates: { + start_date: '2021-04-15', + end_date: '2021-04-15', + start_hour: '18:05', + end_hour: '19:00', + }, + expectedTimeDiff: '00:55', + }, + { + case: 'negative should return 00:00', + entryDates: { + start_date: '2021-04-15', + end_date: '2021-04-14', + start_hour: '18:05', + end_hour: '17:00', + }, + expectedTimeDiff: '00:00', + }, + ]; + diffParams.map((param) => { + it(`if [start_date, start_hour] and [end_date, end_hour] diff is ${param.case}`, () => { + component.entryForm.setValue({ ...formValues, ...param.entryDates }); + const timeDiff = component.getTimeDifference(); + + expect(timeDiff).toBe(param.expectedTimeDiff); + }); + }); + /* TODO As part of https://github.com/ioet/time-tracker-ui/issues/424 a new parameter was added to the details-field-component, and now these couple of tests are failing. A solution to this error might be generate a Test Wrapper Component. More details here: 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 b2893c57f..a684f5871 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 @@ -130,6 +130,17 @@ export class DetailsFieldsComponent implements OnChanges, OnInit { this.end_date.setValue($event); } + getTimeDifference(): string { + const startDate = moment(`${this.start_date.value} ${this.start_hour.value}`); + const endDate = moment(`${this.end_date.value} ${this.end_hour.value}`); + if (startDate <= endDate) { + const diffDate = endDate.diff(startDate); + const duration = moment.duration(diffDate); + return moment.utc(duration.asMilliseconds()).format('HH:mm'); + } + return '00:00'; + } + ngOnChanges(): void { this.goingToWorkOnThis = this.entryToEdit ? this.entryToEdit.running : false; this.shouldRestartEntry = false;