88import { constructSearchEndpointDefault , SearchData , SearchDataImpl } from './search-data' ;
99import { FindListOptions } from '../find-list-options.model' ;
1010import { followLink } from '../../../shared/utils/follow-link-config.model' ;
11- import { of as observableOf } from 'rxjs' ;
11+ import { of , of as observableOf } from 'rxjs' ;
1212import { getMockRequestService } from '../../../shared/mocks/request.service.mock' ;
1313import { getMockRemoteDataBuildService } from '../../../shared/mocks/remote-data-build.service.mock' ;
14+ import { TestScheduler } from 'rxjs/testing' ;
15+ import { RemoteData } from '../remote-data' ;
16+ import { RequestEntryState } from '../request-entry-state.model' ;
1417
1518/**
1619 * Tests whether calls to `SearchData` methods are correctly patched through in a concrete data service that implements it
@@ -19,6 +22,12 @@ export function testSearchDataImplementation(serviceFactory: () => SearchData<an
1922 let service ;
2023
2124 describe ( 'SearchData implementation' , ( ) => {
25+ let testScheduler : TestScheduler ;
26+ const searchByResp = Object . assign (
27+ new RemoteData ( 0 , 0 , 0 , undefined , undefined , { } , 200 ) ,
28+ { state : RequestEntryState . Success , payload : 'TEST searchBy' }
29+ ) ;
30+ const searchByResp$ = of ( searchByResp ) ;
2231 const OPTIONS = Object . assign ( new FindListOptions ( ) , { elementsPerPage : 10 , currentPage : 3 } ) ;
2332 const FOLLOWLINKS = [
2433 followLink ( 'test' ) ,
@@ -27,16 +36,27 @@ export function testSearchDataImplementation(serviceFactory: () => SearchData<an
2736
2837 beforeAll ( ( ) => {
2938 service = serviceFactory ( ) ;
30- ( service as any ) . searchData = jasmine . createSpyObj ( 'searchData' , {
31- searchBy : 'TEST searchBy' ,
39+ ( service as any ) . searchData = jasmine . createSpyObj ( 'searchData' , [ 'searchBy' ] ) ;
40+ service . searchData . searchBy . and . returnValue ( searchByResp$ ) ;
41+ } ) ;
42+
43+ beforeEach ( ( ) => {
44+ testScheduler = new TestScheduler ( ( actual , expected ) => {
45+ return expect ( actual ) . toEqual ( expected ) ;
3246 } ) ;
3347 } ) ;
3448
3549 it ( 'should handle calls to searchBy' , ( ) => {
50+ const expectedMarbles = '(a|)' ;
51+ const expectedValues = {
52+ a : searchByResp
53+ } ;
3654 const out : any = service . searchBy ( 'searchMethod' , OPTIONS , false , true , ...FOLLOWLINKS ) ;
3755
3856 expect ( ( service as any ) . searchData . searchBy ) . toHaveBeenCalledWith ( 'searchMethod' , OPTIONS , false , true , ...FOLLOWLINKS ) ;
39- expect ( out ) . toBe ( 'TEST searchBy' ) ;
57+ testScheduler . run ( ( { expectObservable } ) => {
58+ expectObservable ( out ) . toBe ( expectedMarbles , expectedValues ) ;
59+ } ) ;
4060 } ) ;
4161 } ) ;
4262}
0 commit comments