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
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,20 @@


<div class="form-group row">
<label class="col-12 col-sm-2 col-form-label">Date:</label>
<div class="col-12 col-sm-10">
<label class="col-12 col-sm-2">Date in:</label>
<div class="col-12 col-sm-4">
<input
formControlName="entry_date"
id="entry_date"
formControlName="start_date"
id="start_date"
type="date"
class="form-control"
aria-label="Small"
aria-describedby="inputGroup-sizing-sm"
[class.is-invalid]="entry_date.invalid && entry_date.touched"
[class.is-invalid]="start_date.invalid && start_date.touched"
required
/>
</div>
</div>


<div class="form-group row">
<label class="col-12 col-sm-2">Time in:</label>
<div class="col-12 col-sm-4">
<input
Expand All @@ -108,11 +105,27 @@
aria-describedby="inputGroup-sizing-sm"
/>
</div>
</div>


<div class="form-group row" *ngIf="!goingToWorkOnThis">
<label class="col-12 col-sm-2">Date out:</label>
<div class="col-12 col-sm-4">
<input
formControlName="end_date"
id="end_date"
type="date"
class="form-control"
aria-label="Small"
aria-describedby="inputGroup-sizing-sm"
[class.is-invalid]="end_date.invalid && end_date.touched"
required
/>
</div>

