import { ComponentFixture , TestBed , async , inject , fakeAsync , tick } from '@angular/core/testing' ; import { Observable , of } from 'rxjs' ; import { HttpHeaders , HttpResponse } from '@angular/common/http' ; import { FrontendTestModule } from '../../../test.module' ; import { UserMgmtComponent } from 'app/admin/user-management/user-management.component' ; import { UserService , User } from 'app/core' ; describe ( 'Component Tests' , ( ) => { describe ( 'User Management Component' , ( ) => { let comp ; let fixture ; let service ; beforeEach ( async ( ( ) => { TestBed . configureTestingModule ( { imports : [ FrontendTestModule ] , declarations : [ UserMgmtComponent ] } ) . overrideTemplate ( UserMgmtComponent , '' ) . compileComponents ( ) ; } ) ) ; beforeEach ( ( ) => { fixture = TestBed . createComponent ( UserMgmtComponent ) ; comp = fixture . componentInstance ; service = fixture . debugElement . injector . get ( UserService ) ; } ) ; describe ( 'OnInit' , ( ) => { it ( 'Should call load all on init' , inject ( [ ] , fakeAsync ( ( ) => { const headers = new HttpHeaders ( ) . append ( 'link' , 'link;link' ) ; spyOn ( service , 'query' ) . and . returnValue ( of ( new HttpResponse ( { body : [ new User ( 123 ) ] , headers } ) ) ) ; comp . ngOnInit ( ) ; tick ( ) ; expect ( service . query ) . toHaveBeenCalled ( ) ; expect ( comp . users [ 0 ] ) . toEqual ( jasmine . objectContaining ( { id : 123 } ) ) ; } ) ) ) ; } ) ; describe ( 'setActive' , ( ) => { it ( 'Should update user and call load all' , inject ( [ ] , fakeAsync ( ( ) => { const headers = new HttpHeaders ( ) . append ( 'link' , 'link;link' ) ; const user = new User ( 123 ) ; spyOn ( service , 'query' ) . and . returnValue ( of ( new HttpResponse ( { body : [ user ] , headers } ) ) ) ; spyOn ( service , 'update' ) . and . returnValue ( of ( new HttpResponse ( { status : 200 } ) ) ) ; comp . setActive ( user , true ) ; tick ( ) ; expect ( service . update ) . toHaveBeenCalledWith ( user ) ; expect ( service . query ) . toHaveBeenCalled ( ) ; expect ( comp . users [ 0 ] ) . toEqual ( jasmine . objectContaining ( { id : 123 } ) ) ; } ) ) ) ; } ) ; } ) ; } ) ;