Skip to content

Commit ecf119f

Browse files
authored
Merge pull request #379 from ioet/357-entries-with-same-hh-mm
fix: #357 allow to enter data in the same hour minute
2 parents d9bb2f8 + 6e5348c commit ecf119f

File tree

8 files changed

+78
-11
lines changed

8 files changed

+78
-11
lines changed

src/app/modules/login/services/azure.ad.b2c.service.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export class AzureAdB2CService {
3434
}
3535

3636
isAdmin() {
37-
// console.log("Account: " ,this.msal.getAccount());
3837
return this.msal.getAccount()?.idToken?.extension_role === 'time-tracker-admin';
3938
}
4039

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

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,36 @@ describe('DetailsFieldsComponent', () => {
116116
expect(component.entryForm.value).toEqual(formValues);
117117
});
118118

119+
it('returns the current elapsed seconds when date has more than 2', () => {
120+
const seconds = 12;
121+
const date = new Date();
122+
date.setSeconds(seconds);
123+
124+
const elapsedSeconds = component.getElapsedSeconds(date);
125+
126+
expect(elapsedSeconds).toEqual(seconds.toString());
127+
});
128+
129+
it('returns 02 when seconds 0', () => {
130+
const seconds = 0;
131+
const date = new Date();
132+
date.setSeconds(seconds);
133+
134+
const elapsedSeconds = component.getElapsedSeconds(date);
135+
136+
expect(elapsedSeconds).toEqual('02');
137+
});
138+
139+
it('returns 02 when seconds 1', () => {
140+
const seconds = 1;
141+
const date = new Date();
142+
date.setSeconds(seconds);
143+
144+
const elapsedSeconds = component.getElapsedSeconds(date);
145+
146+
expect(elapsedSeconds).toEqual('02');
147+
});
148+
119149
it('should emit ngOnChange with new data', () => {
120150
const childComponent = jasmine.createSpyObj('ChildComponent', ['closeModal']);
121151
component.closeModal = childComponent;
@@ -154,6 +184,7 @@ describe('DetailsFieldsComponent', () => {
154184

155185
it('should emit saveEntry event', () => {
156186
spyOn(component.saveEntry, 'emit');
187+
spyOn(component, 'getElapsedSeconds').and.returnValue('11');
157188
component.entryForm.setValue({
158189
project_id: '',
159190
activity_id: '',
@@ -170,8 +201,8 @@ describe('DetailsFieldsComponent', () => {
170201
activity_id: '',
171202
technologies: [],
172203
description: '',
173-
start_date: '2020-02-05T00:00',
174-
end_date: '2020-02-05T00:01',
204+
start_date: '2020-02-05T00:00:11',
205+
end_date: '2020-02-05T00:01:01',
175206
uri: '',
176207
};
177208
expect(component.saveEntry.emit).toHaveBeenCalledWith(data);
@@ -225,6 +256,7 @@ describe('DetailsFieldsComponent', () => {
225256

226257
it('when submitting a entry that is currently running, the end date should not be sent ', () => {
227258
component.isEntryRunning = true;
259+
spyOn(component, 'getElapsedSeconds').and.returnValue('10');
228260
spyOn(component.saveEntry, 'emit');
229261

230262
component.entryForm.setValue({...formValues, entry_date: '2020-06-11'});
@@ -234,9 +266,10 @@ describe('DetailsFieldsComponent', () => {
234266
activity_id: '',
235267
technologies: [],
236268
description: '',
237-
start_date: '2020-06-11T00:00',
269+
start_date: '2020-06-11T00:00:10',
238270
uri: 'ticketUri',
239271
};
272+
240273
expect(component.saveEntry.emit).toHaveBeenCalledWith(data);
241274
});
242275

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { NumberFormatter } from './../../formatters/number.formatter';
12
import { Component, ElementRef, EventEmitter, Input, OnChanges, OnInit, Output, ViewChild, } from '@angular/core';
23
import { FormBuilder, FormGroup } from '@angular/forms';
34
import { select, Store } from '@ngrx/store';
@@ -144,8 +145,8 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
144145
activity_id: this.entryForm.value.activity_id,
145146
technologies: this.selectedTechnologies ? this.selectedTechnologies : [],
146147
description: this.entryForm.value.description,
147-
start_date: `${entryDate}T${this.entryForm.value.start_hour.trim()}`,
148-
end_date: `${entryDate}T${this.entryForm.value.end_hour.trim()}`,
148+
start_date: `${entryDate}T${this.entryForm.value.start_hour.trim()}:${this.getElapsedSeconds(new Date())}`,
149+
end_date: `${entryDate}T${this.entryForm.value.end_hour.trim()}:01`,
149150
uri: this.entryForm.value.uri,
150151
};
151152
if (this.isEntryRunning) {
@@ -154,10 +155,19 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
154155
this.saveEntry.emit(entry);
155156
}
156157

158+
getElapsedSeconds(date: Date): string {
159+
const currentSeconds = date.getSeconds();
160+
if (currentSeconds < 2) {
161+
return '02';
162+
} else {
163+
return new NumberFormatter(currentSeconds).getAsAtLeastTwoDigitString();
164+
}
165+
}
166+
157167
onIsRunningChange(event: any) {
158168
this.isEntryRunning = event.currentTarget.checked;
159169
if (!this.isEntryRunning) {
160-
this.entryForm.patchValue({end_hour: formatDate(new Date(), 'HH:mm', 'en')});
170+
this.entryForm.patchValue({ end_hour: formatDate(new Date(), 'HH:mm', 'en') });
161171
}
162172
}
163173
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { NumberFormatter } from './number.formatter';
2+
describe('NumberFormatter', () => {
3+
4+
it('adds a 0 if value < 10', () => {
5+
const numberFormatter = new NumberFormatter(9);
6+
7+
expect(numberFormatter.getAsAtLeastTwoDigitString()).toEqual('09');
8+
});
9+
10+
it('returns the same value if number < 10', () => {
11+
const numberMajorThan10 = 19;
12+
const numberFormatter = new NumberFormatter(numberMajorThan10);
13+
14+
expect(numberFormatter.getAsAtLeastTwoDigitString()).toEqual(numberMajorThan10.toString());
15+
});
16+
17+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export class NumberFormatter {
2+
3+
constructor(private value: number) { }
4+
5+
getAsAtLeastTwoDigitString(): string {
6+
const atLeastTwoDigit = (this.value < 10) ? '0' + this.value : this.value.toString();
7+
return atLeastTwoDigit;
8+
}
9+
}

src/app/modules/shared/models/entry.model.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export interface Entry {
55
end_date: Date;
66
activity_id?: string;
77
technologies: string[];
8-
comments?: string;
98
uri?: string;
109
project_id?: string;
1110
owner_email?: string;

src/app/modules/shared/pipes/substract-date/substract-date.pipe.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { NumberFormatter } from './../../formatters/number.formatter';
12
import { Pipe, PipeTransform } from '@angular/core';
23
import * as moment from 'moment';
34
@Pipe({
@@ -18,8 +19,7 @@ export class SubstractDatePipe implements PipeTransform {
1819
}
1920

2021
formatTime(time: number): string {
21-
const formattedTime = (time < 10) ? '0' + time : time.toString();
22-
return formattedTime;
22+
return new NumberFormatter(time).getAsAtLeastTwoDigitString();
2323
}
2424

2525
}

src/app/modules/time-clock/store/entry.reducer.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('entryReducer', () => {
2929

3030
const entry: Entry = {
3131
project_id: '123',
32-
comments: 'description',
32+
description: 'description',
3333
technologies: ['angular', 'javascript'],
3434
uri: 'uri',
3535
id: 'id',

0 commit comments

Comments
 (0)