Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fix: #566 refactor variables name
  • Loading branch information
Guido Quezada committed Nov 27, 2020
commit 329ab0a617665803d60101d0a65774430db7a4d0
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@
<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>
Expand Down Expand Up @@ -112,13 +112,13 @@
<label class="col-12 col-sm-2">Date out:</label>
<div class="col-12 col-sm-4">
<input
formControlName="departure_date"
id="departure_date"
formControlName="end_date"
id="end_date"
type="date"
class="form-control"
aria-label="Small"
aria-describedby="inputGroup-sizing-sm"
[class.is-invalid]="departure_date.invalid && departure_date.touched"
[class.is-invalid]="end_date.invalid && end_date.touched"
required
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ describe('DetailsFieldsComponent', () => {
project_name: '',
activity_id: '',
uri: '',
entry_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
departure_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 @@ -109,8 +109,8 @@ describe('DetailsFieldsComponent', () => {
project_name: 'name',
activity_id: 'a1',
uri: 'ticketUri',
entry_date: '',
departure_date: '',
start_date: '',
end_date: '',
start_hour: '00:00:10',
end_hour: '00:00:11',
description: '',
Expand Down Expand Up @@ -178,8 +178,8 @@ describe('DetailsFieldsComponent', () => {
project_name: '',
activity_id: '',
uri: '',
entry_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
departure_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 @@ -215,8 +215,8 @@ describe('DetailsFieldsComponent', () => {
project_name: 'p-name',
activity_id: 'a1',
uri: '',
entry_date: '2020-02-05',
departure_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 @@ -291,7 +291,7 @@ describe('DetailsFieldsComponent', () => {
component.goingToWorkOnThis = true;
spyOn(component.saveEntry, 'emit');

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

component.onSubmit();

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

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

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

it('when entry_date is in the future and departure_date is OK then throws an error', () => {
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, entry_date: futureDate, departure_date: currentDate });
component.entryForm.setValue({ ...formValues, start_date: futureDate, end_date: currentDate });
component.onSubmit();

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

it('when entry_date is OK and departure_date is in the future then throws an error future', () => {
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, entry_date: currentDate, departure_date: futureDate });
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 @@ -49,8 +49,8 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
project_name: ['', Validators.required],
activity_id: ['', Validators.required],
description: '',
entry_date: '',
departure_date: '',
start_date: '',
end_date: '',
start_hour: '',
end_hour: '',
uri: '',
Expand Down Expand Up @@ -131,8 +131,8 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
project_id: this.entryToEdit.project_id,
activity_id: this.entryToEdit.activity_id,
description: this.entryToEdit.description,
entry_date: formatDate(get(this.entryToEdit, 'start_date', '') , 'yyyy-MM-dd', 'en'),
departure_date: formatDate(get(this.entryToEdit, 'end_date'), 'yyyy-MM-dd', 'en'),
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,
Expand All @@ -150,8 +150,8 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
project_id: '',
activity_id: '',
description: '',
entry_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
departure_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 @@ -175,12 +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 departure_date() {
return this.entryForm.get('departure_date');
get end_date() {
return this.entryForm.get('end_date');
}

get start_hour() {
Expand All @@ -201,24 +201,24 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
this.toastrService.warning('Make sure to select a project and activity');
return;
}
const entryDate = this.entryForm.value.entry_date;
const departureDate = this.entryForm.value.departure_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(`${departureDate}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());
const isDepartureDateInTheFuture = moment(departureDate).isAfter(moment());
if (isEntryDateInTheFuture || isDepartureDateInTheFuture) {
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