7f5a43fe73ccc3d86e766f6d19a52396fc646adc
[portal/sdk.git] /
1 /*
2  * ============LICENSE_START==========================================
3  * ONAP Portal SDK
4  * ===================================================================
5  * Copyright © 2019 AT&T Intellectual Property. All rights reserved.
6  * 
7  * Modification Copyright © 2020 IBM.
8  * ===================================================================
9  *
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
14  *
15  *             http://www.apache.org/licenses/LICENSE-2.0
16  *
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.
22  *
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
27  *
28  *             https://creativecommons.org/licenses/by/4.0/
29  *
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.
35  *
36  * ============LICENSE_END============================================
37  *
38  * 
39  */
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';
51
52 describe('SidebarComponent', () => {
53   let component: SidebarComponent;
54   let fixture: ComponentFixture<SidebarComponent>;
55   let sidebarService: SidebarService;
56
57   var stubData1={
58     "data":'{"data":"cachedRegions"}',
59     "data2":'{"data2":"cachedRegions2"}'
60      };
61
62
63   beforeEach(async(() => {
64     let sidebarService: SidebarService;
65     TestBed.configureTestingModule({
66       imports: [
67         LayoutModule,
68         RouterTestingModule,
69         TranslateModule.forRoot(),
70         HttpClientModule,
71         HttpClientTestingModule
72       ],
73       providers:[CookieService, SidebarService],
74     })
75     .compileComponents();
76   }));
77
78   beforeEach(() => {
79     fixture = TestBed.createComponent(SidebarComponent);
80     component = fixture.componentInstance;
81     fixture.detectChanges();
82     sidebarService = TestBed.get(SidebarService);
83     
84   });
85
86   it('should create', () => {
87     expect(component).toBeTruthy();
88   });
89
90   it('testing if condition in ngOnInit method',()=>{
91     component.cookieService.set('show_app_header','false');
92     component.ngOnInit();
93     expect(component.showHeader).toBe(false)
94   })
95  
96
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();  
102     })
103   })
104
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');
109   });
110
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');
115   });
116
117   it('should test toggleCollapsed function', () => {
118     component.collapsed= true;
119     component.toggleCollapsed();
120     expect(component.collapsed).toBe(false);
121   });
122
123   it('should test eventCalled function', () => {
124     component.isActive= true;
125     component.eventCalled();
126     expect(component.isActive).toBe(false);
127   });
128
129   it('should test isToggled method',()=>{
130     expect(component.isToggled()).toBe(false);  
131   })
132
133   it('should test toggleSidebar method',()=>{
134     component.pushRightClass="kumar";
135     expect(component.toggleSidebar()).toBeUndefined;
136   })
137
138   it('should test on onLoggedout method',()=>{
139      expect(localStorage.getItem('isLoggedin')).toBeFalsy
140     })
141
142 });