Skip to content

Commit 1166bfe

Browse files
committed
fix: TT-20 testing
1 parent 9e58e85 commit 1166bfe

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
@@ -494,15 +494,23 @@ describe('DetailsFieldsComponent', () => {
494494
expect(endDateInput.max).toEqual(expectedDate);
495495
});
496496

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-
});
497+
fit('should return the difference if there is data in the time in and in the time out', () => {
498+
component.ngOnChanges();
499+
const StartHour = '08:00';
500+
const EndHour = '19:00';
501+
const StartDate = '2021-04-14';
502+
const EndDate = '2021-04-15';
503+
const startDateInput: HTMLInputElement = fixture.debugElement.nativeElement.querySelector('#start_date');
504+
const startHourInput: HTMLInputElement = fixture.debugElement.nativeElement.querySelector('#start_hour');
505+
const endDateInput: HTMLInputElement = fixture.debugElement.nativeElement.querySelector('#end_date');
506+
const endHourInput: HTMLInputElement = fixture.debugElement.nativeElement.querySelector('#end_hour');
507+
startDateInput.value = StartDate;
508+
startHourInput.value = StartHour;
509+
endDateInput.value = EndDate;
510+
endHourInput.value = EndHour;
511+
spyOn(component, 'getTimeDifference');
512+
513+
expect(component.getTimeDifference).toHaveBeenCalled();
506514
});
507515

508516
/*

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

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

131-
getTimeDifference(){
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));
131+
getTimeDifference() {
132+
const startDate = moment(`${this.start_date.value} ${this.start_hour.value}`);
133+
const endDate = moment(`${this.end_date.value} ${this.end_hour.value}`);
134+
if (startDate <= endDate) {
135+
const diffDate = endDate.diff(startDate);
136136
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';
137+
return moment.utc(duration.asMilliseconds()).format('HH:mm');
141138
}
139+
return '00:00';
142140
}
143141

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