diff options
author | Indrijeet kumar <indriku1@in.ibm.com> | 2020-02-28 16:18:51 +0530 |
---|---|---|
committer | Indrijeet kumar <indriku1@in.ibm.com> | 2020-02-28 16:19:06 +0530 |
commit | 7d2f5168adf3f7d9f35d7a0e8671e99ccb84a467 (patch) | |
tree | bcac8a717c8f0171845e923cef0f45d3c9918b86 /ecomp-sdk/epsdk-app-overlay | |
parent | 1fe7926c797ca4eb839fd323b31b7b9438501878 (diff) |
few test cases in header component
few test cases in header component
Issue-ID: PORTAL-813
Change-Id: I34115217e0bce99cce2e3bcf09e87bb3edcbfae0
Signed-off-by: Indrijeet Kumar <indriku1@in.ibm.com>
Diffstat (limited to 'ecomp-sdk/epsdk-app-overlay')
-rw-r--r-- | ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/layout/components/header/header.component.spec.ts | 61 |
1 files changed, 42 insertions, 19 deletions
diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/layout/components/header/header.component.spec.ts b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/layout/components/header/header.component.spec.ts index 4a12cd9f..ecbbcc60 100644 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/layout/components/header/header.component.spec.ts +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/layout/components/header/header.component.spec.ts @@ -4,7 +4,7 @@ * =================================================================== * Copyright © 2019 AT&T Intellectual Property. All rights reserved. * =================================================================== - * Modification Copyright © 2020 IBM. + * * Modification Copyright © 2020 IBM. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed @@ -37,7 +37,7 @@ * * */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { async, ComponentFixture, TestBed, inject } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { TranslateModule } from '@ngx-translate/core'; import { HttpClientModule } from '@angular/common/http'; @@ -47,15 +47,23 @@ import { LayoutModule } from '../../layout.module'; import { CookieService } from 'ngx-cookie-service'; import { HeaderService } from 'src/app/shared/services/header/header.service'; import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { Router } from '@angular/router'; +import { MockBackend, MockConnection } from '@angular/http/testing'; +//import { observable, Observable } from 'rxjs'; +import 'rxjs/add/observable/of'; +import { Observable } from 'rxjs/Observable'; +import { BaseRequestOptions, Http } from '@angular/http'; describe('HeaderComponent', () => { let headerService:HeaderService; + let cookieService:CookieService; + let router:Router; let component: HeaderComponent; let fixture: ComponentFixture<HeaderComponent>; + let spy: any; beforeEach(async(() => { TestBed.configureTestingModule({ - providers:[CookieService], imports: [ LayoutModule, RouterTestingModule, @@ -63,6 +71,13 @@ describe('HeaderComponent', () => { HttpClientModule, HttpClientTestingModule ], + providers:[CookieService,HeaderService,MockBackend, BaseRequestOptions, { + provide: Http, + useFactory: (backend: MockBackend, defaultOptions: BaseRequestOptions) => { + return new Http(backend, defaultOptions); + }, + deps: [MockBackend, BaseRequestOptions], + }] }) .compileComponents(); })); @@ -72,27 +87,35 @@ describe('HeaderComponent', () => { component = fixture.componentInstance; fixture.detectChanges(); headerService = TestBed.get(HeaderService); + cookieService=TestBed.get(CookieService); + }); it('should create', () => { expect(component).toBeTruthy(); }); - it('should test ngOnInit method',()=>{ - fixture.detectChanges(); - component.ngOnInit(); - if(component.cookieService.get('show_app_header')=='false') - expect(component.showHeader).toBe(false); - expect(component.pushRightClass).toEqual('push-right'); - (done: DoneFn)=> { - headerService.getTopMenuItems().subscribe(res=>{ - expect(component.response).toEqual(res); - expect(component.userFirstName).toBe(component.response.firstName); - expect(component.userEmail).toBe(component.response.email); - expect(component.userId).toBe(component.response.userId); - expect(component.userName).toBe(component.response.userName); - done(); + describe('should test ngOnInit',()=>{ + it('should validate on ngOnInit',()=>{ + let spy=spyOn(headerService, 'getTopMenuItems').and.returnValue(Observable.of('you object')); + component.ngOnInit(); + expect(spy).toHaveBeenCalled(); }) - } - }); + }) + + + it('should test isToggled method',()=>{ + expect(component.isToggled()).toBe(false); + }) + + it('should test toggleSidebar method',()=>{ + component.pushRightClass="kumar"; + expect(component.toggleSidebar()).toBeUndefined; + }) + + it('should test on onLoggedout method',()=>{ + expect(localStorage.getItem('isLoggedin')).toBeFalsy + }) + + }); |