summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/layout/components/sidebar/sidebar.component.spec.ts57
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
+ })
});