add new action configscalein for cdt
[appc/cdt.git] / src / app / vnfs / build-artifacts / reference-dataform / reference-dataform.component.spec.ts
1 /*
2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
5
6 Modification Copyright (C) 2018 IBM.
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 ============LICENSE_END============================================
23 */
24 /* tslint:disable:no-unused-variable */
25 import { ComponentFixture, TestBed, async, inject } from '@angular/core/testing';
26 import { Http, Response, ResponseOptions, XHRBackend } from '@angular/http';
27
28 import { BuildDesignComponent } from '../build-artifacts.component';
29 import { DialogService } from 'ng2-bootstrap-modal';
30 import { FormsModule } from '@angular/forms';
31 import { HttpModule } from '@angular/http';
32 import { HttpUtilService } from '../../../shared/services/httpUtil/http-util.service';
33 import { MappingEditorService } from '../../..//shared/services/mapping-editor.service';
34 import { NO_ERRORS_SCHEMA } from '@angular/core';
35 import { NgModule } from '@angular/core';
36 import { NgProgress } from 'ngx-progressbar';
37 import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
38 import { NotificationService } from '../../../shared/services/notification.service';
39 import { Observable } from 'rxjs/Observable';
40 import { ParamShareService } from '../../..//shared/services/paramShare.service';
41 import { ReferenceDataformComponent } from './reference-dataform.component';
42 import { RouterTestingModule } from '@angular/router/testing';
43 import { SharedModule } from '../../../shared/shared.module';
44 import { environment } from '../../../../environments/environment';
45
46 describe('ReferenceDataformComponent', () => {
47     let component: ReferenceDataformComponent;
48     let fixture: ComponentFixture<ReferenceDataformComponent>;
49     let service: MockMappingService;
50     let originalTimeout;
51
52     let httpMock: HttpUtilService
53     //mockingthe data for mappingEditorService
54
55     class HttpMock {
56         post(req) {
57
58             return Observable.of(
59
60
61                 {
62                     "output": { "data": { "block": "{\"userID\":null,\"designInfo\":null,\"statusInfo\":null,\"artifactInfo\":[{\"artifact-content\":\" {\\\"reference_data\\\":[{\\\"action\\\":\\\"Configure\\\",\\\"action-level\\\":\\\"vnf\\\",\\\"scope\\\":{\\\"vnf-type\\\":\\\"Btesting123\\\",\\\"vnfc-type\\\":\\\"\\\"},\\\"template\\\":\\\"Y\\\",\\\"vm\\\":[],\\\"device-protocol\\\":\\\"ANSIBLE\\\",\\\"user-name\\\":\\\"root\\\",\\\"port-number\\\":\\\"830\\\",\\\"artifact-list\\\":[{\\\"artifact-name\\\":\\\"template_Configure_Btesting123_0.0.1V.json\\\",\\\"artifact-type\\\":\\\"config_template\\\"},{\\\"artifact-name\\\":\\\"pd_Configure_Btesting123_0.0.1V.yaml\\\",\\\"artifact-type\\\":\\\"parameter_definitions\\\"}],\\\"scopeType\\\":\\\"vnf-type\\\"},{\\\"action\\\":\\\"AllAction\\\",\\\"action-level\\\":\\\"vnf\\\",\\\"scope\\\":{\\\"vnf-type\\\":\\\"Btesting123\\\",\\\"vnfc-type\\\":\\\"\\\"},\\\"artifact-list\\\":[{\\\"artifact-name\\\":\\\"reference_AllAction_Btesting123_0.0.1V.json\\\",\\\"artifact-type\\\":\\\"reference_template\\\"}]},{\\\"action\\\":\\\"ConfigScaleOut\\\",\\\"action-level\\\":\\\"vnf\\\",\\\"scope\\\":{\\\"vnf-type\\\":\\\"Btesting123\\\",\\\"vnfc-type\\\":\\\"\\\"},\\\"template\\\":\\\"Y\\\",\\\"vm\\\":[{\\\"template-id\\\":\\\"id1\\\",\\\"vm-instance\\\":1,\\\"vnfc\\\":[{\\\"vnfc-instance\\\":\\\"1\\\",\\\"vnfc-function-code\\\":\\\"12313\\\",\\\"ipaddress-v4-oam-vip\\\":\\\"Y\\\",\\\"group-notation-type\\\":\\\"first-vnfc-name\\\",\\\"group-notation-value\\\":\\\"pair\\\",\\\"vnfc-type\\\":\\\"vDBE-V\\\"}]},{\\\"template-id\\\":\\\"id1\\\",\\\"vm-instance\\\":2,\\\"vnfc\\\":[{\\\"vnfc-instance\\\":\\\"1\\\",\\\"vnfc-function-code\\\":\\\"12313\\\",\\\"ipaddress-v4-oam-vip\\\":\\\"Y\\\",\\\"group-notation-type\\\":\\\"first-vnfc-name\\\",\\\"group-notation-value\\\":\\\"pair\\\",\\\"vnfc-type\\\":\\\"vDBE-V\\\"}]},{\\\"template-id\\\":\\\"id1\\\",\\\"vm-instance\\\":3,\\\"vnfc\\\":[{\\\"vnfc-instance\\\":\\\"1\\\",\\\"vnfc-function-code\\\":\\\"12313\\\",\\\"ipaddress-v4-oam-vip\\\":\\\"Y\\\",\\\"group-notation-type\\\":\\\"first-vnfc-name\\\",\\\"group-notation-value\\\":\\\"pair\\\",\\\"vnfc-type\\\":\\\"vDBE-V\\\"}]}],\\\"device-protocol\\\":\\\"CHEF\\\",\\\"user-name\\\":\\\"root\\\",\\\"port-number\\\":\\\"830\\\",\\\"artifact-list\\\":[{\\\"artifact-name\\\":\\\"template_ConfigScaleOut_Btesting123_0.0.1V_id1.json\\\",\\\"artifact-type\\\":\\\"config_template\\\"},{\\\"artifact-name\\\":\\\"pd_ConfigScaleOut_Btesting123_0.0.1V_id1.yaml\\\",\\\"artifact-type\\\":\\\"parameter_definitions\\\"}],\\\"scopeType\\\":\\\"vnf-type\\\",\\\"template-id-list\\\":[\\\"id1\\\"]}]}\"}]}", "requestId": "563507520187" }, "status": { "code": "400", "message": "success" } },
63
64                     "status": { code: "400", message: "success" }
65                 }
66
67
68             )
69         }
70     }
71     class MockMappingService {
72         public latestAction; // = {"action":"Configure"}
73         appDataObject = {
74             reference: {},
75             template: {
76                 templateData: {},
77                 nameValueData: {}
78             },
79             pd: {}
80         };
81         downloadDataObject = {
82             reference: {},
83             template: {
84                 templateData: {},
85                 nameValueData: {},
86                 templateFileName: '',
87                 nameValueFileName: ''
88             },
89             pd: {
90                 pdData: '',
91                 pdFileName: ''
92             }
93         }
94         referenceNameObjects = [
95             {
96                 action: "Configure"
97             }, {
98                 action: "StartApplication"
99             }
100         ]
101
102         setTemplateMappingDataFromStore(data) {
103             return "test"
104         }
105         getReferenceList() {
106             return ["test data"]
107         }
108         changeNav() {
109             return "test data"
110         }
111         setParamContent(data) {
112             return "test"
113         }
114         setSessionParamData(data) {
115             return "test"
116         }
117
118         saveLatestAction() { }
119         saveLatestIdentifier() { }
120         changeNavDownloadData() { }
121         changeNavAppData() { }
122     }
123     class MockreferenceDataObject { }
124     beforeEach(async(() => {
125         //  originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
126         //  jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
127         TestBed.configureTestingModule({
128             declarations: [ReferenceDataformComponent],
129             schemas: [NO_ERRORS_SCHEMA],
130             imports: [
131
132                 FormsModule, RouterTestingModule, HttpModule, NgbModule.forRoot(),
133                 SharedModule.forRoot()
134             ],
135             providers: [
136                 BuildDesignComponent, {
137                     provide: MappingEditorService,
138                     useClass: MockMappingService
139                 },
140                 ParamShareService,
141                 DialogService,
142                 NotificationService, {
143                     provide: HttpUtilService,
144                     useClass: HttpMock
145                 }
146
147             ]
148         }).compileComponents();
149     }));
150     beforeEach(() => {
151
152         fixture = TestBed.createComponent(ReferenceDataformComponent);
153         component = fixture.componentInstance;
154         //  component = new ReferenceDataformComponent(service)
155         fixture.detectChanges();
156         service = TestBed.get(MappingEditorService)
157         httpMock = TestBed.get(HttpUtilService)
158         sessionStorage.setItem('vnfParams', JSON.stringify({ vnfType: "test", vnfcType: "testVnfcType" }));
159         // component = new ReferenceDataformComponent(service)
160     });
161     it('should create reference component', () => {
162         expect(component).toBeTruthy();
163     });
164     it('Should load data from mapping sevice', () => {
165         component.ngOnInit()
166         expect(component.tempAllData.length).toBe(2)
167     })
168     it('testing init method', () => {
169         component.ngOnInit()
170         expect(component.tempAllData.length).toBe(2)
171     })
172
173     it("should set app data from service", () => {
174         component.ngOnInit()
175         expect(component.appData)
176             .not
177             .toBe(undefined)
178     })
179     it("should set download from service", () => {
180         component.ngOnInit()
181         expect(component.downloadData)
182             .not
183             .toBe(undefined)
184     })
185     it('Should reset form', () => {
186         component.resetForm()
187         expect(component.referenceDataObject['device-protocol']).toBe('')
188         expect(component.referenceDataObject['action-level']).toBe('vnf')
189         expect(component.referenceDataObject.template).toBe('Y')
190         expect(component.referenceDataObject['user-name']).toBe('')
191         expect(component.Sample['vnfc-type']).toBe('')
192         expect(component.refernceScopeObj.sourceType).toBe('')
193         expect(component.referenceDataObject['port-number']).toBe('')
194     })
195     it("prepare reference method at vnf level", () => {
196
197         component.referenceDataObject = {
198             action: 'Configure',
199             'action-level': 'vnf',
200             scope: {
201                 'vnf-type': '',
202                 'vnfc-type-list': []
203             },
204             'template': 'Y',
205             vm: [],
206             'device-protocol': '',
207             'user-name': '',
208             'port-number': '',
209             'artifact-list': []
210         };
211         component.vnfcIdentifier = '346';
212         component.prepareReferenceObject();
213         expect(component.referenceDataObject['action-level']).toBe("vnf")
214     })
215
216     it("prepare reference method at vnfc level", () => {
217
218         component.referenceDataObject = {
219             action: 'Configure',
220             'action-level': 'vnf',
221             scope: {
222                 'vnf-type': '123',
223                 'vnfc-type-list': ['346']
224             },
225             'template': 'Y',
226             vm: [],
227             'device-protocol': '',
228             'user-name': '',
229             'port-number': '',
230             'artifact-list': []
231         }
232         component.vnfcIdentifier = '346';
233         component.prepareReferenceObject();
234         expect(component.referenceDataObject['action-level']).toBe("vnf")
235     })
236
237     it("prepare reference method at vnf and vnfc level", () => {
238
239         component.referenceDataObject = {
240             action: 'starttApplication',
241             'action-level': 'vnf',
242             scope: {
243                 'vnf-type': '123',
244                 'vnfc-type-list': ['346']
245             },
246             'template': 'Y',
247             vm: [],
248             'device-protocol': 'ANSIBLE',
249             'user-name': '',
250             'port-number': '',
251             'artifact-list': []
252         };
253         component.vnfcIdentifier = '346';
254         component.prepareReferenceObject();
255
256         expect(component.referenceDataObject['action-level']).toBe("vnf")
257     })
258     //deviceprotocols netconf
259     it("prepare reference method testing with netconf", () => {
260
261         component.referenceDataObject = {
262             action: 'starttApplication',
263             'action-level': 'vnf',
264             scope: {
265                 'vnf-type': '123',
266                 'vnfc-type-list': ['346']
267             },
268             'template': 'Y',
269             vm: [],
270             'device-protocol': 'NETCONF-XML',
271             'user-name': '',
272             'port-number': '',
273             'artifact-list': []
274         }
275         component.vnfcIdentifier = '346';
276         component.prepareReferenceObject();
277         expect(component.referenceDataObject['action-level']).toBe("vnf")
278     })
279     //template id list
280     it("prepare reference method at template id list", () => {
281
282         component.referenceDataObject = {
283             action: 'ConfigScaleOut',
284             'action-level': 'vnf',
285             scope: {
286                 'vnf-type': '123',
287                 'vnfc-type-list': ['346']
288             },
289             'template': 'Y',
290             vm: [],
291             'device-protocol': 'NETCONF-XML',
292             'user-name': '',
293             'port-number': '',
294             'artifact-list': []
295
296         }
297         component.vnfcIdentifier = '346';
298         component.referenceDataObject['template-id-list'] = ['id1', 'id2']
299
300         component.prepareReferenceObject();
301
302         expect(component.referenceDataObject['action-level']).toBe("vnf")
303     })
304     it("prepare reference method at vnfc level", () => {
305
306         component.referenceDataObject = {
307             action: 'startApplication',
308             'action-level': 'vnfc',
309             scope: {
310                 'vnf-type': '',
311                 'vnfc-type-list': ['346']
312             },
313             'template': 'Y',
314             vm: [],
315             'device-protocol': '',
316             'user-name': '',
317             'port-number': '',
318             'artifact-list': []
319         };
320         component.vnfcIdentifier = '346';
321         component.prepareReferenceObject();
322         expect(component.referenceDataObject['action-level']).toBe("vnf")
323     })
324     it("prepare reference method at vnf level", () => {
325
326         component.referenceDataObject = {
327             action: 'ConfigScaleOut',
328             'action-level': 'vnf',
329             scope: {
330                 'vnf-type': '',
331                 'vnfc-type-list': ['346']
332             },
333             'template': 'Y',
334             vm: [],
335             'device-protocol': '',
336             'user-name': '',
337             'port-number': '',
338             'artifact-list': []
339         };
340         component.vnfcIdentifier = '346';
341         component.prepareReferenceObject();
342         expect(component.referenceDataObject['action-level']).toBe("vnf")
343     })
344
345     it('should create reference component', () => {
346
347         expect(component).toBeTruthy();
348     });
349     it('configscaleout test', () => {
350         service.latestAction = {
351             action: 'ConfigScaleOut',
352             'action-level': 'vnf',
353             scope: {
354                 'vnf-type': '',
355                 'vnfc-type': ''
356             },
357             'template': 'Y',
358             vm: [],
359             'device-protocol': '',
360             'user-name': '',
361             'port-number': '',
362             'artifact-list': []
363         }
364         service.referenceNameObjects = [
365             {
366                 action: "Configure"
367             }, {
368                 action: "StartApplication"
369             }
370         ]
371         component.ngOnInit()
372         expect(component.referenceDataObject.action).toBe("ConfigScaleOut");
373
374     });
375     it('configscalein test', () => {
376         service.latestAction = {
377             action: 'ConfigScaleIn',
378             'action-level': 'vnf',
379             scope: {
380                 'vnf-type': '',
381                 'vnfc-type': ''
382             },
383             'template': 'Y',
384             vm: [],
385             'device-protocol': '',
386             'user-name': '',
387             'port-number': '',
388             'artifact-list': []
389         }
390         service.referenceNameObjects = [
391             {
392                 action: "Configure"
393             }, {
394                 action: "StartApplication"
395             }
396         ]
397         component.ngOnInit()
398         expect(component.referenceDataObject.action).toBe("ConfigScaleIn");
399
400     });
401     it('shoud add vms with template id when the action is configscaleout ', () => {
402         component.referenceDataObject = {
403             action: 'ConfigScaleOut',
404             'action-level': 'vnf',
405             scope: {
406                 'vnf-type': '',
407                 'vnfc-type-list': ['346']
408             },
409             'template': 'Y',
410             vm: [
411                 {
412                     vnfc: [
413                         {
414                             test: "123"
415                         }
416                     ]
417
418                 }
419             ],
420             'device-protocol': '',
421             'user-name': '',
422             'port-number': '',
423             'artifact-list': []
424         }
425
426         component.refernceScopeObj.from = "3"
427         // let arr = [1, 2];
428         component.addVms()
429         expect(component.referenceDataObject.vm.length).toBe(4);
430     });
431     it('shoud add vms with template id when the action is configscalein ', () => {
432         component.referenceDataObject = {
433             action: 'ConfigScaleIn',
434             'action-level': 'vnf',
435             scope: {
436                 'vnf-type': '',
437                 'vnfc-type-list': ['346']
438             },
439             'template': 'Y',
440             vm: [
441                 {
442                     vnfc: [
443                         {
444                             test: "123"
445                         }
446                     ]
447
448                 }
449             ],
450             'device-protocol': '',
451             'user-name': '',
452             'port-number': '',
453             'artifact-list': []
454         }
455
456         component.refernceScopeObj.from = "3"
457         // let arr = [1, 2];
458         component.addVms()
459         expect(component.referenceDataObject.vm.length).toBe(4);
460     });
461     it('shoud add vms with template id when the action is not configscaleout or configscalein', () => {
462         component.referenceDataObject = {
463             action: 'Config',
464             'action-level': 'vnf',
465             scope: {
466                 'vnf-type': '',
467                 'vnfc-type-list': ['346']
468             },
469             'template': 'Y',
470             vm: [
471                 {
472                     vnfc: [
473                         {
474                             test: "123"
475                         }
476                     ]
477
478                 }
479             ],
480             'device-protocol': '',
481             'user-name': '',
482             'port-number': '',
483             'artifact-list': []
484         }
485
486         component.refernceScopeObj.from = "3"
487         // let arr = [1, 2];
488         component.addVms()
489         expect(component.referenceDataObject.vm[0]['template-id']).toBe(undefined);
490     });
491
492     it('testing ngdestroy', () => {
493         this.uploadFileName = 'testing'
494         component.ngOnDestroy()
495         expect(component.uploadedDataArray.length).toBe(0);
496         expect(component.uploadFileName).toBe('');
497     });
498     it('should validate numbers', () => {
499
500         component.numberValidation(1)
501         expect(component.numberOfVmTest).toBe(true);
502
503     });
504
505     it('should validate numbers if input is string', () => {
506
507         component.numberValidation('test')
508         expect(component.numberOfVmTest).toBe(false);
509
510     });
511
512     it('testing check if elements exixts in an array', () => {
513
514         let x = component.checkIfelementExistsInArray(2, [1, 2, 3])
515         expect(x).toBeTruthy();
516     });
517
518     it('should set action in session if type is action', () => {
519
520         component.updateSessionValues("test event for action", "action")
521
522         expect(sessionStorage.getItem('action')).toBe('test event for action');
523     });
524     it('should set action in session if type is vnfType', () => {
525
526         component.updateSessionValues("test event for vnfType", "vnfType")
527
528         expect(sessionStorage.getItem('vnfType')).toBe('test event for vnfType');
529     });
530
531     it('should add vnfs on to reference Object ', () => {
532
533         component.referenceDataObject = {
534             action: '',
535             'action-level': 'vnf',
536             scope: {
537                 'vnf-type': '',
538                 'vnfc-type-list': ['346']
539             },
540             'template': 'Y',
541             vm: [
542                 {
543                     vnfc: [
544                         {
545                             test: "123"
546                         }
547                     ]
548
549                 }
550             ],
551             'device-protocol': '',
552             'user-name': '',
553             'port-number': '',
554             'artifact-list': []
555         };
556
557         component.addVnfcData(0)
558
559         expect(component.referenceDataObject.vm[0].vnfc.length).toBe(2);
560     });
561
562     it("should remove feature from the reference object ", () => {
563         component.referenceDataObject = {
564             action: 'Configure',
565             'action-level': 'vnf',
566             scope: {
567                 'vnf-type': '',
568                 'vnfc-type-list': ['346']
569             },
570             'template': 'Y',
571             vm: [
572                 {
573                     vnfc: [
574                         {
575                             test: "123"
576                         }
577                     ]
578
579                 }, {
580                     vnfc: [
581                         {
582                             test: "123"
583                         }
584                     ]
585
586                 }
587             ],
588             'device-protocol': '',
589             'user-name': '',
590             'port-number': '',
591             'artifact-list': []
592         };
593
594         component.removeFeature(0, 0, 0)
595
596         expect(component.referenceDataObject.vm.length).toBe(1)
597     })
598
599     it("remove templateIds vm if action is confiogscaleout", () => {
600         component.referenceDataObject = {
601             action: 'ConfigScaleOut',
602             'action-level': 'vnf',
603             scope: {
604                 'vnf-type': '',
605                 'vnfc-type-list': ['346']
606             },
607             'template': 'Y',
608             "vm": [
609                 {
610                     "template-id": "klmklj",
611                     "vm-instance": 1,
612                     "vnfc": [
613                         {
614                             "vnfc-instance": "1",
615                             "vnfc-function-code": "klkl",
616                             "ipaddress-v4-oam-vip": "",
617                             "group-notation-type": "",
618                             "group-notation-value": "",
619                             "vnfc-type": "nnk"
620                         }
621                     ]
622                 }, {
623                     "template-id": "test 12",
624                     "vm-instance": 2,
625                     "vnfc": [
626                         {
627                             "vnfc-instance": "1",
628                             "vnfc-function-code": "klkl",
629                             "ipaddress-v4-oam-vip": "",
630                             "group-notation-type": "",
631                             "group-notation-value": "",
632                             "vnfc-type": "nnk"
633                         }
634                     ]
635                 }
636             ],
637             'device-protocol': '',
638             'user-name': '',
639             'port-number': '',
640             'artifact-list': []
641         };
642
643         component.removeFeature(0, 0, 'test 12')
644
645         //expect(component.referenceDataObject.vm.length).toBe(2)
646
647     })
648
649     it("remove templateIds vm if action is configscalein", () => {
650         component.referenceDataObject = {
651             action: 'ConfigScaleIn',
652             'action-level': 'vnf',
653             scope: {
654                 'vnf-type': '',
655                 'vnfc-type-list': ['346']
656             },
657             'template': 'Y',
658             "vm": [
659                 {
660                     "template-id": "klmklj",
661                     "vm-instance": 1,
662                     "vnfc": [
663                         {
664                             "vnfc-instance": "1",
665                             "vnfc-function-code": "klkl",
666                             "ipaddress-v4-oam-vip": "",
667                             "group-notation-type": "",
668                             "group-notation-value": "",
669                             "vnfc-type": "nnk"
670                         }
671                     ]
672                 }, {
673                     "template-id": "test 12",
674                     "vm-instance": 2,
675                     "vnfc": [
676                         {
677                             "vnfc-instance": "1",
678                             "vnfc-function-code": "klkl",
679                             "ipaddress-v4-oam-vip": "",
680                             "group-notation-type": "",
681                             "group-notation-value": "",
682                             "vnfc-type": "nnk"
683                         }
684                     ]
685                 }
686             ],
687             'device-protocol': '',
688             'user-name': '',
689             'port-number': '',
690             'artifact-list': []
691         };
692
693         component.removeFeature(0, 0, 'test 12')
694
695         //expect(component.referenceDataObject.vm.length).toBe(2)
696
697     })
698
699     it("should add capabilities", () => {
700         component.uploadedDataArray = [
701             ['y', 'n']
702         ]
703         component.addVmCapabilitiesData()
704
705         expect(component.tempAllData.length).toBe(3)
706     })
707     it("should add capabilities", () => {
708         service.latestAction = {
709             action: 'OpenStack Actions',
710             'action-level': 'vnf',
711             scope: {
712                 'vnf-type': '',
713                 'vnfc-type': ''
714             },
715             'template': 'Y',
716             vm: [],
717             'device-protocol': '',
718             'user-name': '',
719             'port-number': '',
720             'artifact-list': []
721         }
722         service.referenceNameObjects = [
723             {
724                 action: "Configure"
725             }, {
726                 action: "StartApplication"
727             }
728         ]
729
730         component.prepareReferenceObject();
731
732         expect(component.referenceDataObject['action-level']).toBe("vnf")
733     })
734
735     it("should add capabilities", () => {
736         service.latestAction = {
737             action: 'OpenStack Actions',
738             'action-level': 'vnf',
739             scope: {
740                 'vnf-type': '',
741                 'vnfc-type': ''
742             },
743             'template': 'Y',
744             vm: [],
745             'device-protocol': '',
746             'user-name': '',
747             'port-number': '',
748             'artifact-list': []
749         }
750
751         component.referenceDataObject.action = "OpenStack Actions"
752         service.referenceNameObjects = [
753             {
754                 action: "Configure"
755             }, {
756                 action: "StartApplication"
757             }
758         ]
759
760         component.prepareReferenceObject();
761
762         expect(component.referenceDataObject['action-level']).toBe("vnf")
763     })
764
765     it("should switch vms if action is configscaleout", () => {
766
767         component.currentAction = "ConfigScaleOut"
768         service.latestAction = {
769             action: 'OpenStack Actions',
770             'action-level': 'vnf',
771             scope: {
772                 'vnf-type': '',
773                 'vnfc-type': ''
774             },
775             'template': 'Y',
776             vm: [],
777             'device-protocol': '',
778             'user-name': '',
779             'port-number': '',
780             'artifact-list': []
781         }
782         service.referenceNameObjects = [
783             {
784                 action: "Configure"
785             }, {
786                 action: "StartApplication"
787             }
788         ]
789
790         component.tempAllData = [
791             {
792                 action: "ConfigScaleOut",
793                 vm: [{}, {}]
794             }
795         ]
796
797         component.prepareReferenceObject();
798
799         expect(component.referenceDataObject.vm.length).toBe(2)
800     })
801     it("should switch vms if action is configscalein", () => {
802
803         component.currentAction = "ConfigScaleIn"
804         service.latestAction = {
805             action: 'OpenStack Actions',
806             'action-level': 'vnf',
807             scope: {
808                 'vnf-type': '',
809                 'vnfc-type': ''
810             },
811             'template': 'Y',
812             vm: [],
813             'device-protocol': '',
814             'user-name': '',
815             'port-number': '',
816             'artifact-list': []
817         }
818         service.referenceNameObjects = [
819             {
820                 action: "Configure"
821             }, {
822                 action: "StartApplication"
823             }
824         ]
825
826         component.tempAllData = [
827             {
828                 action: "ConfigScaleIn",
829                 vm: [{}, {}]
830             }
831         ]
832
833         component.prepareReferenceObject();
834
835         expect(component.referenceDataObject.vm.length).toBe(2)
836     })
837     it("should switch vms if action is configscaleout", () => {
838
839         component.currentAction = "ConfigScaleOut"
840         service.latestAction = {
841             action: 'OpenStack Actions',
842             'action-level': 'vnf',
843             scope: {
844                 'vnf-type': '',
845                 'vnfc-type': ''
846             },
847             'template': 'Y',
848             vm: [],
849             'device-protocol': '',
850             'user-name': '',
851             'port-number': '',
852             'artifact-list': []
853         }
854         service.referenceNameObjects = [
855             {
856                 action: "Configure"
857             }, {
858                 action: "StartApplication"
859             }
860         ]
861
862         component.tempAllData = [
863             {
864                 action: "startAplicaton"
865             }
866         ]
867
868         component.prepareReferenceObject();
869
870         expect(component.referenceDataObject.vm.length).toBe(0)
871     })
872     it("should switch vms if action is configscalein", () => {
873
874         component.currentAction = "ConfigScaleIn"
875         service.latestAction = {
876             action: 'OpenStack Actions',
877             'action-level': 'vnf',
878             scope: {
879                 'vnf-type': '',
880                 'vnfc-type': ''
881             },
882             'template': 'Y',
883             vm: [],
884             'device-protocol': '',
885             'user-name': '',
886             'port-number': '',
887             'artifact-list': []
888         }
889         service.referenceNameObjects = [
890             {
891                 action: "Configure"
892             }, {
893                 action: "StartApplication"
894             }
895         ]
896
897         component.tempAllData = [
898             {
899                 action: "startAplicaton"
900             }
901         ]
902
903         component.prepareReferenceObject();
904
905         expect(component.referenceDataObject.vm.length).toBe(0)
906     })
907     it('shoud show template identifier when action is config scaleout', () => {
908         let data = 'ConfigScaleOut'
909         component.toggleIdentifier(data)
910         expect(component.isConfigScaleOut).toBe(true);
911     });
912     it('shoud show template identifier when action is configscalein', () => {
913         let data = 'ConfigScaleIn'
914         component.toggleIdentifier(data)
915         expect(component.isConfigScaleIn).toBe(true);
916     });
917     it('shoud show template identifier when action is not configscaleout', () => {
918         let data = 'startApplication'
919         component.toggleIdentifier(data)
920         expect(component.isConfigScaleOut).toBe(false);
921     });
922     it('shoud show template identifier when action is not configscalein', () => {
923         let data = 'startApplication'
924         component.toggleIdentifier(data)
925         expect(component.isConfigScaleIn).toBe(false);
926     });
927
928     it('Should call get artifact', () => {
929
930         service.referenceNameObjects = undefined
931         component.ngOnInit()
932         expect(component.tempAllData.length).toBe(2)
933     })
934
935     it('Should call get artifact', () => {
936         let spy = spyOn(BuildDesignComponent.prototype, 'getRefData');
937         let refData = { "action": "Configure", "vnf-type": "test 1", "device-protocol": "ANSIBLE" };
938         sessionStorage.setItem('updateParams', JSON.stringify({ vnf: 123, userID: 'testUser' }))
939
940         component.getArtifact()
941
942         expect(spy).toHaveBeenCalled();
943         expect(component.tempAllData.length).toBe(3);
944     })
945
946     it('Save file - should not process if action is null ', () => {
947         component.referenceDataObject.action = ""
948         let fileSaved = component.save({}, true)
949         expect(fileSaved).toBe(undefined)
950     })
951     it('Save file - should not process if device protocol is null ', () => {
952         component.referenceDataObject.action = "Configure"
953         component.referenceDataObject['device-protocol'] = ''
954         let fileSaved = component.save({}, true)
955         expect(fileSaved).toBe(undefined)
956     })
957     it('Save file - should not process if device protocol is null ', () => {
958         component.referenceDataObject.action = "Configure"
959         component.referenceDataObject['device-protocol'] = "test"
960         component.downloadData.template.templateData = { "test": "test" }
961         component.downloadData.template.nameValueData = { "test": "test" }
962         component.downloadData.pd.pdData = "test"
963         let fileSaved = component.save({}, true)
964         //expect(fileSaved).toBe(undefined)
965     })
966
967     it('Save to appc file - should not process if action is null ', () => {
968         component.referenceDataObject.action = "";
969         component.referenceDataObject.scope['vnf-type'] = '';
970         component.tempAllData = [{
971             action: "Configure",
972             scope: {
973                 'vnf-type': "testVnf"
974             }
975         },{
976             action: "StartApplication",
977             scope: {
978                 'vnf-type': "testVnf"
979             }
980         }
981     ];
982         let fileSaved = component.saveToAppc();
983         expect(fileSaved).toBe(undefined)
984     })
985     it('Save to app cfile - should not process if device protocol is null ', () => {
986         component.referenceDataObject['device-protocol'] = ""
987         component.referenceDataObject.action = "Configure"
988         component.tempAllData = [{
989             action: "Configure",
990             scope: {
991                 'vnf-type': "testVnf"
992             }
993         },{
994             action: "StartApplication",
995             scope: {
996                 'vnf-type': "testVnf"
997             }
998         }
999     ];
1000         let fileSaved = component.saveToAppc();
1001         expect(fileSaved).toBe(undefined)
1002     })
1003     it('Save to appc file - should not process if device protocol is null ', () => {
1004         component.tempAllData = [
1005             {
1006                 action: "Configure",
1007                 scope: {
1008                     'vnf-type': "testVnf"
1009                 }
1010             }
1011         ]
1012         component.referenceDataObject.action = "Configure"
1013         component.referenceDataObject['device-protocol'] = "test"
1014         component.appData.template.templateData = { "test": "test" }
1015         component.appData.template.nameValueData = { "test": "test" }
1016         component.appData.pd = { "test": "test" }
1017         component.actionChanged = true
1018         component.currentAction = "COnfigure"
1019         let fileSaved = component.saveToAppc();
1020         expect(fileSaved).toBe(undefined)
1021     })
1022
1023     //   it('uploadfile  ', () => {  let    files = { 0: {name:'foo.XLS', size:
1024     // 500001} };     var mockEVet = {         target:{files:files}     }
1025     // component.upload(mockEVet)     //expect(fileSaved).toBe(undefined) })
1026
1027     it('validateTempAllData() of reference dataform', () => {
1028         component.validateTempAllData()
1029     })
1030     it('retriveFromAppc() of reference dataform', () => {
1031         sessionStorage.setItem('updateParams', JSON.stringify({ vnf: 123, userID: 'testUser' }))
1032         component.retriveFromAppc()
1033         expect(component.noCacheData).toBeFalsy()
1034     })
1035     it('retriveFromAppc() of reference dataform for false', () => {
1036         sessionStorage.setItem('updateParams', 'undefined')
1037         component.retriveFromAppc()
1038         expect(component.noCacheData).toBeTruthy()
1039     })
1040
1041     it('resetGroupNotation() of reference dataform for false case', () => {
1042         component.resetGroupNotation()
1043         expect(component.disableGrpNotationValue).toBeFalsy()
1044     })
1045     it('resetGroupNotation() of reference dataform for true case', () => {
1046         component.Sample['group-notation-type'] = "existing-group-name"
1047         component.resetGroupNotation()
1048         expect(component.disableGrpNotationValue).toBeTruthy()
1049     })
1050     it('resetVms() of reference dataform', () => {
1051         component.resetVms()
1052         expect(component.referenceDataObject.vm).toBeNull
1053     })
1054
1055     it('Clear cache ', () => {
1056         component.clearCache()
1057         expect(component.downloadData.reference['name']).toBe(undefined);
1058
1059     })
1060
1061     it('sholud reset group notification ', () => {
1062         component.Sample['group-notation-type'] = "existing-group-name"
1063         component.resetGroupNotation()
1064         expect(component.disableGrpNotationValue).toBe(true);
1065
1066     })
1067     it('sholud reset group notification if value does not match ', () => {
1068         component.Sample['group-notation-type'] = "123"
1069         component.resetGroupNotation()
1070         expect(component.disableGrpNotationValue).toBe(false);
1071
1072     })
1073     it('add identity group', () => {
1074         component.referenceDataObject['template-id-list'] = undefined
1075         component.templateId = "test"
1076         component.addToIdentDrp()
1077         expect(component.referenceDataObject['template-id-list'].length).toBe(1);
1078
1079     })
1080
1081     it('add identity group', () => {
1082
1083         component.resetVms()
1084         expect(component.referenceDataObject.vm.length).toBe(0);
1085         //expect(fileSaved).toBe(undefined)
1086     })
1087     it('data modified', () => {
1088
1089         component.dataModified()
1090
1091         component.referenceDataObject.vm = [1, 2]
1092         expect(component.referenceDataObject.vm.length).toBe(2);
1093         //expect(fileSaved).toBe(undefined)
1094     })
1095
1096     it("should set values on action change ConfigScaleOut", () => {
1097         component.actionChange('ConfigScaleOut', { valid: true });
1098
1099         expect(component.groupAnotationType.length).toBe(5)
1100     })
1101     it("shpukd return false if its very first action", () => {
1102         component.actionChange(null,{ valid: true });
1103
1104         expect(component.disableGrpNotationValue).toBe(false)
1105     })
1106     it("sholud check no configuration actions", () => {
1107         component.tempAllData = [
1108             {
1109                 action: "Configure",
1110                 scope: {
1111                     'vnf-type': "testVnf"
1112                 }
1113             }
1114         ]
1115         component.actionChange("Configure", { valid: true });
1116
1117         expect(component.nonConfigureAction).toBe(false)
1118     })
1119
1120     it("should set values on action change when action is HealthCheck ", () => {
1121         component.populateExistinAction("HealthCheck")
1122
1123         expect(component.deviceProtocols.length).toBe(4)
1124
1125     })
1126     it("should set values on action change when action is UpgradeBackout", () => {
1127         component.populateExistinAction("UpgradeBackout")
1128
1129         expect(component.deviceProtocols.length).toBe(3)
1130
1131     })
1132     it("should set values on action change when action is OpenStack Actions", () => {
1133         component.populateExistinAction("OpenStack Actions")
1134
1135         expect(component.deviceProtocols.length).toBe(2)
1136
1137     })
1138     it("should set values on action change when action is Configure", () => {
1139         component.tempAllData = [
1140             {
1141                 action: "Configure",
1142                 scope: {
1143                     'vnf-type': "testVnf"
1144                 }
1145             }
1146         ]
1147         component.populateExistinAction("Configure")
1148         expect(component.referenceDataObject.scope['vnf-type']).toBe('testVnf')
1149
1150     })
1151     it("shoukd clear vnf data ", () => {
1152         component.clearVnfcData()
1153         expect(component.Sample['vnfc-instance']).toBe('1')
1154     })
1155     it("shoudl showUpload", () => {
1156         component.uploadTypes = [
1157             {
1158                 value: 'Reference Data',
1159                 display: 'Sample Json Param File'
1160             },
1161             {
1162                 value: 'Mapping Data',
1163                 display: 'Sample Json Param File'
1164             }
1165         ]
1166         component.showUpload()
1167
1168         expect(component.selectedUploadType).toBe('Reference Data')
1169     })
1170     it("set vm instance", () => {
1171
1172         component.referenceDataObject.vm = [
1173             {
1174                 'vm-instance': 1
1175             }
1176         ]
1177         component.setVmInstance(0)
1178         expect(component.referenceDataObject.vm[0]['vm-instance']).toBe(1)
1179
1180     })
1181     it("set vnfc type", () => {
1182        // component.setVnfcType("test")
1183        //    expect(component.Sample['vnfc-type']).toBe("test");
1184     })
1185     it("getChange", () => {
1186        // component.getChange("vnfType")
1187         // expect(component.referenceDataObject.scope['vnfc-type']).toBe("");
1188     })
1189     it("idChange", () => {
1190         component.idChange(null, { valid: true })
1191         component.oldAction = "Configure"
1192         expect(component.actionChanged).toBeFalsy()
1193     })
1194     it("idChange", () => {
1195         component.oldAction = "Configure"
1196         component.oldtemplateIdentifier = "id1"
1197         component.templateIdentifier = "id1"
1198         component.idChange(null, { valid: true })
1199         expect(component.actionChanged).toBe(false)
1200     })
1201     it('Should test deviceProtocolChange method', () => {
1202         let spy = spyOn(BuildDesignComponent.prototype, 'getRefData');
1203         let refData = { "action": "Configure", "vnf-type": "test 1", "device-protocol": "ANSIBLE" };
1204         component.deviceProtocolChange();
1205         expect(spy).toHaveBeenCalled()
1206     });
1207
1208     it('should test uplaod function', () => {        
1209         let content = "Hello World";  
1210         let data = new Blob([content], { type: 'text/plain' });  
1211         let arrayOfBlob = new Array<Blob>();  
1212         arrayOfBlob.push(data);  
1213         let file = new File(arrayOfBlob, "Mock.XLS"); 
1214         let evnt = {target: {files: [file]}};
1215         component.upload(evnt);
1216     });
1217
1218     it('Should validatte fileChange method if file type is xml', async(() => {
1219         let reader = new FileReader();
1220         let content = "{data : 'Hello World'}";  
1221         let data = new Blob([content], { type: 'text/plain' });  
1222         let arrayOfBlob = new Array<Blob>();  
1223         arrayOfBlob.push(data);  
1224         let file = new File(arrayOfBlob, "Mock.XLS"); 
1225         let input = {target: {files: [file]}};
1226     
1227         component.fileChange(input);
1228       }));
1229
1230       it('should test validateVnfcName function with empty name value', ()=>{
1231         component.validateVnfcName('');
1232         expect(component.errorMessage).toBe('');
1233         expect(component.invalid).toBe(true);
1234     });
1235
1236     it('should test validateVnfcName function with name value leading and trailing white spaces', ()=>{
1237         component.validateVnfcName(' name ');
1238         expect(component.errorMessage).toBe('Leading and trailing spaces are not allowed');
1239         expect(component.invalid).toBe(true);
1240     });
1241
1242     it('should test validateVnfcName function with name including more than one space', ()=>{
1243         component.validateVnfcName('na  me');
1244         expect(component.errorMessage).toBe('More than one space is not allowed in VNFC Type');
1245         expect(component.invalid).toBe(true);
1246     });
1247
1248     it('should test validateVnfcName function with name length greated than 150', ()=>{
1249         component.validateVnfcName('namenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenanamenamnamenamename');
1250         expect(component.errorMessage).toBe('VNFC Type should be of minimum one character and maximum 50 character');
1251         expect(component.invalid).toBe(true);
1252     });
1253
1254     it('should test validateVnfcName function with valid name value', ()=>{
1255         component.validateVnfcName('name');
1256         expect(component.errorMessage).toBe('');
1257         expect(component.invalid).toBe(false);
1258     });
1259
1260     it('should test displayHideVnfc function', inject([MappingEditorService], (service: MappingEditorService) => {
1261         component.referenceDataObject = {
1262             action: 'ConfigScaleOut',
1263             'action-level': 'vnf',
1264             scope: {
1265                 'vnf-type': '',
1266                 'vnfc-type-list': ['346']
1267             },
1268             'template': 'Y',
1269             vm: [],
1270             'device-protocol': '',
1271             'user-name': '',
1272             'port-number': '',
1273             'artifact-list': []
1274         };
1275         service.newObject = { vnfc: false};
1276         component.displayHideVnfc();
1277         expect(component.vnfcIdentifier).toBe('346');
1278     }));
1279
1280     it('should test displayHideVnfc function vnfc is true', inject([MappingEditorService], (service: MappingEditorService) => {
1281         component.referenceDataObject = {
1282             action: 'ConfigScaleOut',
1283             'action-level': 'vnf',
1284             scope: {
1285                 'vnf-type': '',
1286                 'vnfc-type-list': ['346']
1287             },
1288             'template': 'Y',
1289             vm: [],
1290             'device-protocol': '',
1291             'user-name': '',
1292             'port-number': '',
1293             'artifact-list': []
1294         };
1295         service.newObject = { vnfc: true};
1296         component.displayHideVnfc();
1297         expect(component.vnfcIdentifier).toBe(true);
1298     }));
1299
1300     it('should test validateDataAndSaveToAppc function', ()=>{
1301         component.tempAllData = [{
1302             action: "Configure",
1303             scope: {
1304                 'vnf-type': "testVnf"
1305             }
1306         },{
1307             action: "StartApplication",
1308             scope: {
1309                 'vnf-type': "testVnf"
1310             }
1311         }
1312     ];
1313         component.actionChanged = true;
1314         component.currentAction = 'Config';
1315         let spy = spyOn(ReferenceDataformComponent.prototype, 'populateExistinAction');
1316         component.validateDataAndSaveToAppc(true, {}, {});
1317         expect(spy).toHaveBeenCalled();
1318         expect(component.referenceDataObject.action).toBe('Config')
1319     });
1320
1321
1322     // afterEach(function() {
1323     //     jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
1324     // });
1325 });