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
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ToastrService, IndividualConfig } from 'ngx-toastr';
import { SwitchTimeEntry } from './../../store/entry.actions';
import { FormBuilder } from '@angular/forms';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
Expand All @@ -17,6 +18,9 @@ describe('ProjectListHoverComponent', () => {
let fixture: ComponentFixture<ProjectListHoverComponent>;
let store: MockStore<ProjectState>;
let mockProjectsSelector;
const toastrServiceStub = {
error: (message?: string, title?: string, override?: Partial<IndividualConfig>) => { }
};

const state = {
projects: {
Expand All @@ -41,7 +45,8 @@ describe('ProjectListHoverComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ProjectListHoverComponent, FilterProjectPipe],
providers: [FormBuilder, provideMockStore({ initialState: state })],
providers: [FormBuilder, provideMockStore({ initialState: state }),
{ provide: ToastrService, useValue: toastrServiceStub }],
imports: [HttpClientTestingModule, AutocompleteLibModule],
}).compileComponents();
store = TestBed.inject(MockStore);
Expand Down Expand Up @@ -76,6 +81,15 @@ describe('ProjectListHoverComponent', () => {
expect(store.dispatch).toHaveBeenCalledWith(new UpdateEntryRunning({ id: component.activeEntry.id, project_id: 1 }));
});

it('displays a message when the acitivity_id is null', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you mean activity_id?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops

spyOn(toastrServiceStub, 'error');
component.activeEntry = { activity_id: null };

component.switch(1, 'customer', 'project');

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

it('dispatch a SwitchTimeEntry action', () => {
spyOn(store, 'dispatch');
component.activeEntry = { id: '123' };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ToastrService } from 'ngx-toastr';
import { EntryActionTypes } from './../../store/entry.actions';
import { filter } from 'rxjs/operators';
import { FormGroup, FormBuilder } from '@angular/forms';
Expand Down Expand Up @@ -26,7 +27,8 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
showClockIn: boolean;
updateEntrySubscription: Subscription;

constructor(private formBuilder: FormBuilder, private store: Store<ProjectState>, private actionsSubject$: ActionsSubject) {
constructor(private formBuilder: FormBuilder, private store: Store<ProjectState>,
private actionsSubject$: ActionsSubject, private toastrService: ToastrService) {
this.projectsForm = this.formBuilder.group({ project_id: null, });
}

Expand Down Expand Up @@ -88,8 +90,12 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
}

switch(selectedProject, customerName, name) {
this.store.dispatch(new entryActions.SwitchTimeEntry(this.activeEntry.id, selectedProject));
this.projectsForm.setValue( { project_id: `${customerName} - ${name}`, } );
if (this.activeEntry.activity_id === null) {
this.toastrService.error('Before switching, please select an activity');
} else {
this.store.dispatch(new entryActions.SwitchTimeEntry(this.activeEntry.id, selectedProject));
this.projectsForm.setValue( { project_id: `${customerName} - ${name}`, } );
}
}

ngOnDestroy(): void {
Expand Down