parameter component- spec fixes
[appc/cdt.git] / src / app / vnfs / build-artifacts / parameter-definitions / parameter.component.spec.ts
1 /*
2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
5
6 Copyright (C) 2018 IBM Intellectual Property. All rights reserved.
7 ===================================================================
8
9 Unless otherwise specified, all software contained herein is licensed
10 under the Apache License, Version 2.0 (the License);
11 you may not use this software except in compliance with the License.
12 You may obtain a copy of the License at
13
14     http://www.apache.org/licenses/LICENSE-2.0
15
16 Unless required by applicable law or agreed to in writing, software
17 distributed under the License is distributed on an "AS IS" BASIS,
18 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 See the License for the specific language governing permissions and
20 limitations under the License.
21
22 ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 ============LICENSE_END============================================
24 */
25
26 /* tslint:disable:no-unused-variable */
27 import {async, ComponentFixture, TestBed, inject} from '@angular/core/testing';
28 import {NO_ERRORS_SCHEMA} from '@angular/core';
29 import {FormsModule} from '@angular/forms';
30 import { NgxSpinnerService } from 'ngx-spinner';
31 import {NotificationService} from '../../../shared/services/notification.service';
32 import {ParamShareService} from '../../../shared/services/paramShare.service';
33 import {MappingEditorService} from '../../../shared/services/mapping-editor.service';
34 import {ModalComponent} from '../../../shared/modal/modal.component';
35 import {DialogService} from 'ng2-bootstrap-modal';
36 import {ConfirmComponent} from '../../../shared/confirmModal/confirm.component';
37 import {RouterTestingModule} from '@angular/router/testing';
38 import {HttpUtilService} from '../../../shared/services/httpUtil/http-util.service';
39 import {UtilityService} from '../../../shared/services/utilityService/utility.service';
40
41 import {BuildDesignComponent} from '../build-artifacts.component';
42 import {NotificationsService} from 'angular2-notifications';
43 import {HomeComponent} from '../../../home/home/home.component';
44 import {LogoutComponent} from '../../../shared/components/logout/logout.component';
45 import {HelpComponent} from '../../../shared/components/help/help/help.component';
46 import {AboutUsComponent} from '../../../about-us/aboutus.component';
47 import {TestComponent} from '../../../test/test.component';
48 import {ParameterComponent} from './parameter.component';
49 import {HttpModule} from '@angular/http';
50 import { NgProgress } from 'ngx-progressbar';
51 import { APIService } from "../../../shared/services/cdt.apicall";
52
53
54
55 describe('ParameterComponent', () => {
56     let component: ParameterComponent;
57     let fixture: ComponentFixture<ParameterComponent>;
58     const routes = [
59         {
60             path: 'home',
61             component: HomeComponent
62         }, {
63             path: 'vnfs',
64             loadChildren: './vnfs/vnfs.module#VnfsModule'
65         }, {
66             path: 'test',
67             component: TestComponent
68         },
69         {
70             path: 'help',
71             component: HelpComponent
72         }, {
73             path: 'aboutUs',
74             component: AboutUsComponent
75         }, {
76             path: 'logout',
77             component: LogoutComponent
78         }, {
79             path: '',
80             redirectTo: '/home',
81             pathMatch: 'full'
82         }
83     ];
84     beforeEach(async(() => {
85         TestBed.configureTestingModule({
86             declarations: [ParameterComponent, HomeComponent, TestComponent, HelpComponent, AboutUsComponent, LogoutComponent],
87             schemas: [NO_ERRORS_SCHEMA],
88             imports: [HttpModule, FormsModule, RouterTestingModule.withRoutes(routes)],
89             providers: [APIService, UtilityService, NgProgress, BuildDesignComponent, ParamShareService, DialogService, NotificationService, HttpUtilService, MappingEditorService, NotificationsService, NgxSpinnerService]
90         })
91             .compileComponents();
92     }));
93
94     beforeEach(() => {
95         fixture = TestBed.createComponent(ParameterComponent);
96         component = fixture.componentInstance;
97         fixture.detectChanges();
98     });
99
100     it('should create', () => {
101         expect(component).toBeTruthy();
102     });
103
104     it('should call ngOnInit...', inject([MappingEditorService, ParamShareService], (mappingEditorService: MappingEditorService, paramShareService:ParamShareService) => {
105     
106         mappingEditorService.latestAction = {"action":"Configure","action-level":"vnf","scope":{"vnf-type":"ticktack","vnfc-type":""},"template":"Y","vm":[],"device-protocol":"CHEF","user-name":"","port-number":"","artifact-list":[{"artifact-name":"template_Configure_ticktack_0.0.1V.json","artifact-type":"config_template"},{"artifact-name":"pd_Configure_ticktack_0.0.1V.yaml","artifact-type":"parameter_definitions"}],"scopeType":"vnf-type"};
107         mappingEditorService.appDataObject = {"value" : ''};
108         mappingEditorService.downloadDataObject = {"value": ''};
109         mappingEditorService.identifier = "identifier";
110         component.ngOnInit();
111     
112     }));
113
114     it('should test selectedNavItem method...', () => {
115             component.selectedNavItem('item');
116             expect(component.item).toEqual('item');
117         });
118
119     it('should set the selectedUploadType value', ()=>{
120         let obj = {value : 'type1', display : 'display1'};
121         component.uploadTypes = [obj];
122         component.showUpload();
123         expect(component.selectedUploadType.toString()).toEqual("type1");
124     });
125
126
127      it('should retrieve PD from APPC...', () => {
128     expect(component.getPD());
129   });
130
131   fit('should infer some information from reference object...', inject([MappingEditorService, UtilityService], (mappingEditorService: MappingEditorService, utilityService: UtilityService) => {
132     // mappingEditorService.latestAction = {"action":"Configure","action-level":"vnf","scope":{"vnf-type":"ticktack","vnfc-type":""},"template":"Y","vm":[],"device-protocol":"CHEF","user-name":"","port-number":"","artifact-list":[{"artifact-name":"template_Configure_ticktack_0.0.1V.json","artifact-type":"config_template"},{"artifact-name":"pd_Configure_ticktack_0.0.1V.yaml","artifact-type":"parameter_definitions"}],"scopeType":"vnf-type"};
133     mappingEditorService.newObject = {"action":"Configure",
134                                         "vnfc": "vnfcType",
135                                        "action-level":"vnf",
136                                         "scope":{"vnf-type":"ticktack","vnfc-type":""},
137                                         "template":"Y",
138                                         "vm":[],
139                                         "device-protocol":"CHEF",
140                                         "user-name":"",
141                                         "port-number":"",
142                                         "artifact-list":[
143                                             {"artifact-name":"template_Configure_ticktack_0.0.1V.json",
144                                             "artifact-type":"config_template"},
145                                             {"artifact-name":"pd_Configure_ticktack_0.0.1V.yaml",
146                                             "artifact-type":"parameter_definitions"}
147                                         ],"scopeType":"vnf-type",
148                                         "vnf": "ticktack",
149                                         "protocol": 'CHEF',
150                                         "pd_artifact": 'pd_Configure_ticktack_0.0.1V.yaml'}; 
151     utilityService.setTracelvl(1);
152     expect(component.ngOnInit());
153     expect(component.vnfType).toEqual('ticktack');
154     expect(component.vnfcType).toEqual('vnfcType');
155     expect(component.protocol).toEqual('CHEF');
156     expect(component.action).toEqual('Configure');
157     expect(component.artifact_fileName).toEqual('pd_Configure_ticktack_0.0.1V.yaml');
158   }));
159
160
161   it('should retrieve the PD from cache...', inject([MappingEditorService, ParamShareService], (mappingEditorService: MappingEditorService, paramShareService:ParamShareService) => {
162     mappingEditorService.latestAction = {"action":"Configure","action-level":"vnf","scope":{"vnf-type":"ticktack","vnfc-type":""},"template":"Y","vm":[],"device-protocol":"CHEF","user-name":"","port-number":"","artifact-list":[{"artifact-name":"template_Configure_ticktack_0.0.1V.json","artifact-type":"config_template"},{"artifact-name":"pd_Configure_ticktack_0.0.1V.yaml","artifact-type":"parameter_definitions"}],"scopeType":"vnf-type"};
163     paramShareService.setSessionParamData("TEST PD INFORMATION");
164     expect(component.ngAfterViewInit()).toEqual([]);
165   }));
166
167
168   it('should set the ruletypes for source A&AI...', inject([MappingEditorService, ParamShareService], (mappingEditorService: MappingEditorService, paramShareService:ParamShareService) => {
169     let obj = {"name":"name1","type":"ipv4-address","description":"xxx","required":"true","default":null,"source":"A&AI","rule-type":null,"request-keys":[{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null}],"response-keys":[{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null}],"ruleTypeValues":[null]}
170     let data = "A&AI";
171     expect(component.sourceChanged(data, obj));
172     expect(obj.ruleTypeValues).toEqual([null, 'vnf-name', 'vm-name-list', 'vnfc-name-list', 'vnf-oam-ipv4-address', 'vnfc-oam-ipv4-address-list']);
173   }));
174
175   it('should set the ruletypes for source Manual...', inject([MappingEditorService, ParamShareService], (mappingEditorService: MappingEditorService, paramShareService:ParamShareService) => {
176     let obj = {"name":"name1","type":"ipv4-address","description":"xxx","required":"true","default":null,"source":"A&AI","rule-type":null,"request-keys":[{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null}],"response-keys":[{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null}],"ruleTypeValues":[null]}
177     let data = "Manual";
178     expect(component.sourceChanged(data, obj));
179     expect(obj.ruleTypeValues).toEqual([null]);
180     expect(obj['rule-type']).toBeNull();
181   }));
182
183   it('should set the ruletypes for source INSTAR...', inject([MappingEditorService, ParamShareService], (mappingEditorService: MappingEditorService, paramShareService:ParamShareService) => {
184     let obj = {"name":"name1","type":"ipv4-address","description":"xxx","required":"true","default":null,"source":"A&AI","rule-type":null,"request-keys":[{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null}],"response-keys":[{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null}],"ruleTypeValues":[null]}
185     let data = "INSTAR";
186     expect(component.sourceChanged(data, obj));
187     expect(obj.ruleTypeValues).toEqual([null]);
188   }));
189
190   it('should set the ruletypes for ruletype null...', inject([MappingEditorService, ParamShareService], (mappingEditorService: MappingEditorService, paramShareService:ParamShareService) => {
191     let obj = {"name":"name1","type":"ipv4-address","description":"xxx","required":"true","default":null,"source":"A&AI","rule-type":null,"request-keys":[{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null}],"response-keys":[{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null}],"ruleTypeValues":[null]}
192     let data = null
193     expect(component.ruleTypeChanged(data, obj));
194     expect(obj['showFilterFields']).toBeFalsy();
195     expect(obj['rule-type']).toBeNull();
196   }));
197
198   it('should set the ruletypes for ruletype vm-name-list...', inject([MappingEditorService, ParamShareService], (mappingEditorService: MappingEditorService, paramShareService:ParamShareService) => {
199     let obj = {"name":"name1","type":"ipv4-address","description":"xxx","required":"true","default":null,"source":"A&AI","rule-type":null,"request-keys":[{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null}],"response-keys":[{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null}],"ruleTypeValues":[null]}
200     let data = 'vm-name-list';
201     let sourceObject = component.ruleTypeConfiguaration[data];
202
203     expect(component.ruleTypeChanged(data, obj));
204     expect(obj['showFilterFields']).toBeTruthy();
205     expect(obj['rule-type']).toBeNull();
206
207     for (let x = 0; x < sourceObject.length; x++) {
208         expect(obj['response-keys'][x]['key-name']).toEqual(sourceObject[x]['key-name']);
209         expect(obj['response-keys'][x]['key-value']).toEqual(sourceObject[x]['key-value']);
210     }
211   }));
212
213
214   it('should set the ruletypes for ruletype vnf-name...', inject([MappingEditorService, ParamShareService], (mappingEditorService: MappingEditorService, paramShareService:ParamShareService) => {
215     let obj = {"name":"name1","type":"ipv4-address","description":"xxx","required":"true","default":null,"source":"A&AI","rule-type":null,"request-keys":[{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null}],"response-keys":[{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null}],"ruleTypeValues":[null]}
216     let data = "vnf-name";
217     expect(component.ruleTypeChanged(data, obj));
218     expect(obj['showFilterFields']).toBeFalsy();
219     expect(obj['response-keys'][3]['key-name']).toBeNull;
220     expect(obj['response-keys'][3]['key-value']).toBeNull;
221     expect(obj['response-keys'][4]['key-name']).toBeNull;
222     expect(obj['response-keys'][4]['key-value']).toBeNull;
223   }));
224    
225   it('should read file key file content...', () => {
226       let file = new File(["testing"], "foo.XLS", {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
227       let uploadType = 'keyfile';
228       let input = {files: [file]};
229
230       component.fileChange(input, uploadType);
231   });
232
233
234   it('should read file key file content...', () => {
235       let file = new File(["testing"], "foo.XLS", {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
236       let uploadType = 'pdfile';
237       let input = {files: [file]};
238
239       component.fileChange(input, uploadType);
240   }); 
241
242
243 });