1+ import { ToastrService , IndividualConfig } from 'ngx-toastr' ;
12import { SwitchTimeEntry } from './../../store/entry.actions' ;
23import { FormBuilder } from '@angular/forms' ;
34import { async , ComponentFixture , TestBed } from '@angular/core/testing' ;
@@ -17,6 +18,9 @@ describe('ProjectListHoverComponent', () => {
1718 let fixture : ComponentFixture < ProjectListHoverComponent > ;
1819 let store : MockStore < ProjectState > ;
1920 let mockProjectsSelector ;
21+ const toastrServiceStub = {
22+ error : ( message ?: string , title ?: string , override ?: Partial < IndividualConfig > ) => { }
23+ } ;
2024
2125 const state = {
2226 projects : {
@@ -41,7 +45,8 @@ describe('ProjectListHoverComponent', () => {
4145 beforeEach ( async ( ( ) => {
4246 TestBed . configureTestingModule ( {
4347 declarations : [ ProjectListHoverComponent , FilterProjectPipe ] ,
44- providers : [ FormBuilder , provideMockStore ( { initialState : state } ) ] ,
48+ providers : [ FormBuilder , provideMockStore ( { initialState : state } ) ,
49+ { provide : ToastrService , useValue : toastrServiceStub } ] ,
4550 imports : [ HttpClientTestingModule , AutocompleteLibModule ] ,
4651 } ) . compileComponents ( ) ;
4752 store = TestBed . inject ( MockStore ) ;
@@ -76,6 +81,15 @@ describe('ProjectListHoverComponent', () => {
7681 expect ( store . dispatch ) . toHaveBeenCalledWith ( new UpdateEntryRunning ( { id : component . activeEntry . id , project_id : 1 } ) ) ;
7782 } ) ;
7883
84+ it ( 'displays a message when the activity_id is null' , ( ) => {
85+ spyOn ( toastrServiceStub , 'error' ) ;
86+ component . activeEntry = { activity_id : null } ;
87+
88+ component . switch ( 1 , 'customer' , 'project' ) ;
89+
90+ expect ( toastrServiceStub . error ) . toHaveBeenCalled ( ) ;
91+ } ) ;
92+
7993 it ( 'dispatch a SwitchTimeEntry action' , ( ) => {
8094 spyOn ( store , 'dispatch' ) ;
8195 component . activeEntry = { id : '123' } ;
0 commit comments