diff options
author | Sunder Tattavarada <statta@research.att.com> | 2020-03-03 15:20:26 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-03-03 15:20:26 +0000 |
commit | 1096c1bcfdc23116eac97c0a1db00e5d0106530e (patch) | |
tree | a72293d0c45b9e84164bf7cb162d4e16dbef681e /ecomp-sdk/epsdk-app-overlay/src/main/webapp | |
parent | 4ddb402301e25cb4dc80fc6ac64b08b0a224e187 (diff) | |
parent | 3f97c83d8ac6c2eb570c7711c165830c0c1c4dbc (diff) |
Merge "some test cases for sidebar component"
Diffstat (limited to 'ecomp-sdk/epsdk-app-overlay/src/main/webapp')
-rw-r--r-- | ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/layout/components/sidebar/sidebar.component.spec.ts | 57 |
1 files changed, 50 insertions, 7 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 ad425219..38902784 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 @@ -41,27 +41,47 @@ 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 { CookieModule, CookieService } from 'ngx-cookie'; 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'; describe('SidebarComponent', () => { let component: SidebarComponent; let fixture: ComponentFixture<SidebarComponent>; + let sidebarService: SidebarService; + let spy:any; + + let mockSidebarService = { + navigate: jasmine.createSpy('navigate') + }; beforeEach(async(() => { TestBed.configureTestingModule({ - providers:[CookieService], imports: [ LayoutModule, RouterTestingModule, TranslateModule.forRoot(), HttpClientModule, - // CookieModule.forRoot() + HttpClientTestingModule ], - // providers:[CookieService] + providers:[CookieService, SidebarService,MockBackend, BaseRequestOptions, { + provide: Http, + useFactory: (backend: XHRBackend, defaultOptions: BaseRequestOptions) => { + return new Http(backend, defaultOptions); + }, + deps: [MockBackend, BaseRequestOptions], + }], }) .compileComponents(); })); @@ -70,12 +90,26 @@ describe('SidebarComponent', () => { fixture = TestBed.createComponent(SidebarComponent); component = fixture.componentInstance; fixture.detectChanges(); + sidebarService = TestBed.get(SidebarService); }); it('should create', () => { expect(component).toBeTruthy(); }); + 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 test addExpandClass if element and showMenu variable value are same', () => { component.showMenu= '1'; component.addExpandClass('1'); @@ -100,8 +134,17 @@ describe('SidebarComponent', () => { expect(component.isActive).toBe(false); }); - it('should test ngOnInit function', () => { - component.ngOnInit(); - }); + 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 + }) }); |