2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2019 AT&T Intellectual Property. All rights reserved.
7 * Modification Copyright © 2019 IBM.
8 * ===================================================================
10 * Unless otherwise specified, all software contained herein is licensed
11 * under the Apache License, Version 2.0 (the "License");
12 * you may not use this software except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * Unless otherwise specified, all documentation contained herein is licensed
24 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
25 * you may not use this documentation except in compliance with the License.
26 * You may obtain a copy of the License at
28 * https://creativecommons.org/licenses/by/4.0/
30 * Unless required by applicable law or agreed to in writing, documentation
31 * distributed under the License is distributed on an "AS IS" BASIS,
32 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33 * See the License for the specific language governing permissions and
34 * limitations under the License.
36 * ============LICENSE_END============================================
40 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
41 import { RouterTestingModule } from '@angular/router/testing';
42 import { TranslateModule } from '@ngx-translate/core';
43 import { SidebarComponent } from './sidebar.component';
44 import { LayoutModule } from '../../layout.module';
45 import { Session } from 'protractor';
46 import { CookieService } from 'ngx-cookie-service';
47 import { SidebarService } from 'src/app/shared/services';
48 import { ReplaySubject } from 'rxjs';
49 import 'rxjs/add/observable/of';
50 import { Observable } from 'rxjs/Observable';
51 import { BaseRequestOptions, Http, XHRBackend } from '@angular/http';
52 import { MockBackend } from '@angular/http/testing';
53 import { environment } from 'src/environments/environment';
54 import { inject } from '@angular/core';
55 import { Response } from '@angular/http';
56 import { HttpClientTestingModule } from '@angular/common/http/testing';
58 describe('SidebarComponent', () => {
59 let component: SidebarComponent;
60 let fixture: ComponentFixture<SidebarComponent>;
61 let sidebarService: SidebarService;
64 let mockSidebarService = {
65 navigate: jasmine.createSpy('navigate')
68 beforeEach(async(() => {
69 TestBed.configureTestingModule({
73 TranslateModule.forRoot(),
74 HttpClientTestingModule
76 providers:[CookieService, SidebarService,MockBackend, BaseRequestOptions, {
78 useFactory: (backend: XHRBackend, defaultOptions: BaseRequestOptions) => {
79 return new Http(backend, defaultOptions);
81 deps: [MockBackend, BaseRequestOptions],
88 fixture = TestBed.createComponent(SidebarComponent);
89 component = fixture.componentInstance;
90 fixture.detectChanges();
91 sidebarService = TestBed.get(SidebarService);
94 it('should create', () => {
95 expect(component).toBeTruthy();
98 describe('should test ngOnInit',()=>{
99 it('should validate on ngOnInit',(done)=>{
100 var result=sidebarService.getLeftMenu()
101 spy=spyOn(sidebarService, 'getLeftMenu').and.returnValue(result);
102 fixture.detectChanges();
103 sidebarService.getLeftMenu();
104 expect(spy).toHaveBeenCalled();
105 component.ngOnInit();
107 //expect(component.result).toEqual(result)
111 it('should test addExpandClass if element and showMenu variable value are same', () => {
112 component.showMenu= '1';
113 component.addExpandClass('1');
114 expect(component.showMenu).toBe('0');
117 it('should test addExpandClass if element and showMenu variable value are not same', () => {
118 component.showMenu= '0';
119 component.addExpandClass('1');
120 expect(component.showMenu).toBe('1');
123 it('should test toggleCollapsed function', () => {
124 component.collapsed= true;
125 component.toggleCollapsed();
126 expect(component.collapsed).toBe(false);
129 it('should test eventCalled function', () => {
130 component.isActive= true;
131 component.eventCalled();
132 expect(component.isActive).toBe(false);
135 it('should test isToggled method',()=>{
136 expect(component.isToggled()).toBe(false);
139 it('should test toggleSidebar method',()=>{
140 component.pushRightClass="kumar";
141 expect(component.toggleSidebar()).toBeUndefined;
144 it('should test on onLoggedout method',()=>{
145 expect(localStorage.getItem('isLoggedin')).toBeFalsy