650f09a62d82fdc4c5162082626eb9c7d00a939f
[portal/sdk.git] /
1 /*
2  * ============LICENSE_START==========================================
3  * ONAP Portal SDK
4  * ===================================================================
5  * Copyright © 2019 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  * 
8  *  * Modification Copyright © 2020 IBM.
9  * ===================================================================
10
11  * Unless otherwise specified, all software contained herein is licensed
12  * under the Apache License, Version 2.0 (the "License");
13  * you may not use this software except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  *             http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  *
24  * Unless otherwise specified, all documentation contained herein is licensed
25  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
26  * you may not use this documentation except in compliance with the License.
27  * You may obtain a copy of the License at
28  *
29  *             https://creativecommons.org/licenses/by/4.0/
30  *
31  * Unless required by applicable law or agreed to in writing, documentation
32  * distributed under the License is distributed on an "AS IS" BASIS,
33  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34  * See the License for the specific language governing permissions and
35  * limitations under the License.
36  *
37  * ============LICENSE_END============================================
38  *
39  */
40
41 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
42 import {FormsModule} from '@angular/forms';
43 import { NewMenuComponent } from './new-menu.component';
44 import { HttpClientTestingModule } from '@angular/common/http/testing';
45 import { NgbActiveModal, NgbModalModule } from '@ng-bootstrap/ng-bootstrap';
46 import { RouterTestingModule } from '@angular/router/testing';
47 import { CookieService } from 'ngx-cookie-service';
48 import { AdminService } from '../../admin.service';
49 import 'rxjs/add/operator/toPromise';
50 import { ConfirmationModalComponent } from 'src/app/modals/confirmation-modal/confirmation-modal.component';
51 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
52 import 'rxjs/add/observable/of';
53 import { Observable } from 'rxjs/Observable';
54 import 'rxjs/add/operator/catch';
55 import 'rxjs/add/observable/throw';
56 import { BrowserDynamicTestingModule } from '@angular/platform-browser-dynamic/testing';
57
58
59 describe('NewMenuComponent', () => {
60   let component: NewMenuComponent;
61   let fixture: ComponentFixture<NewMenuComponent>;
62   let adminService:AdminService;
63
64   beforeEach(async(() => {
65     TestBed.configureTestingModule({
66       declarations: [ NewMenuComponent,ConfirmationModalComponent ],
67       imports:[
68         FormsModule, 
69         HttpClientTestingModule,
70         RouterTestingModule,
71         NgbModalModule,
72         BrowserAnimationsModule
73       ],
74       providers:[
75         AdminService,
76         NgbActiveModal,
77         CookieService
78       ],   
79     })
80     TestBed.overrideModule(BrowserDynamicTestingModule,{
81       set:{
82         entryComponents:[ConfirmationModalComponent ]
83       }
84     })
85     .compileComponents();
86     
87   }));
88
89   beforeEach(() => {
90     fixture = TestBed.createComponent(NewMenuComponent);
91     component = fixture.componentInstance;
92     fixture.detectChanges();
93     adminService=TestBed.get(AdminService);
94   });
95
96   it('should create', () => {
97     expect(component).toBeTruthy();
98   });
99
100   it('testing ngOnInit method for if condition',()=>{
101     component.selectedMenu=1;
102     component.ngOnInit();
103     expect(component.menu).toEqual(component.selectedMenu);
104   })
105
106   it('testing ngOnInit method for else condition',()=>{
107     component.selectedMenu=0;
108     component.ngOnInit();
109     expect(component.menu.menuSetCode).toEqual('APP');
110   })
111
112   it('testing sortItems method',()=>{
113     let prop: any;
114       component.sortItems(prop);
115
116   })
117
118   it('testing getParentLabel method',()=>{
119     component.getParentLabel(1,"data");
120   })
121
122  
123   it('should test getParentData method1 ',()=>{
124     const children="children";
125     let spy=spyOn(adminService,'getParentData').and.returnValue(Observable.of('you object'));
126     component.getParentData();
127     expect(spy).toHaveBeenCalled();
128   })
129
130   it('should test getParentData method2 error part ',()=>{
131     const children="children";
132     let spy=spyOn(adminService,'getParentData').and.returnValue(Observable.throw({status:404}));
133     component.getParentData();
134     expect(spy).toHaveBeenCalled();
135   })
136
137   describe('should test getLeftMenuItems',()=>{
138   it('testing getLeftMenuItems',()=>{
139     component.getLeftMenuItems();
140   })
141   })
142
143   it('testing getFunctionCDselectData method1',()=>{
144      let spy=spyOn(adminService,'getFunctionCdList').and.returnValue(Observable.of('your object'));
145      component.getFunctionCDselectData();
146      expect(spy).toHaveBeenCalled();
147      expect(component.result).toEqual('your object');
148      expect(component.functionCDselectData).toEqual('your object');
149    })
150
151   describe('should test getFunctionCDselectData method2',()=>{
152     it('testing getFunctionCDselectData',()=>{
153      let spy= spyOn(adminService,'getFunctionCdList').and.returnValue(Observable.throw({status:404}))
154       component.getFunctionCDselectData();
155       expect(spy).toHaveBeenCalled();
156       expect(component.showSpinner).toEqual(false);
157     })
158   })
159
160   it('should test updateFnMenu method',()=>{
161      component.menu.label!=null;
162     component.updateFnMenu();
163   })
164
165 });