Skip to content

Commit 818a16a

Browse files
committed
fix: TT-20 unit test
1 parent 46fb57e commit 818a16a

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
@@ -512,6 +512,18 @@ describe('DetailsFieldsComponent', () => {
512512
expect(endDateInput.id).toEqual('end_date');
513513
expect(endDateInput.max).toEqual(expectedDate);
514514
});
515+
516+
const params = [
517+
{formatDate: 'YYY-MM-DD'},
518+
{dateFormatHour: 'DD/MM/YYYY HH:mm'},
519+
];
520+
params.map((param) => {
521+
fit('should return the difference if there is data in the time in and in the time out', () => {
522+
const date = moment('2016-01-05');
523+
expect(4).toEqual(component.getTimeDifference());
524+
});
525+
});
526+
515527
/*
516528
TODO As part of https://github.com/ioet/time-tracker-ui/issues/424 a new parameter was added to the details-field-component,
517529
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
import { TechnologiesComponent } from '../technologies/technologies.component';
2323

2424
type Merged = TechnologyState & ProjectState & ActivityState & EntryState;
@@ -131,23 +131,16 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
131131
}
132132

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

153146
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)