Skip to content

Commit 9e58e85

Browse files
committed
fix: TT-20 unit test
1 parent eefd758 commit 9e58e85

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,18 @@ describe('DetailsFieldsComponent', () => {
493493
expect(endDateInput.id).toEqual('end_date');
494494
expect(endDateInput.max).toEqual(expectedDate);
495495
});
496+
497+
const params = [
498+
{formatDate: 'YYY-MM-DD'},
499+
{dateFormatHour: 'DD/MM/YYYY HH:mm'},
500+
];
501+
params.map((param) => {
502+
fit('should return the difference if there is data in the time in and in the time out', () => {
503+
const date = moment('2016-01-05');
504+
expect(4).toEqual(component.getTimeDifference());
505+
});
506+
});
507+
496508
/*
497509
TODO As part of https://github.com/ioet/time-tracker-ui/issues/424 a new parameter was added to the details-field-component,
498510
and now these couple of tests are failing. A solution to this error might be generate a Test Wrapper Component. More details here:

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

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { EntryActionTypes } from './../../../time-clock/store/entry.actions';
1818
import { SaveEntryEvent } from './save-entry-event';
1919
import { ProjectSelectedEvent } from './project-selected-event';
2020
import { get } from 'lodash';
21-
import { DATE_FORMAT } from 'src/environments/environment';
21+
import { DATE_FORMAT, DATE_FORMAT_HOUR } from 'src/environments/environment';
2222

2323
type Merged = TechnologyState & ProjectState & ActivityState & EntryState;
2424
@Component({
@@ -129,23 +129,16 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
129129
}
130130

131131
getTimeDifference(){
132-
moment.locale('es');
133-
const hourStart = this.start_hour.value;
134-
const hourEnd = this.end_hour.value;
135-
const ab = moment(hourStart, 'HH:mm');
136-
const ac = moment(hourEnd, 'HH:mm');
137-
if (hourStart === '00:00') {
138-
const hourTotal = '00:00';
139-
return hourTotal;
140-
}
141-
if (hourEnd === '00:00') {
142-
const hourTotal = '00:00';
143-
return hourTotal;
144-
}else {
145-
const hourTotal = [moment.duration(ab.diff(ac))];
146-
return hourTotal;
132+
const startDate = moment(`${this.start_date.value} ${this.start_hour.value}`).format(DATE_FORMAT_HOUR);
133+
const endDate = moment(`${this.end_date.value} ${this.end_hour.value}`).format(DATE_FORMAT_HOUR);
134+
if (this.end_hour.value !== '00:00') {
135+
const diffDate = moment(endDate, DATE_FORMAT_HOUR).diff(moment(startDate, DATE_FORMAT_HOUR));
136+
const duration = moment.duration(diffDate);
137+
const diferenceTime = Math.floor(duration.asHours()) + moment.utc(diffDate).format(':mm');
138+
return diferenceTime;
139+
} else {
140+
return '0:00';
147141
}
148-
149142
}
150143

151144
ngOnChanges(): void {

src/environments/environment.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const STACK_EXCHANGE_ACCESS_TOKEN = keys.STACK_EXCHANGE_ACCESS_TOKEN;
1818
export const AZURE_APP_CONFIGURATION_CONNECTION_STRING = keys.AZURE_APP_CONFIGURATION_CONNECTION_STRING;
1919
export const DATE_FORMAT = 'yyyy-MM-dd';
2020
export const DATE_FORMAT_YEAR = 'YYYY-MM-DD';
21+
export const DATE_FORMAT_HOUR = 'DD/MM/YYYY HH:mm';
2122
export const GROUPS = {
2223
ADMIN: 'time-tracker-admin',
2324
TESTER: 'time-tracker-tester',

0 commit comments

Comments
 (0)