summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIndrijeet kumar <indriku1@in.ibm.com>2020-03-29 01:34:48 +0530
committerIndrijeet Kumar <indriku1@in.ibm.com>2020-04-01 15:02:34 +0000
commit7a8ac29ede90353b9667ba99f99d33899b25659d (patch)
tree03029bf32fb31028860c195f38e7c91c7fa99290
parent7d3ad2425c0a774179ddb522e741d977c3bcf992 (diff)
test cases for ngOnInit method in sidebar comp
test cases for ngOnInit method in sidebar component Issue-ID: PORTAL-813 Change-Id: I4b0d6997a12fc81cdfa84c84a237ef19b53bfc1d 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.ts60
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
- });
+ })
});