<label class="col-12 col-sm-2" *ngIf="!goingToWorkOnThis">Time out:</label>
<div class="col-12 col-sm-4" *ngIf="!goingToWorkOnThis">
<label class="col-12 col-sm-2">Time out:</label>
<div class="col-12 col-sm-4">
<input
*ngIf="!goingToWorkOnThis"
[clearIfNotMatch]="true"
[showMaskTyped]="true"
[dropSpecialCharacters]="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ describe('DetailsFieldsComponent', () => {
project_name: '',
activity_id: '',
uri: '',
entry_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
start_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
end_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
start_hour: '00:00:00',
end_hour: '00:00:00',
description: '',
Expand Down Expand Up @@ -108,7 +109,8 @@ describe('DetailsFieldsComponent', () => {
project_name: 'name',
activity_id: 'a1',
uri: 'ticketUri',
entry_date: '',
start_date: '',
end_date: '',
start_hour: '00:00:10',
end_hour: '00:00:11',
description: '',
Expand Down Expand Up @@ -176,7 +178,8 @@ describe('DetailsFieldsComponent', () => {
project_name: '',
activity_id: '',
uri: '',
entry_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
start_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
end_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
start_hour: '00:00:00',
end_hour: '00:00:00',
description: '',
Expand Down Expand Up @@ -212,7 +215,8 @@ describe('DetailsFieldsComponent', () => {
project_name: 'p-name',
activity_id: 'a1',
uri: '',
entry_date: '2020-02-05',
start_date: '2020-02-05',
end_date: '2020-02-05',
start_hour: '00:00:01',
end_hour: '00:01:01',
description: '',
Expand Down Expand Up @@ -287,7 +291,7 @@ describe('DetailsFieldsComponent', () => {
component.goingToWorkOnThis = true;
spyOn(component.saveEntry, 'emit');

component.entryForm.setValue({ ...formValues, entry_date: '2020-06-11' });
component.entryForm.setValue({ ...formValues, start_date: '2020-06-11', end_date: '2020-06-11' });

component.onSubmit();

Expand All @@ -311,7 +315,29 @@ describe('DetailsFieldsComponent', () => {
spyOn(toastrServiceStub, 'error');

const futureDate = moment().add(1, 'days').format('YYYY-MM-DD');
component.entryForm.setValue({ ...formValues, entry_date: futureDate });
component.entryForm.setValue({ ...formValues, start_date: futureDate, end_date: futureDate });
component.onSubmit();

expect(toastrServiceStub.error).toHaveBeenCalled();
});

it('when start_date is in the future and end_date is OK then throws an error', () => {
spyOn(toastrServiceStub, 'error');

const futureDate = moment().add(1, 'days').format('YYYY-MM-DD');
const currentDate = moment().format('YYYY-MM-DD');
component.entryForm.setValue({ ...formValues, start_date: futureDate, end_date: currentDate });
component.onSubmit();

expect(toastrServiceStub.error).toHaveBeenCalled();
});

it('when start_date is OK and end_date is in the future then throws an error future', () => {
spyOn(toastrServiceStub, 'error');

const futureDate = moment().add(1, 'days').format('YYYY-MM-DD');
const currentDate = moment().format('YYYY-MM-DD');
component.entryForm.setValue({ ...formValues, start_date: currentDate, end_date: futureDate });
component.onSubmit();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add a couple of tests here:

  1. start_date in the future / end date OK
  2. start_date OK / end date in the future

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


expect(toastrServiceStub.error).toHaveBeenCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { TechnologyState } from '../../store/technology.reducers';
import { EntryActionTypes } from './../../../time-clock/store/entry.actions';
import { SaveEntryEvent } from './save-entry-event';
import { ProjectSelectedEvent } from './project-selected-event';
import { get } from 'lodash';


type Merged = TechnologyState & ProjectState & ActivityState & EntryState;
Expand Down Expand Up @@ -48,7 +49,8 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
project_name: ['', Validators.required],
activity_id: ['', Validators.required],
description: '',
entry_date: '',
start_date: '',
end_date: '',
start_hour: '',
end_hour: '',
uri: '',
Expand Down Expand Up @@ -129,9 +131,10 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
project_id: this.entryToEdit.project_id,
activity_id: this.entryToEdit.activity_id,
description: this.entryToEdit.description,
entry_date: this.entryToEdit.start_date ? formatDate(this.entryToEdit.start_date, 'yyyy-MM-dd', 'en') : '',
start_hour: this.entryToEdit.start_date ? formatDate(this.entryToEdit.start_date, 'HH:mm:ss', 'en') : '00:00:00',
end_hour: this.entryToEdit.end_date ? formatDate(this.entryToEdit.end_date, 'HH:mm:ss', 'en') : '00:00:00',
start_date: formatDate(get(this.entryToEdit, 'start_date', '') , 'yyyy-MM-dd', 'en'),
end_date: formatDate(get(this.entryToEdit, 'end_date'), 'yyyy-MM-dd', 'en'),
start_hour: formatDate(get(this.entryToEdit, 'start_date', '00:00:00'), 'HH:mm:ss', 'en'),
end_hour: formatDate(get(this.entryToEdit, 'end_date', '00:00:00'), 'HH:mm:ss', 'en'),
uri: this.entryToEdit.uri,
technology: '',
});
Expand All @@ -147,7 +150,8 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
project_id: '',
activity_id: '',
description: '',
entry_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
start_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
end_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
start_hour: '00:00:00',
end_hour: '00:00:00',
uri: '',
Expand All @@ -171,8 +175,12 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
return this.entryForm.get('activity_id');
}

get entry_date() {
return this.entryForm.get('entry_date');
get start_date() {
return this.entryForm.get('start_date');
}

get end_date() {
return this.entryForm.get('end_date');
}

get start_hour() {
Expand All @@ -193,23 +201,24 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
this.toastrService.warning('Make sure to select a project and activity');
return;
}
// start&end date same for now
const entryDate = this.entryForm.value.entry_date;
const startDate = this.entryForm.value.start_date;
const endDate = this.entryForm.value.end_date;
const entry = {
project_id: this.entryForm.value.project_id,
activity_id: this.entryForm.value.activity_id,
technologies: this.selectedTechnologies ? this.selectedTechnologies : [],
technologies: get(this, 'selectedTechnologies', []),
description: this.entryForm.value.description,
start_date: new Date(`${entryDate}T${this.entryForm.value.start_hour.trim()}`).toISOString(),
end_date: new Date(`${entryDate}T${this.entryForm.value.end_hour.trim()}`).toISOString(),
start_date: new Date(`${startDate}T${this.entryForm.value.start_hour.trim()}`).toISOString(),
end_date: new Date(`${endDate}T${this.entryForm.value.end_hour.trim()}`).toISOString(),
uri: this.entryForm.value.uri,
timezone_offset: new Date().getTimezoneOffset(),
};
if (this.goingToWorkOnThis) {
delete entry.end_date;
}
const isEntryDateInTheFuture = moment(entryDate).isAfter(moment());
if (isEntryDateInTheFuture) {
const isStartDateInTheFuture = moment(startDate).isAfter(moment());
const isEndDateInTheFuture = moment(endDate).isAfter(moment());
if (isStartDateInTheFuture || isEndDateInTheFuture) {
this.toastrService.error('You cannot start a time-entry in the future');
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@ describe('TimeEntriesComponent', () => {
uri : 'http://testing.is.fun',
activity_id : 'sss',
project_id : 'id',
start_date : new Date(new Date().setHours(0, 0, 0, 0))
start_date : new Date(new Date().setHours(0, 0, 0, 0)),
end_date : new Date(new Date().setHours(0, 0, 0, 0))
};
state.timeEntriesDataSource.data = [ lastEntry ];
mockEntriesSelector = store.overrideSelector(getTimeEntriesDataSource, state.timeEntriesDataSource);
Expand Down
3 changes: 2 additions & 1 deletion src/app/modules/time-entries/pages/time-entries.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
uri : dataToUse.uri ? dataToUse.uri : '',
activity_id : dataToUse.activity_id,
project_id : dataToUse.project_id,
start_date : startDate
start_date : startDate,
end_date : startDate
};
this.entry = entry;
}
Expand Down