import { async , ComponentFixture , TestBed } from '@angular/core/testing' ; import { RouterTestingModule } from '@angular/router/testing' ; import { Store , StoreModule } from '@ngrx/store' ; import { BriebugListComponent } from './entity-list.component' ; import { appReducer } from '@state/app.reducer' ; import { AppState } from '@state/app.interfaces' ; import { SearchAllBriebugEntities , SearchAllBriebugEntitiesSuccess , SearchAllBriebugEntitiesFail } from '@state/briebug/briebug.actions' ; import { generateBriebugArray } from '@state/briebug/briebug.model' ; describe ( 'BriebugListComponent' , ( ) => { let component ; let fixture ; let store ; beforeEach ( async ( ( ) => { TestBed . configureTestingModule ( { declarations : [ BriebugListComponent ] , imports : [ RouterTestingModule , StoreModule . forRoot ( appReducer ) ] } ) . compileComponents ( ) ; } ) ) ; beforeEach ( ( ) => { fixture = TestBed . createComponent ( BriebugListComponent ) ; component = fixture . componentInstance ; store = TestBed . get ( Store ) ; fixture . detectChanges ( ) ; spyOn ( store , 'dispatch' ) . and . callThrough ( ) ; } ) ; it ( 'should create' , ( ) => { expect ( component ) . toBeTruthy ( ) ; } ) ; it ( 'should get briebug entities when available' , ( done ) => { const entities = generateBriebugArray ( ) ; store . dispatch ( new SearchAllBriebugEntitiesSuccess ( { result : entities } ) ) ; component . briebugEntities$ . subscribe ( ( result ) => { expect ( result ) . toEqual ( entities ) ; done ( ) ; } ) ; } ) ; it ( 'should get the loading status when available' , ( done ) => { store . dispatch ( new SearchAllBriebugEntities ( ) ) ; component . isLoading$ . subscribe ( ( isLoading ) => { expect ( isLoading ) . toBe ( true ) ; done ( ) ; } ) ; } ) ; it ( 'should get the error message when available' , ( done ) => { const testError = 'Some Error Message' ; store . dispatch ( new SearchAllBriebugEntitiesFail ( { error : testError } ) ) ; component . errorMessage$ . subscribe ( ( errorResult ) => { if ( errorResult ) { expect ( errorResult ) . toContain ( testError ) ; done ( ) ; } } ) ; } ) ; describe ( 'ngOnInit' , ( ) => { it ( 'should request all Briebug entities' , ( ) => { component . ngOnInit ( ) ; expect ( store . dispatch ) . toHaveBeenCalledWith ( new SearchAllBriebugEntities ( ) ) ; } ) ; } ) ; } ) ;