diff options
author | 2020-03-02 12:42:42 +0530 | |
---|---|---|
committer | 2020-03-02 12:42:49 +0530 | |
commit | 3f97c83d8ac6c2eb570c7711c165830c0c1c4dbc (patch) | |
tree | 030455418737f4e0e08da73026a992ed306ba32d | |
parent | 1fe7926c797ca4eb839fd323b31b7b9438501878 (diff) |
some test cases for sidebar component
some test cases written for sidebar component
Issue-ID: PORTAL-813
Change-Id: I85078a29751fdca90b9169017c424e5a2fe7f9c4
Signed-off-by: Indrijeet Kumar <indriku1@in.ibm.com>
-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 + }) }); |