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 describe('should test ngOnInit',()=>{
94 it('should validate on ngOnInit',()=>{
95 let spy=spyOn(sidebarService,'getLeftMenu').and.returnValue(Observable.of(stubData1));
97 expect(spy).toHaveBeenCalled();
101 //describe('should test ngOnInit if part',()=>{
102 //it('should validate on ngOnInit',()=>{
103 //let spy=spyOn(sidebarService,'getLeftMenu').and.returnValue(Observable.of(stubData2));
104 // component.ngOnInit();
105 //expect(spy).toHaveBeenCalled();
109 it('should test addExpandClass if element and showMenu variable value are same', () => {
110 component.showMenu= '1';
111 component.addExpandClass('1');
112 expect(component.showMenu).toBe('0');
115 it('should test addExpandClass if element and showMenu variable value are not same', () => {
116 component.showMenu= '0';
117 component.addExpandClass('1');
118 expect(component.showMenu).toBe('1');
121 it('should test toggleCollapsed function', () => {
122 component.collapsed= true;
123 component.toggleCollapsed();
124 expect(component.collapsed).toBe(false);
127 it('should test eventCalled function', () => {
128 component.isActive= true;
129 component.eventCalled();
130 expect(component.isActive).toBe(false);
133 it('should test isToggled method',()=>{
134 expect(component.isToggled()).toBe(false);
137 it('should test toggleSidebar method',()=>{
138 component.pushRightClass="kumar";
139 expect(component.toggleSidebar()).toBeUndefined;
142 it('should test on onLoggedout method',()=>{
143 expect(localStorage.getItem('isLoggedin')).toBeFalsy