1c08a97af8c1e56f7478ec073bc745f60a527001
[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
42 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
43 import {FormsModule} from '@angular/forms';
44 import { NewMenuComponent } from './new-menu.component';
45 import { HttpClientTestingModule } from '@angular/common/http/testing';
46 import { NgbActiveModal, NgbModalModule } from '@ng-bootstrap/ng-bootstrap';
47 import { RouterTestingModule } from '@angular/router/testing';
48 import { CookieService } from 'ngx-cookie-service';
49 import { MockBackend } from '@angular/http/testing';
50 import { BaseRequestOptions, Http } from '@angular/http';
51 import { AdminService } from '../../admin.service';
52 import 'rxjs/add/operator/toPromise';
53 import { ConfirmationModalComponent } from 'src/app/modals/confirmation-modal/confirmation-modal.component';
54 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
55 import { MaterialModule } from 'portalsdk-tag-lib/material-module';
56 import 'rxjs/add/observable/of';
57 import { Observable } from 'rxjs/Observable';
58 import 'rxjs/add/operator/catch';
59 import 'rxjs/add/observable/throw';
60 import { BrowserDynamicTestingModule } from '@angular/platform-browser-dynamic/testing';
61
62
63 describe('NewMenuComponent', () => {
64   let component: NewMenuComponent;
65   let fixture: ComponentFixture<NewMenuComponent>;
66   let adminService:AdminService;
67  // let entryComponents:any;
68
69   beforeEach(async(() => {
70     TestBed.configureTestingModule({
71       declarations: [ NewMenuComponent,ConfirmationModalComponent ],
72       imports:[
73         FormsModule, 
74         HttpClientTestingModule,
75         RouterTestingModule,
76         NgbModalModule,
77         BrowserAnimationsModule
78       ],
79       providers:[
80         AdminService,
81         NgbActiveModal,
82         CookieService
83       ],   
84     })
85     TestBed.overrideModule(BrowserDynamicTestingModule,{
86       set:{
87         entryComponents:[ConfirmationModalComponent ]
88       }
89     })
90     .compileComponents();
91     
92   }));
93
94   beforeEach(() => {
95     fixture = TestBed.createComponent(NewMenuComponent);
96     component = fixture.componentInstance;
97     fixture.detectChanges();
98     adminService=TestBed.get(AdminService);
99   });
100
101   it('should create', () => {
102     expect(component).toBeTruthy();
103   });
104
105   it('testing ngOnInit method for if condition',()=>{
106     component.selectedMenu=1;
107     component.ngOnInit();
108     expect(component.menu).toEqual(component.selectedMenu);
109   })
110
111   it('testing ngOnInit method for else condition',()=>{
112     component.selectedMenu=0;
113     component.ngOnInit();
114     expect(component.menu.menuSetCode).toEqual('APP');
115   })
116
117   it('testing sortItems method',()=>{
118     let prop: any;
119       component.sortItems(prop);
120
121   })
122
123   it('testing getParentLabel method',()=>{
124     component.getParentLabel(1,"data");
125   })
126
127  
128   it('should test getParentData method1 ',()=>{
129     const children="children";
130     let spy=spyOn(adminService,'getParentData').and.returnValue(Observable.of('you object'));
131     component.getParentData();
132     expect(spy).toHaveBeenCalled();
133   })
134
135   it('should test getParentData method2 error part ',()=>{
136     const children="children";
137     let spy=spyOn(adminService,'getParentData').and.returnValue(Observable.throw({status:404}));
138     component.getParentData();
139     expect(spy).toHaveBeenCalled();
140   })
141
142   describe('should test getLeftMenuItems',()=>{
143   it('testing getLeftMenuItems',()=>{
144     component.getLeftMenuItems();
145   })
146   })
147
148   it('testing getFunctionCDselectData method1',()=>{
149      let spy=spyOn(adminService,'getFunctionCdList').and.returnValue(Observable.of('your object'));
150      component.getFunctionCDselectData();
151      expect(spy).toHaveBeenCalled();
152    })
153
154   describe('should test getFunctionCDselectData method2',()=>{
155     it('testing getFunctionCDselectData',()=>{
156      let spy= spyOn(adminService,'getFunctionCdList').and.returnValue(Observable.throw({status:404}))
157       component.getFunctionCDselectData();
158       expect(spy).toHaveBeenCalled();
159     })
160   })
161
162   it('should test updateFnMenu method',()=>{
163      component.menu.label!=null;
164     component.updateFnMenu();
165   })
166
167 });