import { TestBed } from '@angular/core/testing' ; import { ToggleFavoriteComponent } from './toggle-favorite.component' ; import { Store } from '@ngrx/store' ; import { ExtensionService } from '@alfresco/adf-extensions' ; import { CoreModule } from '@alfresco/adf-core' ; import { Router } from '@angular/router' ; import { of } from 'rxjs' ; import { TranslateModule } from '@ngx-translate/core' ; import { AppTestingModule } from '../../../testing/app-testing.module' ; describe ( 'ToggleFavoriteComponent' , ( ) => { let component ; let fixture ; let router ; const mockRouter = { url : 'some-url' } ; const mockStore = { dispatch : jasmine . createSpy ( 'dispatch' ) , select : jasmine . createSpy ( 'select' ) . and . returnValue ( of ( { nodes : [ ] } ) ) } ; beforeEach ( ( ) => { TestBed . configureTestingModule ( { imports : [ TranslateModule . forRoot ( ) , CoreModule . forRoot ( ) , AppTestingModule ] , declarations : [ ToggleFavoriteComponent ] , providers : [ ExtensionService , { provide : Store , useValue : mockStore } , { provide : Router , useValue : mockRouter } ] } ) ; fixture = TestBed . createComponent ( ToggleFavoriteComponent ) ; component = fixture . componentInstance ; router = TestBed . inject ( Router ) ; } ) ; afterEach ( ( ) => { mockStore . dispatch . calls . reset ( ) ; } ) ; it ( 'should get selection data on initialization' , ( ) => { expect ( mockStore . select ) . toHaveBeenCalled ( ) ; } ) ; it ( 'should not dispatch reload if route is not specified' , ( ) => { component . data = "['/reload_on_this_route']" ; router . url = '/somewhere_over_the_rainbow' ; fixture . detectChanges ( ) ; component . onToggleEvent ( ) ; expect ( mockStore . dispatch ) . toHaveBeenCalled ( ) ; } ) ; it ( 'should dispatch reload if route is specified' , ( ) => { component . data = "['/reload_on_this_route']" ; router . url = '/reload_on_this_route' ; fixture . detectChanges ( ) ; component . onToggleEvent ( ) ; expect ( mockStore . dispatch ) . toHaveBeenCalled ( ) ; } ) ; } ) ;