From e3d10020fa178a7bca5446caaaa3d257c249cc1e Mon Sep 17 00:00:00 2001 From: Indrijeet kumar Date: Wed, 1 Apr 2020 20:50:05 +0530 Subject: test cases written in header component test cases written in header component Issue-ID: PORTAL-813 Change-Id: I41c7e7c5a84c1ab534753e380a042cb0dccc54e0 Signed-off-by: Indrijeet Kumar --- .../components/header/header.component.spec.ts | 31 +++++++++++++--------- 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'ecomp-sdk/epsdk-app-overlay/src/main') 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 ecfd694d..1253b2be 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 @@ -37,20 +37,21 @@ * * */ -import { async, ComponentFixture, TestBed, inject } from '@angular/core/testing'; +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { TranslateModule } from '@ngx-translate/core'; +import { HttpClientModule } from '@angular/common/http'; + import { HeaderComponent } from './header.component'; 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; @@ -66,15 +67,13 @@ describe('HeaderComponent', () => { LayoutModule, RouterTestingModule, TranslateModule.forRoot(), + HttpClientModule, HttpClientTestingModule ], - providers:[CookieService,HeaderService,MockBackend, BaseRequestOptions, { - provide: Http, - useFactory: (backend: MockBackend, defaultOptions: BaseRequestOptions) => { - return new Http(backend, defaultOptions); - }, - deps: [MockBackend, BaseRequestOptions], - }] + providers:[ + CookieService, + HeaderService + ] }) .compileComponents(); })); @@ -92,6 +91,12 @@ describe('HeaderComponent', () => { expect(component).toBeTruthy(); }); + it('testing if condition in ngOnInit method',()=>{ + component.cookieService.set('show_app_header','false'); + component.ngOnInit(); + expect(component.showHeader).toBe(false) + }) + describe('should test ngOnInit',()=>{ it('should validate on ngOnInit',()=>{ let spy=spyOn(headerService, 'getTopMenuItems').and.returnValue(Observable.of('you object')); @@ -113,4 +118,6 @@ describe('HeaderComponent', () => { it('should test on onLoggedout method',()=>{ expect(localStorage.getItem('isLoggedin')).toBeFalsy }) -}); \ No newline at end of file + + +}); -- cgit 1.2.3-korg