e2b08a4f768c6311cc5c512cb0241be8e1b1fcab
[portal/sdk.git] /
1 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2
3 import { LogComponent } from './log.component';
4 import { HttpClientTestingModule } from '@angular/common/http/testing';
5 import { LogService } from './log.service';
6 import { MockBackend } from '@angular/http/testing';
7 import { BaseRequestOptions, Http } from '@angular/http';
8 import 'rxjs/add/observable/of';
9 import { Observable } from 'rxjs/Observable';
10
11 describe('LogComponent', () => {
12   let component: LogComponent;
13   let fixture: ComponentFixture<LogComponent>;
14   let logService:LogService;
15
16   beforeEach(async(() => {
17     TestBed.configureTestingModule({
18       declarations: [ LogComponent ],
19       imports: [HttpClientTestingModule],
20       // providers:[LogService,MockBackend,BaseRequestOptions,{
21       //   porvide:Http,useFactory:(backend:MockBackend,defaultOptions:BaseRequestOptions)=>{
22       //     return new Http(backend,defaultOptions);
23       //   },
24       //   deps:[MockBackend,BaseRequestOptions],
25       // }]
26     })
27     .compileComponents();
28   }));
29
30   beforeEach(() => {
31     fixture = TestBed.createComponent(LogComponent);
32     component = fixture.componentInstance;
33     fixture.detectChanges();
34     logService=TestBed.get(LogService);
35   });
36
37   it('should create', () => {
38     expect(component).toBeTruthy();
39   });
40
41   describe('should test subscribe',()=>{
42     it('should test ngOnInit method1',()=>{
43       component.reportType = "Dashboard";
44       component.ngOnInit();
45       expect(component.stepNo).toEqual("3");
46     })
47   })
48
49   it('should test ngOnInit method2',()=>{
50     component.reportType != "Dashboard";
51     component.ngOnInit();
52     expect(component.stepNo).toEqual("7");
53   })
54
55   it('should test subscribe method inside ngOnInit method',()=>{
56     let spy=spyOn(logService,'getLogData').and.returnValue(Observable.of('you object'));
57     component.ngOnInit();
58     expect(spy).toHaveBeenCalled();
59   })
60 });