diff options
author | Lorraine Welch <lb2391@att.com> | 2020-04-01 15:32:38 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-04-01 15:32:38 +0000 |
commit | fa8fd81b7076a7a2c52bcabf60a5ef71551d9cb0 (patch) | |
tree | 07cd9c85a3a754a0b0e49d6ce7709b5ca87bf0a5 | |
parent | 6ee087b36fd8bbee66e6949d4b0070c1c11fb01a (diff) | |
parent | 7a8ac29ede90353b9667ba99f99d33899b25659d (diff) |
Merge "test cases for ngOnInit method in sidebar comp"
-rw-r--r-- | ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/layout/components/sidebar/sidebar.component.spec.ts | 60 |
1 files changed, 27 insertions, 33 deletions
diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/layout/components/sidebar/sidebar.component.spec.ts b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/layout/components/sidebar/sidebar.component.spec.ts index cc710b5c..7f5a43fe 100644 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/layout/components/sidebar/sidebar.component.spec.ts +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/layout/components/sidebar/sidebar.component.spec.ts @@ -4,7 +4,7 @@ * =================================================================== * Copyright © 2019 AT&T Intellectual Property. All rights reserved. * - * Modification Copyright © 2019 IBM. + * Modification Copyright © 2020 IBM. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed @@ -40,46 +40,37 @@ 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 { SidebarComponent } from './sidebar.component'; import { LayoutModule } from '../../layout.module'; -import { Session } from 'protractor'; import { CookieService } from 'ngx-cookie-service'; import { SidebarService } from 'src/app/shared/services'; -import { ReplaySubject } from 'rxjs'; import 'rxjs/add/observable/of'; -import { Observable } from 'rxjs/Observable'; -import { BaseRequestOptions, Http, XHRBackend } from '@angular/http'; -import { MockBackend } from '@angular/http/testing'; -import { environment } from 'src/environments/environment'; -import { inject } from '@angular/core'; -import { Response } from '@angular/http'; import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { Observable } from 'rxjs'; describe('SidebarComponent', () => { let component: SidebarComponent; let fixture: ComponentFixture<SidebarComponent>; let sidebarService: SidebarService; - let spy:any; - - let mockSidebarService = { - navigate: jasmine.createSpy('navigate') - }; + + var stubData1={ + "data":'{"data":"cachedRegions"}', + "data2":'{"data2":"cachedRegions2"}' + }; + beforeEach(async(() => { + let sidebarService: SidebarService; TestBed.configureTestingModule({ imports: [ LayoutModule, RouterTestingModule, TranslateModule.forRoot(), + HttpClientModule, HttpClientTestingModule ], - providers:[CookieService, SidebarService,MockBackend, BaseRequestOptions, { - provide: Http, - useFactory: (backend: XHRBackend, defaultOptions: BaseRequestOptions) => { - return new Http(backend, defaultOptions); - }, - deps: [MockBackend, BaseRequestOptions], - }], + providers:[CookieService, SidebarService], }) .compileComponents(); })); @@ -89,22 +80,25 @@ describe('SidebarComponent', () => { component = fixture.componentInstance; fixture.detectChanges(); sidebarService = TestBed.get(SidebarService); + }); it('should create', () => { 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',(done)=>{ - var result=sidebarService.getLeftMenu() - spy=spyOn(sidebarService, 'getLeftMenu').and.returnValue(result); - fixture.detectChanges(); - sidebarService.getLeftMenu(); - expect(spy).toHaveBeenCalled(); - component.ngOnInit(); - done() - //expect(component.result).toEqual(result) + it('should validate on ngOnInit',()=>{ + let spy=spyOn(sidebarService,'getLeftMenu').and.returnValue(Observable.of(stubData1)); + component.ngOnInit(); + expect(spy).toHaveBeenCalled(); }) }) @@ -134,15 +128,15 @@ describe('SidebarComponent', () => { 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 - }); + }) }); |