9bbcfc4eec6bb5397cc07f63203aab7511f556d5
[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
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';
52
53 describe('SidebarComponent', () => {
54   let component: SidebarComponent;
55   let fixture: ComponentFixture<SidebarComponent>;
56   let sidebarService: SidebarService;
57
58   var stubData1={
59     "data":'"d"',
60     "data2":'"data2"'
61      };
62      var stubData2={
63       "data":'"d"',
64       "data2":'" "'
65        };
66
67   beforeEach(async(() => {
68     TestBed.configureTestingModule({
69       imports: [
70         LayoutModule,
71         RouterTestingModule,
72         TranslateModule.forRoot(),
73         HttpClientModule,
74         HttpClientTestingModule
75       ],
76       providers:[CookieService, SidebarService],
77     })
78     .compileComponents();
79   }));
80
81   beforeEach(() => {
82     fixture = TestBed.createComponent(SidebarComponent);
83     component = fixture.componentInstance;
84     fixture.detectChanges();
85     sidebarService = TestBed.get(SidebarService);
86     
87   });
88
89   it('should create', () => {
90     expect(component).toBeTruthy();
91   });
92
93   describe('should test ngOnInit',()=>{
94     it('should validate on ngOnInit',()=>{
95      let spy=spyOn(sidebarService,'getLeftMenu').and.returnValue(Observable.of(stubData1));
96      component.ngOnInit();
97      expect(spy).toHaveBeenCalled();  
98     })
99   })
100
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();  
106     //})
107   //})
108
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');
113   });
114
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');
119   });
120
121   it('should test toggleCollapsed function', () => {
122     component.collapsed= true;
123     component.toggleCollapsed();
124     expect(component.collapsed).toBe(false);
125   });
126
127   it('should test eventCalled function', () => {
128     component.isActive= true;
129     component.eventCalled();
130     expect(component.isActive).toBe(false);
131   });
132
133   it('should test isToggled method',()=>{
134     expect(component.isToggled()).toBe(false);  
135   })
136
137   it('should test toggleSidebar method',()=>{
138     component.pushRightClass="kumar";
139     expect(component.toggleSidebar()).toBeUndefined;
140   })
141
142   it('should test on onLoggedout method',()=>{
143      expect(localStorage.getItem('isLoggedin')).toBeFalsy
144     })
145
146 });