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
Next Next commit
fix: TT-236 fix bug in details-fields 'Im working on this'
  • Loading branch information
thegreatyamori committed May 6, 2021
commit f183ac6c863d68f48dbab215a8ce7ae82807ff4c
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,7 @@ describe('DetailsFieldsComponent', () => {
component.ngOnChanges();
expect(component.shouldRestartEntry).toBeFalse();
expect(component.entryForm.value).toEqual(initialData);
component.activities$.subscribe(item => {
expect(item.length).not.toBe(null);
expect(item.length).toBe(3);
});
expect(component.activities$).toBe(undefined);
});

it('should emit ngOnChange with new data', () => {
Expand Down Expand Up @@ -233,22 +230,11 @@ describe('DetailsFieldsComponent', () => {
component.ngOnChanges();

component.activities$.subscribe(items => {
console.log(items);

expect(items.length).toBe(param.expected_size_activities);
});
});
});

it('selectActiveActivities should return 3 active activities', () => {
const activeActivities = component.selectActiveActivities();

activeActivities.subscribe(item => {
expect(item.length).not.toBe(null);
expect(item.length).toBe(3);
});
});

it('should call createError ', () => {
const childComponent = jasmine.createSpyObj('ChildComponent', ['closeModal']);
component.closeModal = childComponent;
Expand Down Expand Up @@ -621,6 +607,20 @@ describe('DetailsFieldsComponent', () => {
expect(result).toBe(param.expected_result);
});
});

it('should display an error message when isStartTimeEntryAfterEndedEntry() is true & goingToWorkOnThis is false', () => {
const times = {
start_date: '2021-04-21',
end_date: '2021-04-21',
start_hour: '10:00',
end_hour: '00:00',
};
component.goingToWorkOnThis = false;
component.entryForm.setValue({ ...formValues, ...times });
const displayError = component.isStartTimeEntryAfterEndedEntry() && !component.goingToWorkOnThis;
component.onSubmit();
expect(displayError).toBeTrue();
});
/*
TODO As part of https://github.com/ioet/time-tracker-ui/issues/424 a new parameter was added to the details-field-component,
and now these couple of tests are failing. A solution to this error might be generate a Test Wrapper Component. More details here:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
});

this.store.dispatch(new LoadActivities());
this.activities$ = this.selectActiveActivities();

const updateError$ = this.store.pipe(select(getUpdateError));
updateError$.subscribe((updateError) => {
Expand Down Expand Up @@ -141,7 +140,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
}

ngOnChanges(): void {
this.goingToWorkOnThis = this.entryToEdit ? this.entryToEdit.running : false;
this.goingToWorkOnThis = this.entryToEdit ? this.entryToEdit.running ?? true : false;
this.shouldRestartEntry = false;

if (this.entryToEdit) {
Expand Down Expand Up @@ -172,7 +171,6 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
);
} else {
this.cleanForm();
this.activities$ = this.selectActiveActivities();
}
}

Expand All @@ -199,10 +197,6 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
this.cleanForm(true);
}

selectActiveActivities() {
return this.store.pipe(select(allActiveActivities));
}

findInactiveActivity(activities) {
return activities.find(activity => activity.status === 'inactive' &&
activity.id === this.entryToEdit.activity_id
Expand Down Expand Up @@ -276,7 +270,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
const startDateToSubmit = this.dateToSubmit('start_date', 'start_hour');
const endDateToSubmit = this.dateToSubmit('end_date', 'end_hour');

if (this.isStartTimeEntryAfterEndedEntry()) {
if (this.isStartTimeEntryAfterEndedEntry() && !this.goingToWorkOnThis) {
this.toastrService.error('You must end the time entry after it started');
return;
}
Expand All @@ -291,6 +285,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
uri: this.entryForm.value.uri,
timezone_offset: new Date().getTimezoneOffset(),
};

if (this.goingToWorkOnThis) {
delete entry.end_date;
}
Expand Down