diff --git a/src/app/modules/login/services/azure.ad.b2c.service.ts b/src/app/modules/login/services/azure.ad.b2c.service.ts index 8871232e7..2a0239fd6 100644 --- a/src/app/modules/login/services/azure.ad.b2c.service.ts +++ b/src/app/modules/login/services/azure.ad.b2c.service.ts @@ -34,7 +34,6 @@ export class AzureAdB2CService { } isAdmin() { - // console.log("Account: " ,this.msal.getAccount()); return this.msal.getAccount()?.idToken?.extension_role === 'time-tracker-admin'; } diff --git a/src/app/modules/shared/components/details-fields/details-fields.component.spec.ts b/src/app/modules/shared/components/details-fields/details-fields.component.spec.ts index b307d5632..6320957ae 100644 --- a/src/app/modules/shared/components/details-fields/details-fields.component.spec.ts +++ b/src/app/modules/shared/components/details-fields/details-fields.component.spec.ts @@ -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; @@ -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: '', @@ -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); @@ -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'}); @@ -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); }); diff --git a/src/app/modules/shared/components/details-fields/details-fields.component.ts b/src/app/modules/shared/components/details-fields/details-fields.component.ts index 623b0611c..8b5ee5d2b 100644 --- a/src/app/modules/shared/components/details-fields/details-fields.component.ts +++ b/src/app/modules/shared/components/details-fields/details-fields.component.ts @@ -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'; @@ -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) { @@ -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') }); } } } diff --git a/src/app/modules/shared/formatters/number.formatter.spec.ts b/src/app/modules/shared/formatters/number.formatter.spec.ts new file mode 100644 index 000000000..7b6ed26d6 --- /dev/null +++ b/src/app/modules/shared/formatters/number.formatter.spec.ts @@ -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()); + }); + +}); diff --git a/src/app/modules/shared/formatters/number.formatter.ts b/src/app/modules/shared/formatters/number.formatter.ts new file mode 100644 index 000000000..2a4c1d6ef --- /dev/null +++ b/src/app/modules/shared/formatters/number.formatter.ts @@ -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; + } +} diff --git a/src/app/modules/shared/models/entry.model.ts b/src/app/modules/shared/models/entry.model.ts index 31ea9c987..bfc4831f7 100644 --- a/src/app/modules/shared/models/entry.model.ts +++ b/src/app/modules/shared/models/entry.model.ts @@ -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; diff --git a/src/app/modules/shared/pipes/substract-date/substract-date.pipe.ts b/src/app/modules/shared/pipes/substract-date/substract-date.pipe.ts index ed031125c..4cd0f3017 100644 --- a/src/app/modules/shared/pipes/substract-date/substract-date.pipe.ts +++ b/src/app/modules/shared/pipes/substract-date/substract-date.pipe.ts @@ -1,3 +1,4 @@ +import { NumberFormatter } from './../../formatters/number.formatter'; import { Pipe, PipeTransform } from '@angular/core'; import * as moment from 'moment'; @Pipe({ @@ -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(); } } diff --git a/src/app/modules/time-clock/store/entry.reducer.spec.ts b/src/app/modules/time-clock/store/entry.reducer.spec.ts index 0f061b741..f2aa88e48 100644 --- a/src/app/modules/time-clock/store/entry.reducer.spec.ts +++ b/src/app/modules/time-clock/store/entry.reducer.spec.ts @@ -29,7 +29,7 @@ describe('entryReducer', () => { const entry: Entry = { project_id: '123', - comments: 'description', + description: 'description', technologies: ['angular', 'javascript'], uri: 'uri', id: 'id',