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============================================
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 { HttpClientModule } from '@angular/common/http';
44 import { SidebarComponent } from './sidebar.component';
45 import { LayoutModule } from '../../layout.module';
46 import { CookieService } from 'ngx-cookie-service';
47 import { SidebarService } from 'src/app/shared/services';
48 import 'rxjs/add/observable/of';
49 import { HttpClientTestingModule } from '@angular/common/http/testing';
50 import { Observable } from 'rxjs';
52 describe('SidebarComponent', () => {
53 let component: SidebarComponent;
54 let fixture: ComponentFixture<SidebarComponent>;
55 let sidebarService: SidebarService;
58 "data":'{"data":"cachedRegions"}',
59 "data2":'{"data2":"cachedRegions2"}'
63 beforeEach(async(() => {
64 let sidebarService: SidebarService;
65 TestBed.configureTestingModule({
69 TranslateModule.forRoot(),
71 HttpClientTestingModule
73 providers:[CookieService, SidebarService],
79 fixture = TestBed.createComponent(SidebarComponent);
80 component = fixture.componentInstance;
81 fixture.detectChanges();
82 sidebarService = TestBed.get(SidebarService);
86 it('should create', () => {
87 expect(component).toBeTruthy();
90 it('testing if condition in ngOnInit method',()=>{
91 component.cookieService.set('show_app_header','false');
93 expect(component.showHeader).toBe(false)
97 describe('should test ngOnInit',()=>{
98 it('should validate on ngOnInit',()=>{
99 let spy=spyOn(sidebarService,'getLeftMenu').and.returnValue(Observable.of(stubData1));
100 component.ngOnInit();
101 expect(spy).toHaveBeenCalled();
105 it('should test addExpandClass if element and showMenu variable value are same', () => {
106 component.showMenu= '1';
107 component.addExpandClass('1');
108 expect(component.showMenu).toBe('0');
111 it('should test addExpandClass if element and showMenu variable value are not same', () => {
112 component.showMenu= '0';
113 component.addExpandClass('1');
114 expect(component.showMenu).toBe('1');
117 it('should test toggleCollapsed function', () => {
118 component.collapsed= true;
119 component.toggleCollapsed();
120 expect(component.collapsed).toBe(false);
123 it('should test eventCalled function', () => {
124 component.isActive= true;
125 component.eventCalled();
126 expect(component.isActive).toBe(false);
129 it('should test isToggled method',()=>{
130 expect(component.isToggled()).toBe(false);
133 it('should test toggleSidebar method',()=>{
134 component.pushRightClass="kumar";
135 expect(component.toggleSidebar()).toBeUndefined;
138 it('should test on onLoggedout method',()=>{
139 expect(localStorage.getItem('isLoggedin')).toBeFalsy