Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: #357 allow to enter data in the same hour minute
  • Loading branch information
enriquezrene committed Jun 11, 2020
commit 6e5348c878a4da78e44afa2ed053e827c89df47f
1 change: 0 additions & 1 deletion src/app/modules/login/services/azure.ad.b2c.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export class AzureAdB2CService {
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,36 @@ describe('DetailsFieldsComponent', () => {
expect(component.entryForm.value).toEqual(formValues);
});

it('returns the current elapsed seconds when date has more than 2', () => {
const seconds = 12;
const date = new Date();
date.setSeconds(seconds);

const elapsedSeconds = component.getElapsedSeconds(date);

expect(elapsedSeconds).toEqual(seconds.toString());
});

it('returns 02 when seconds 0', () => {
const seconds = 0;
const date = new Date();
date.setSeconds(seconds);

const elapsedSeconds = component.getElapsedSeconds(date);

expect(elapsedSeconds).toEqual('02');
});

it('returns 02 when seconds 1', () => {
const seconds = 1;
const date = new Date();
date.setSeconds(seconds);

const elapsedSeconds = component.getElapsedSeconds(date);

expect(elapsedSeconds).toEqual('02');
});

it('should emit ngOnChange with new data', () => {
const childComponent = jasmine.createSpyObj('ChildComponent', ['closeModal']);
component.closeModal = childComponent;
Expand Down Expand Up @@ -154,6 +184,7 @@ describe('DetailsFieldsComponent', () => {

it('should emit saveEntry event', () => {
spyOn(component.saveEntry, 'emit');
spyOn(component, 'getElapsedSeconds').and.returnValue('11');
component.entryForm.setValue({
project_id: '',
activity_id: '',
Expand All @@ -170,8 +201,8 @@ describe('DetailsFieldsComponent', () => {
activity_id: '',
technologies: [],
description: '',
start_date: '2020-02-05T00:00',
end_date: '2020-02-05T00:01',
start_date: '2020-02-05T00:00:11',
end_date: '2020-02-05T00:01:01',
uri: '',
};
expect(component.saveEntry.emit).toHaveBeenCalledWith(data);
Expand Down Expand Up @@ -225,6 +256,7 @@ describe('DetailsFieldsComponent', () => {

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

component.entryForm.setValue({...formValues, entry_date: '2020-06-11'});
Expand All @@ -234,9 +266,10 @@ describe('DetailsFieldsComponent', () => {
activity_id: '',
technologies: [],
description: '',
start_date: '2020-06-11T00:00',
start_date: '2020-06-11T00:00:10',
uri: 'ticketUri',
};

expect(component.saveEntry.emit).toHaveBeenCalledWith(data);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NumberFormatter } from './../../formatters/number.formatter';
import { Component, ElementRef, EventEmitter, Input, OnChanges, OnInit, Output, ViewChild, } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { select, Store } from '@ngrx/store';
Expand Down Expand Up @@ -144,8 +145,8 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
activity_id: this.entryForm.value.activity_id,
technologies: this.selectedTechnologies ? this.selectedTechnologies : [],
description: this.entryForm.value.description,
start_date: `${entryDate}T${this.entryForm.value.start_hour.trim()}`,
end_date: `${entryDate}T${this.entryForm.value.end_hour.trim()}`,
start_date: `${entryDate}T${this.entryForm.value.start_hour.trim()}:${this.getElapsedSeconds(new Date())}`,
end_date: `${entryDate}T${this.entryForm.value.end_hour.trim()}:01`,
uri: this.entryForm.value.uri,
};
if (this.isEntryRunning) {
Expand All @@ -154,10 +155,19 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
this.saveEntry.emit(entry);
}

getElapsedSeconds(date: Date): string {
const currentSeconds = date.getSeconds();
if (currentSeconds < 2) {
return '02';
} else {
return new NumberFormatter(currentSeconds).getAsAtLeastTwoDigitString();
}
}

onIsRunningChange(event: any) {
this.isEntryRunning = event.currentTarget.checked;
if (!this.isEntryRunning) {
this.entryForm.patchValue({end_hour: formatDate(new Date(), 'HH:mm', 'en')});
this.entryForm.patchValue({ end_hour: formatDate(new Date(), 'HH:mm', 'en') });
}
}
}
17 changes: 17 additions & 0 deletions src/app/modules/shared/formatters/number.formatter.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { NumberFormatter } from './number.formatter';
describe('NumberFormatter', () => {

it('adds a 0 if value < 10', () => {
const numberFormatter = new NumberFormatter(9);

expect(numberFormatter.getAsAtLeastTwoDigitString()).toEqual('09');
});

it('returns the same value if number < 10', () => {
const numberMajorThan10 = 19;
const numberFormatter = new NumberFormatter(numberMajorThan10);

expect(numberFormatter.getAsAtLeastTwoDigitString()).toEqual(numberMajorThan10.toString());
});

});
9 changes: 9 additions & 0 deletions src/app/modules/shared/formatters/number.formatter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export class NumberFormatter {

constructor(private value: number) { }

getAsAtLeastTwoDigitString(): string {
const atLeastTwoDigit = (this.value < 10) ? '0' + this.value : this.value.toString();
return atLeastTwoDigit;
}
}
1 change: 0 additions & 1 deletion src/app/modules/shared/models/entry.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export interface Entry {
end_date: Date;
activity_id?: string;
technologies: string[];
comments?: string;
uri?: string;
project_id?: string;
owner_email?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NumberFormatter } from './../../formatters/number.formatter';
import { Pipe, PipeTransform } from '@angular/core';
import * as moment from 'moment';
@Pipe({
Expand All @@ -18,8 +19,7 @@ export class SubstractDatePipe implements PipeTransform {
}

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

}
2 changes: 1 addition & 1 deletion src/app/modules/time-clock/store/entry.reducer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('entryReducer', () => {

const entry: Entry = {
project_id: '123',
comments: 'description',
description: 'description',
technologies: ['angular', 'javascript'],
uri: 'uri',
id: 'id',
Expand Down