cc710b5c73c61b478721b8b9005702335c5bc7d7
[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 © 2019 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 { SidebarComponent } from './sidebar.component';
44 import { LayoutModule } from '../../layout.module';
45 import { Session } from 'protractor';
46 import { CookieService } from 'ngx-cookie-service';
47 import { SidebarService } from 'src/app/shared/services';
48 import { ReplaySubject } from 'rxjs';
49 import 'rxjs/add/observable/of';
50 import { Observable } from 'rxjs/Observable';
51 import { BaseRequestOptions, Http, XHRBackend } from '@angular/http';
52 import { MockBackend } from '@angular/http/testing';
53 import { environment } from 'src/environments/environment';
54 import { inject } from '@angular/core';
55 import { Response } from '@angular/http';
56 import { HttpClientTestingModule } from '@angular/common/http/testing';
57
58 describe('SidebarComponent', () => {
59   let component: SidebarComponent;
60   let fixture: ComponentFixture<SidebarComponent>;
61   let sidebarService: SidebarService;
62   let spy:any;
63   
64   let mockSidebarService = {
65     navigate: jasmine.createSpy('navigate')
66   };
67
68   beforeEach(async(() => {
69     TestBed.configureTestingModule({
70       imports: [
71         LayoutModule,
72         RouterTestingModule,
73         TranslateModule.forRoot(),
74         HttpClientTestingModule
75       ],
76       providers:[CookieService, SidebarService,MockBackend, BaseRequestOptions, {
77         provide: Http,
78                     useFactory: (backend: XHRBackend, defaultOptions: BaseRequestOptions) => {
79                         return new Http(backend, defaultOptions);
80                     },
81                     deps: [MockBackend, BaseRequestOptions],                    
82       }],
83     })
84     .compileComponents();
85   }));
86
87   beforeEach(() => {
88     fixture = TestBed.createComponent(SidebarComponent);
89     component = fixture.componentInstance;
90     fixture.detectChanges();
91     sidebarService = TestBed.get(SidebarService);
92   });
93
94   it('should create', () => {
95     expect(component).toBeTruthy();
96   });
97
98   describe('should test ngOnInit',()=>{
99     it('should validate on ngOnInit',(done)=>{
100      var result=sidebarService.getLeftMenu()
101      spy=spyOn(sidebarService, 'getLeftMenu').and.returnValue(result);  
102      fixture.detectChanges(); 
103      sidebarService.getLeftMenu(); 
104      expect(spy).toHaveBeenCalled();
105      component.ngOnInit(); 
106      done()
107     //expect(component.result).toEqual(result)
108     })
109   })
110
111   it('should test addExpandClass if element and showMenu variable value are same', () => {
112     component.showMenu= '1';
113     component.addExpandClass('1');
114     expect(component.showMenu).toBe('0');
115   });
116
117   it('should test addExpandClass if element and showMenu variable value are not same', () => {
118     component.showMenu= '0';
119     component.addExpandClass('1');
120     expect(component.showMenu).toBe('1');
121   });
122
123   it('should test toggleCollapsed function', () => {
124     component.collapsed= true;
125     component.toggleCollapsed();
126     expect(component.collapsed).toBe(false);
127   });
128
129   it('should test eventCalled function', () => {
130     component.isActive= true;
131     component.eventCalled();
132     expect(component.isActive).toBe(false);
133   });
134
135   it('should test isToggled method',()=>{
136     expect(component.isToggled()).toBe(false);  
137   });
138
139   it('should test toggleSidebar method',()=>{
140     component.pushRightClass="kumar";
141     expect(component.toggleSidebar()).toBeUndefined;
142   });
143
144   it('should test on onLoggedout method',()=>{
145      expect(localStorage.getItem('isLoggedin')).toBeFalsy
146     });
147
148 });