2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2019 AT&T Intellectual Property. All rights reserved.
7 * Modification Copyright © 2020 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============================================
41 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
42 import { RouterTestingModule } from '@angular/router/testing';
43 import { TranslateModule } from '@ngx-translate/core';
44 import { HttpClientModule } from '@angular/common/http';
45 import { SidebarComponent } from './sidebar.component';
46 import { LayoutModule } from '../../layout.module';
47 import { CookieService } from 'ngx-cookie-service';
48 import { SidebarService } from 'src/app/shared/services';
49 import 'rxjs/add/observable/of';
50 import { HttpClientTestingModule } from '@angular/common/http/testing';
51 import { Observable } from 'rxjs';
53 describe('SidebarComponent', () => {
54 let component: SidebarComponent;
55 let fixture: ComponentFixture<SidebarComponent>;
56 let sidebarService: SidebarService;
67 beforeEach(async(() => {
68 TestBed.configureTestingModule({
72 TranslateModule.forRoot(),
74 HttpClientTestingModule
76 providers:[CookieService, SidebarService],
82 fixture = TestBed.createComponent(SidebarComponent);
83 component = fixture.componentInstance;
84 fixture.detectChanges();
85 sidebarService = TestBed.get(SidebarService);
89 it('should create', () => {
90 expect(component).toBeTruthy();
93 it('testing if condition in ngOnInit method',()=>{
94 component.cookieService.set('show_app_header','false');
96 expect(component.showHeader).toBe(false)
100 describe('should test ngOnInit',()=>{
101 it('should validate on ngOnInit',()=>{
102 let spy=spyOn(sidebarService,'getLeftMenu').and.returnValue(Observable.of(stubData1));
103 component.ngOnInit();
104 expect(spy).toHaveBeenCalled();
108 //describe('should test ngOnInit if part',()=>{
109 //it('should validate on ngOnInit',()=>{
110 //let spy=spyOn(sidebarService,'getLeftMenu').and.returnValue(Observable.of(stubData2));
111 // component.ngOnInit();
112 //expect(spy).toHaveBeenCalled();
116 it('should test addExpandClass if element and showMenu variable value are same', () => {
117 component.showMenu= '1';
118 component.addExpandClass('1');
119 expect(component.showMenu).toBe('0');
122 it('should test addExpandClass if element and showMenu variable value are not same', () => {
123 component.showMenu= '0';
124 component.addExpandClass('1');
125 expect(component.showMenu).toBe('1');
128 it('should test toggleCollapsed function', () => {
129 component.collapsed= true;
130 component.toggleCollapsed();
131 expect(component.collapsed).toBe(false);
134 it('should test eventCalled function', () => {
135 component.isActive= true;
136 component.eventCalled();
137 expect(component.isActive).toBe(false);
140 it('should test isToggled method',()=>{
141 expect(component.isToggled()).toBe(false);
144 it('should test toggleSidebar method',()=>{
145 component.pushRightClass="kumar";
146 expect(component.toggleSidebar()).toBeUndefined;
149 it('should test on onLoggedout method',()=>{
150 expect(localStorage.getItem('isLoggedin')).toBeFalsy