Skip to content

Commit 6b10b82

Browse files
committed
fix: TT-20 testing
1 parent 818a16a commit 6b10b82

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -513,15 +513,23 @@ describe('DetailsFieldsComponent', () => {
513513
expect(endDateInput.max).toEqual(expectedDate);
514514
});
515515

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-
});
516+
fit('should return the difference if there is data in the time in and in the time out', () => {
517+
component.ngOnChanges();
518+
const StartHour = '08:00';
519+
const EndHour = '19:00';
520+
const StartDate = '2021-04-14';
521+
const EndDate = '2021-04-15';
522+
const startDateInput: HTMLInputElement = fixture.debugElement.nativeElement.querySelector('#start_date');
523+
const startHourInput: HTMLInputElement = fixture.debugElement.nativeElement.querySelector('#start_hour');
524+
const endDateInput: HTMLInputElement = fixture.debugElement.nativeElement.querySelector('#end_date');
525+
const endHourInput: HTMLInputElement = fixture.debugElement.nativeElement.querySelector('#end_hour');
526+
startDateInput.value = StartDate;
527+
startHourInput.value = StartHour;
528+
endDateInput.value = EndDate;
529+
endHourInput.value = EndHour;
530+
spyOn(component, 'getTimeDifference');
531+
532+
expect(component.getTimeDifference).toHaveBeenCalled();
525533
});
526534

527535
/*

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

Lines changed: 8 additions & 10 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, DATE_FORMAT_HOUR } from 'src/environments/environment';
21+
import { DATE_FORMAT } from 'src/environments/environment';
2222
import { TechnologiesComponent } from '../technologies/technologies.component';
2323

2424
type Merged = TechnologyState & ProjectState & ActivityState & EntryState;
@@ -130,17 +130,15 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
130130
this.end_date.setValue($event);
131131
}
132132

133-
getTimeDifference(){
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));
133+
getTimeDifference() {
134+
const startDate = moment(`${this.start_date.value} ${this.start_hour.value}`);
135+
const endDate = moment(`${this.end_date.value} ${this.end_hour.value}`);
136+
if (startDate <= endDate) {
137+
const diffDate = endDate.diff(startDate);
138138
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';
139+
return moment.utc(duration.asMilliseconds()).format('HH:mm');
143140
}
141+
return '00:00';
144142
}
145143

146144
ngOnChanges(): void {

src/environments/environment.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ 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';
2221
export const GROUPS = {
2322
ADMIN: 'time-tracker-admin',
2423
TESTER: 'time-tracker-tester',

0 commit comments

Comments
 (0)