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