From aeec0f77eb8cd77c95f07fcb75a9dc280f18be2b Mon Sep 17 00:00:00 2001 From: wobravo Date: Thu, 8 Apr 2021 17:20:43 -0500 Subject: [PATCH 1/8] fix: TT-20 difference hours --- .../details-fields/details-fields.component.html | 9 +++++++++ .../details-fields/details-fields.component.ts | 11 +++++++++++ 2 files changed, 20 insertions(+) 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 48388e267..aebca4a9c 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,15 @@ +
+ +
+ + + +
+
+ Date: Fri, 9 Apr 2021 15:11:00 -0500 Subject: [PATCH 2/8] fix: TT-20 Calculate Difference --- .../details-fields.component.html | 8 +++--- .../details-fields.component.scss | 7 ++++++ .../details-fields.component.ts | 25 +++++++++++++------ 3 files changed, 29 insertions(+), 11 deletions(-) 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 aebca4a9c..f32d7b83d 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,11 +137,13 @@ -
+
- - + + {{ this.getTimeDifference() }}
diff --git a/src/app/modules/shared/components/details-fields/details-fields.component.scss b/src/app/modules/shared/components/details-fields/details-fields.component.scss index 25dd0337a..2095fb49a 100644 --- a/src/app/modules/shared/components/details-fields/details-fields.component.scss +++ b/src/app/modules/shared/components/details-fields/details-fields.component.scss @@ -108,3 +108,10 @@ input[type="date"]::-webkit-clear-button { background-color: #e9ecef; opacity: 1; } + +.border-tag { + border: 1px solid $primary; + padding: 10px; + border-radius: 5px; + margin-top: 10px; +} 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 7ab4c455c..8ed6d4038 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 @@ -129,14 +129,23 @@ export class DetailsFieldsComponent implements OnChanges, OnInit { } getTimeDifference(){ - const horainico = this.start_hour.value; - const horafinal = this.end_hour.value; - console.log(horainico + ' ' + horafinal); - const ab = moment(horainico, 'HH:mm'); - const ac = moment(horafinal, 'HH:mm'); - console.error(moment.duration(ab.diff(ac)).humanize()); - const diff = [moment.duration(ab.diff(ac)).humanize()]; - return diff; + moment.locale('es'); + const hourStart = this.start_hour.value; + const hourEnd = this.end_hour.value; + const ab = moment(hourStart, 'HH:mm'); + const ac = moment(hourEnd, 'HH:mm'); + if (hourStart === '00:00') { + const hourTotal = '00:00'; + return hourTotal; + } + if (hourEnd === '00:00') { + const hourTotal = '00:00'; + return hourTotal; + }else { + const hourTotal = [moment.duration(ab.diff(ac))]; + return hourTotal; + } + } ngOnChanges(): void { From 9e58e856ee4ff40f7252c7b772aede3c7114420f Mon Sep 17 00:00:00 2001 From: wobravo Date: Mon, 12 Apr 2021 16:51:45 -0500 Subject: [PATCH 3/8] fix: TT-20 unit test --- .../details-fields.component.spec.ts | 12 +++++++++ .../details-fields.component.ts | 27 +++++++------------ src/environments/environment.ts | 1 + 3 files changed, 23 insertions(+), 17 deletions(-) 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 39cb76bdc..0b9f3e4ff 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 @@ -493,6 +493,18 @@ describe('DetailsFieldsComponent', () => { expect(endDateInput.id).toEqual('end_date'); expect(endDateInput.max).toEqual(expectedDate); }); + + const params = [ + {formatDate: 'YYY-MM-DD'}, + {dateFormatHour: 'DD/MM/YYYY HH:mm'}, + ]; + params.map((param) => { + fit('should return the difference if there is data in the time in and in the time out', () => { + const date = moment('2016-01-05'); + expect(4).toEqual(component.getTimeDifference()); + }); + }); + /* 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 8ed6d4038..5299c198f 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 @@ -18,7 +18,7 @@ import { EntryActionTypes } from './../../../time-clock/store/entry.actions'; import { SaveEntryEvent } from './save-entry-event'; import { ProjectSelectedEvent } from './project-selected-event'; import { get } from 'lodash'; -import { DATE_FORMAT } from 'src/environments/environment'; +import { DATE_FORMAT, DATE_FORMAT_HOUR } from 'src/environments/environment'; type Merged = TechnologyState & ProjectState & ActivityState & EntryState; @Component({ @@ -129,23 +129,16 @@ export class DetailsFieldsComponent implements OnChanges, OnInit { } getTimeDifference(){ - moment.locale('es'); - const hourStart = this.start_hour.value; - const hourEnd = this.end_hour.value; - const ab = moment(hourStart, 'HH:mm'); - const ac = moment(hourEnd, 'HH:mm'); - if (hourStart === '00:00') { - const hourTotal = '00:00'; - return hourTotal; - } - if (hourEnd === '00:00') { - const hourTotal = '00:00'; - return hourTotal; - }else { - const hourTotal = [moment.duration(ab.diff(ac))]; - return hourTotal; + const startDate = moment(`${this.start_date.value} ${this.start_hour.value}`).format(DATE_FORMAT_HOUR); + const endDate = moment(`${this.end_date.value} ${this.end_hour.value}`).format(DATE_FORMAT_HOUR); + if (this.end_hour.value !== '00:00') { + const diffDate = moment(endDate, DATE_FORMAT_HOUR).diff(moment(startDate, DATE_FORMAT_HOUR)); + const duration = moment.duration(diffDate); + const diferenceTime = Math.floor(duration.asHours()) + moment.utc(diffDate).format(':mm'); + return diferenceTime; + } else { + return '0:00'; } - } ngOnChanges(): void { diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 5b04fe66e..3ed929c3b 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -18,6 +18,7 @@ export const STACK_EXCHANGE_ACCESS_TOKEN = keys.STACK_EXCHANGE_ACCESS_TOKEN; export const AZURE_APP_CONFIGURATION_CONNECTION_STRING = keys.AZURE_APP_CONFIGURATION_CONNECTION_STRING; export const DATE_FORMAT = 'yyyy-MM-dd'; export const DATE_FORMAT_YEAR = 'YYYY-MM-DD'; +export const DATE_FORMAT_HOUR = 'DD/MM/YYYY HH:mm'; export const GROUPS = { ADMIN: 'time-tracker-admin', TESTER: 'time-tracker-tester', From 1166bfef29f4907be0a165bc7cb3beace49f9b7b Mon Sep 17 00:00:00 2001 From: wobravo Date: Thu, 15 Apr 2021 14:34:14 -0500 Subject: [PATCH 4/8] fix: TT-20 testing --- .../details-fields.component.spec.ts | 26 ++++++++++++------- .../details-fields.component.ts | 18 ++++++------- src/environments/environment.ts | 1 - 3 files changed, 25 insertions(+), 20 deletions(-) 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 0b9f3e4ff..9fdda7a7f 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 @@ -494,15 +494,23 @@ describe('DetailsFieldsComponent', () => { expect(endDateInput.max).toEqual(expectedDate); }); - const params = [ - {formatDate: 'YYY-MM-DD'}, - {dateFormatHour: 'DD/MM/YYYY HH:mm'}, - ]; - params.map((param) => { - fit('should return the difference if there is data in the time in and in the time out', () => { - const date = moment('2016-01-05'); - expect(4).toEqual(component.getTimeDifference()); - }); + fit('should return the difference if there is data in the time in and in the time out', () => { + component.ngOnChanges(); + const StartHour = '08:00'; + const EndHour = '19:00'; + const StartDate = '2021-04-14'; + const EndDate = '2021-04-15'; + const startDateInput: HTMLInputElement = fixture.debugElement.nativeElement.querySelector('#start_date'); + const startHourInput: HTMLInputElement = fixture.debugElement.nativeElement.querySelector('#start_hour'); + const endDateInput: HTMLInputElement = fixture.debugElement.nativeElement.querySelector('#end_date'); + const endHourInput: HTMLInputElement = fixture.debugElement.nativeElement.querySelector('#end_hour'); + startDateInput.value = StartDate; + startHourInput.value = StartHour; + endDateInput.value = EndDate; + endHourInput.value = EndHour; + spyOn(component, 'getTimeDifference'); + + expect(component.getTimeDifference).toHaveBeenCalled(); }); /* 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 5299c198f..bb51c79aa 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 @@ -18,7 +18,7 @@ import { EntryActionTypes } from './../../../time-clock/store/entry.actions'; import { SaveEntryEvent } from './save-entry-event'; import { ProjectSelectedEvent } from './project-selected-event'; import { get } from 'lodash'; -import { DATE_FORMAT, DATE_FORMAT_HOUR } from 'src/environments/environment'; +import { DATE_FORMAT} from 'src/environments/environment'; type Merged = TechnologyState & ProjectState & ActivityState & EntryState; @Component({ @@ -128,17 +128,15 @@ export class DetailsFieldsComponent implements OnChanges, OnInit { this.end_date.setValue($event); } - getTimeDifference(){ - const startDate = moment(`${this.start_date.value} ${this.start_hour.value}`).format(DATE_FORMAT_HOUR); - const endDate = moment(`${this.end_date.value} ${this.end_hour.value}`).format(DATE_FORMAT_HOUR); - if (this.end_hour.value !== '00:00') { - const diffDate = moment(endDate, DATE_FORMAT_HOUR).diff(moment(startDate, DATE_FORMAT_HOUR)); + getTimeDifference() { + 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); - const diferenceTime = Math.floor(duration.asHours()) + moment.utc(diffDate).format(':mm'); - return diferenceTime; - } else { - return '0:00'; + return moment.utc(duration.asMilliseconds()).format('HH:mm'); } + return '00:00'; } ngOnChanges(): void { diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 3ed929c3b..5b04fe66e 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -18,7 +18,6 @@ export const STACK_EXCHANGE_ACCESS_TOKEN = keys.STACK_EXCHANGE_ACCESS_TOKEN; export const AZURE_APP_CONFIGURATION_CONNECTION_STRING = keys.AZURE_APP_CONFIGURATION_CONNECTION_STRING; export const DATE_FORMAT = 'yyyy-MM-dd'; export const DATE_FORMAT_YEAR = 'YYYY-MM-DD'; -export const DATE_FORMAT_HOUR = 'DD/MM/YYYY HH:mm'; export const GROUPS = { ADMIN: 'time-tracker-admin', TESTER: 'time-tracker-tester', From 3257cf04f76d56069b4545237774e9a06bc62666 Mon Sep 17 00:00:00 2001 From: wobravo Date: Thu, 15 Apr 2021 18:27:08 -0500 Subject: [PATCH 5/8] fix: TT-20 Calculate time difference when new entries added --- .../details-fields.component.spec.ts | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) 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 9fdda7a7f..367a04168 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 @@ -494,23 +494,24 @@ describe('DetailsFieldsComponent', () => { expect(endDateInput.max).toEqual(expectedDate); }); - fit('should return the difference if there is data in the time in and in the time out', () => { - component.ngOnChanges(); - const StartHour = '08:00'; - const EndHour = '19:00'; - const StartDate = '2021-04-14'; - const EndDate = '2021-04-15'; - const startDateInput: HTMLInputElement = fixture.debugElement.nativeElement.querySelector('#start_date'); - const startHourInput: HTMLInputElement = fixture.debugElement.nativeElement.querySelector('#start_hour'); - const endDateInput: HTMLInputElement = fixture.debugElement.nativeElement.querySelector('#end_date'); - const endHourInput: HTMLInputElement = fixture.debugElement.nativeElement.querySelector('#end_hour'); - startDateInput.value = StartDate; - startHourInput.value = StartHour; - endDateInput.value = EndDate; - endHourInput.value = EndHour; - spyOn(component, 'getTimeDifference'); - - expect(component.getTimeDifference).toHaveBeenCalled(); + 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', + }, + ]; + diffParams.map((param) => { + fit(`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); + }); }); /* From 4144da61414041279ed051235ecac97a7168a39b Mon Sep 17 00:00:00 2001 From: wobravo Date: Thu, 15 Apr 2021 19:28:35 -0500 Subject: [PATCH 6/8] fix: TT-20 Calculate time difference when new entries added --- .../components/details-fields/details-fields.component.spec.ts | 2 +- 1 file changed, 1 insertion(+), 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 367a04168..9c1639ef1 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 @@ -507,7 +507,7 @@ describe('DetailsFieldsComponent', () => { }, ]; diffParams.map((param) => { - fit(`if [start_date, start_hour] and [end_date, end_hour] diff is ${param.case}`, () => { + 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); From e2f74443facef3cb14236f2789f76d02f52ea3bb Mon Sep 17 00:00:00 2001 From: wobravo Date: Fri, 16 Apr 2021 15:45:13 -0500 Subject: [PATCH 7/8] fix: TT-20 Calculate time difference when new entries added --- .../details-fields/details-fields.component.spec.ts | 12 ++++++++++++ .../details-fields/details-fields.component.ts | 2 +- 2 files changed, 13 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 9c1639ef1..5c603ed3b 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 @@ -505,11 +505,23 @@ describe('DetailsFieldsComponent', () => { }, 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); expect(timeDiff).toBe(param.expectedTimeDiff); }); }); 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 bb51c79aa..ee5380204 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 @@ -128,7 +128,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit { this.end_date.setValue($event); } - getTimeDifference() { + 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) { From 7f46d2b9b2534c0e337cd742cba4516c0fce4f4d Mon Sep 17 00:00:00 2001 From: wobravo Date: Fri, 16 Apr 2021 16:06:04 -0500 Subject: [PATCH 8/8] fix: TT-20 Calculate time difference when new entries added --- .../components/details-fields/details-fields.component.spec.ts | 1 - 1 file changed, 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 5c603ed3b..9fe1ac2bc 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 @@ -522,7 +522,6 @@ describe('DetailsFieldsComponent', () => { const timeDiff = component.getTimeDifference(); expect(timeDiff).toBe(param.expectedTimeDiff); - expect(timeDiff).toBe(param.expectedTimeDiff); }); });