import { TestBed , fakeAsync , tick } from '@angular/core/testing' ; import { AppTestingModule } from '../../testing/app-testing.module' ; import { SearchEffects } from './search.effects' ; import { EffectsModule } from '@ngrx/effects' ; import { Store } from '@ngrx/store' ; import { Router } from '@angular/router' ; import { SearchOptionIds , SearchByTermAction } from '@alfresco/aca-shared/store' ; describe ( 'SearchEffects' , ( ) => { let store ; let router ; beforeEach ( ( ) => { TestBed . configureTestingModule ( { imports : [ AppTestingModule , EffectsModule . forRoot ( [ SearchEffects ] ) ] } ) ; store = TestBed . inject ( Store ) ; router = TestBed . inject ( Router ) ; spyOn ( router , 'navigateByUrl' ) . and . stub ( ) ; } ) ; describe ( 'searchByTerm$' , ( ) => { it ( 'should navigate to `search` when search options has library false' , fakeAsync ( ( ) => { store . dispatch ( new SearchByTermAction ( 'test' , [ ] ) ) ; tick ( ) ; expect ( router . navigateByUrl ) . toHaveBeenCalledWith ( '/search;q=test' ) ; } ) ) ; it ( 'should navigate to `search-libraries` when search options has library true' , fakeAsync ( ( ) => { store . dispatch ( new SearchByTermAction ( 'test' , [ { id : SearchOptionIds . Libraries , value : true , key : '' , shouldDisable : null } ] ) ) ; tick ( ) ; expect ( router . navigateByUrl ) . toHaveBeenCalledWith ( '/search-libraries;q=test' ) ; } ) ) ; it ( 'should encode search string for parentheses' , fakeAsync ( ( ) => { store . dispatch ( new SearchByTermAction ( '(test)' , [ ] ) ) ; tick ( ) ; expect ( router . navigateByUrl ) . toHaveBeenCalledWith ( '/search;q=%2528test%2529' ) ; } ) ) ; } ) ; } ) ;