fa8ed1a6cdd90577716d65ab080832105bf29e43
[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
376     it('shoud add vms with template id when the acti0on is configscaleout ', () => {
377         component.referenceDataObject = {
378             action: 'ConfigScaleOut',
379             'action-level': 'vnf',
380             scope: {
381                 'vnf-type': '',
382                 'vnfc-type-list': ['346']
383             },
384             'template': 'Y',
385             vm: [
386                 {
387                     vnfc: [
388                         {
389                             test: "123"
390                         }
391                     ]
392
393                 }
394             ],
395             'device-protocol': '',
396             'user-name': '',
397             'port-number': '',
398             'artifact-list': []
399         }
400
401         component.refernceScopeObj.from = "3"
402         // let arr = [1, 2];
403         component.addVms()
404         expect(component.referenceDataObject.vm.length).toBe(4);
405     });
406     it('shoud add vms with template id when the action is not configscaleout', () => {
407         component.referenceDataObject = {
408             action: 'Config',
409             'action-level': 'vnf',
410             scope: {
411                 'vnf-type': '',
412                 'vnfc-type-list': ['346']
413             },
414             'template': 'Y',
415             vm: [
416                 {
417                     vnfc: [
418                         {
419                             test: "123"
420                         }
421                     ]
422
423                 }
424             ],
425             'device-protocol': '',
426             'user-name': '',
427             'port-number': '',
428             'artifact-list': []
429         }
430
431         component.refernceScopeObj.from = "3"
432         // let arr = [1, 2];
433         component.addVms()
434         expect(component.referenceDataObject.vm[0]['template-id']).toBe(undefined);
435     });
436
437     it('testing ngdestroy', () => {
438         this.uploadFileName = 'testing'
439         component.ngOnDestroy()
440         expect(component.uploadedDataArray.length).toBe(0);
441         expect(component.uploadFileName).toBe('');
442     });
443     it('should validate numbers', () => {
444
445         component.numberValidation(1)
446         expect(component.numberOfVmTest).toBe(true);
447
448     });
449
450     it('should validate numbers if input is string', () => {
451
452         component.numberValidation('test')
453         expect(component.numberOfVmTest).toBe(false);
454
455     });
456
457     it('testing check if elements exixts in an array', () => {
458
459         let x = component.checkIfelementExistsInArray(2, [1, 2, 3])
460         expect(x).toBeTruthy();
461     });
462
463     it('should set action in session if type is action', () => {
464
465         component.updateSessionValues("test event for action", "action")
466
467         expect(sessionStorage.getItem('action')).toBe('test event for action');
468     });
469     it('should set action in session if type is vnfType', () => {
470
471         component.updateSessionValues("test event for vnfType", "vnfType")
472
473         expect(sessionStorage.getItem('vnfType')).toBe('test event for vnfType');
474     });
475
476     it('should add vnfs on to reference Object ', () => {
477
478         component.referenceDataObject = {
479             action: '',
480             'action-level': 'vnf',
481             scope: {
482                 'vnf-type': '',
483                 'vnfc-type-list': ['346']
484             },
485             'template': 'Y',
486             vm: [
487                 {
488                     vnfc: [
489                         {
490                             test: "123"
491                         }
492                     ]
493
494                 }
495             ],
496             'device-protocol': '',
497             'user-name': '',
498             'port-number': '',
499             'artifact-list': []
500         };
501
502         component.addVnfcData(0)
503
504         expect(component.referenceDataObject.vm[0].vnfc.length).toBe(2);
505     });
506
507     it("should remove feature from the reference object ", () => {
508         component.referenceDataObject = {
509             action: 'Configure',
510             'action-level': 'vnf',
511             scope: {
512                 'vnf-type': '',
513                 'vnfc-type-list': ['346']
514             },
515             'template': 'Y',
516             vm: [
517                 {
518                     vnfc: [
519                         {
520                             test: "123"
521                         }
522                     ]
523
524                 }, {
525                     vnfc: [
526                         {
527                             test: "123"
528                         }
529                     ]
530
531                 }
532             ],
533             'device-protocol': '',
534             'user-name': '',
535             'port-number': '',
536             'artifact-list': []
537         };
538
539         component.removeFeature(0, 0, 0)
540
541         expect(component.referenceDataObject.vm.length).toBe(1)
542     })
543
544     it("remove templateIds vm if action is confiogscaleout", () => {
545         component.referenceDataObject = {
546             action: 'ConfigScaleOut',
547             'action-level': 'vnf',
548             scope: {
549                 'vnf-type': '',
550                 'vnfc-type-list': ['346']
551             },
552             'template': 'Y',
553             "vm": [
554                 {
555                     "template-id": "klmklj",
556                     "vm-instance": 1,
557                     "vnfc": [
558                         {
559                             "vnfc-instance": "1",
560                             "vnfc-function-code": "klkl",
561                             "ipaddress-v4-oam-vip": "",
562                             "group-notation-type": "",
563                             "group-notation-value": "",
564                             "vnfc-type": "nnk"
565                         }
566                     ]
567                 }, {
568                     "template-id": "test 12",
569                     "vm-instance": 2,
570                     "vnfc": [
571                         {
572                             "vnfc-instance": "1",
573                             "vnfc-function-code": "klkl",
574                             "ipaddress-v4-oam-vip": "",
575                             "group-notation-type": "",
576                             "group-notation-value": "",
577                             "vnfc-type": "nnk"
578                         }
579                     ]
580                 }
581             ],
582             'device-protocol': '',
583             'user-name': '',
584             'port-number': '',
585             'artifact-list': []
586         };
587
588         component.removeFeature(0, 0, 'test 12')
589
590         //expect(component.referenceDataObject.vm.length).toBe(2)
591
592     })
593
594     it("should add capabilities", () => {
595         component.uploadedDataArray = [
596             ['y', 'n']
597         ]
598         component.addVmCapabilitiesData()
599
600         expect(component.tempAllData.length).toBe(3)
601     })
602     it("should add capabilities", () => {
603         service.latestAction = {
604             action: 'OpenStack Actions',
605             'action-level': 'vnf',
606             scope: {
607                 'vnf-type': '',
608                 'vnfc-type': ''
609             },
610             'template': 'Y',
611             vm: [],
612             'device-protocol': '',
613             'user-name': '',
614             'port-number': '',
615             'artifact-list': []
616         }
617         service.referenceNameObjects = [
618             {
619                 action: "Configure"
620             }, {
621                 action: "StartApplication"
622             }
623         ]
624
625         component.prepareReferenceObject();
626
627         expect(component.referenceDataObject['action-level']).toBe("vnf")
628     })
629
630     it("should add capabilities", () => {
631         service.latestAction = {
632             action: 'OpenStack Actions',
633             'action-level': 'vnf',
634             scope: {
635                 'vnf-type': '',
636                 'vnfc-type': ''
637             },
638             'template': 'Y',
639             vm: [],
640             'device-protocol': '',
641             'user-name': '',
642             'port-number': '',
643             'artifact-list': []
644         }
645
646         component.referenceDataObject.action = "OpenStack Actions"
647         service.referenceNameObjects = [
648             {
649                 action: "Configure"
650             }, {
651                 action: "StartApplication"
652             }
653         ]
654
655         component.prepareReferenceObject();
656
657         expect(component.referenceDataObject['action-level']).toBe("vnf")
658     })
659
660     it("should switch vms if action is configscaleout", () => {
661
662         component.currentAction = "ConfigScaleOut"
663         service.latestAction = {
664             action: 'OpenStack Actions',
665             'action-level': 'vnf',
666             scope: {
667                 'vnf-type': '',
668                 'vnfc-type': ''
669             },
670             'template': 'Y',
671             vm: [],
672             'device-protocol': '',
673             'user-name': '',
674             'port-number': '',
675             'artifact-list': []
676         }
677         service.referenceNameObjects = [
678             {
679                 action: "Configure"
680             }, {
681                 action: "StartApplication"
682             }
683         ]
684
685         component.tempAllData = [
686             {
687                 action: "ConfigScaleOut",
688                 vm: [{}, {}]
689             }
690         ]
691
692         component.prepareReferenceObject();
693
694         expect(component.referenceDataObject.vm.length).toBe(2)
695     })
696     it("should switch vms if action is configscaleout", () => {
697
698         component.currentAction = "ConfigScaleOut"
699         service.latestAction = {
700             action: 'OpenStack Actions',
701             'action-level': 'vnf',
702             scope: {
703                 'vnf-type': '',
704                 'vnfc-type': ''
705             },
706             'template': 'Y',
707             vm: [],
708             'device-protocol': '',
709             'user-name': '',
710             'port-number': '',
711             'artifact-list': []
712         }
713         service.referenceNameObjects = [
714             {
715                 action: "Configure"
716             }, {
717                 action: "StartApplication"
718             }
719         ]
720
721         component.tempAllData = [
722             {
723                 action: "startAplicaton"
724             }
725         ]
726
727         component.prepareReferenceObject();
728
729         expect(component.referenceDataObject.vm.length).toBe(0)
730     })
731     it('shoud show template identifier when action is config scaleout', () => {
732         let data = 'ConfigScaleOut'
733         component.toggleIdentifier(data)
734         expect(component.isConfigScaleOut).toBe(true);
735     });
736     it('shoud show template identifier when action is config scaleout', () => {
737         let data = 'startApplication'
738         component.toggleIdentifier(data)
739         expect(component.isConfigScaleOut).toBe(false);
740     });
741
742     it('Should call get artifact', () => {
743
744         service.referenceNameObjects = undefined
745         component.ngOnInit()
746         expect(component.tempAllData.length).toBe(2)
747     })
748
749     it('Should call get artifact', () => {
750         let spy = spyOn(BuildDesignComponent.prototype, 'getRefData');
751         let refData = { "action": "Configure", "vnf-type": "test 1", "device-protocol": "ANSIBLE" };
752         sessionStorage.setItem('updateParams', JSON.stringify({ vnf: 123, userID: 'testUser' }))
753
754         component.getArtifact()
755
756         expect(spy).toHaveBeenCalled();
757         expect(component.tempAllData.length).toBe(3);
758     })
759
760     it('Save file - should not process if action is null ', () => {
761         component.referenceDataObject.action = ""
762         let fileSaved = component.save({}, true)
763         expect(fileSaved).toBe(undefined)
764     })
765     it('Save file - should not process if device protocol is null ', () => {
766         component.referenceDataObject.action = "Configure"
767         component.referenceDataObject['device-protocol'] = ''
768         let fileSaved = component.save({}, true)
769         expect(fileSaved).toBe(undefined)
770     })
771     it('Save file - should not process if device protocol is null ', () => {
772         component.referenceDataObject.action = "Configure"
773         component.referenceDataObject['device-protocol'] = "test"
774         component.downloadData.template.templateData = { "test": "test" }
775         component.downloadData.template.nameValueData = { "test": "test" }
776         component.downloadData.pd.pdData = "test"
777         let fileSaved = component.save({}, true)
778         //expect(fileSaved).toBe(undefined)
779     })
780
781     it('Save to appc file - should not process if action is null ', () => {
782         component.referenceDataObject.action = "";
783         component.referenceDataObject.scope['vnf-type'] = '';
784         component.tempAllData = [{
785             action: "Configure",
786             scope: {
787                 'vnf-type': "testVnf"
788             }
789         },{
790             action: "StartApplication",
791             scope: {
792                 'vnf-type': "testVnf"
793             }
794         }
795     ];
796         let fileSaved = component.saveToAppc();
797         expect(fileSaved).toBe(undefined)
798     })
799     it('Save to app cfile - should not process if device protocol is null ', () => {
800         component.referenceDataObject['device-protocol'] = ""
801         component.referenceDataObject.action = "Configure"
802         component.tempAllData = [{
803             action: "Configure",
804             scope: {
805                 'vnf-type': "testVnf"
806             }
807         },{
808             action: "StartApplication",
809             scope: {
810                 'vnf-type': "testVnf"
811             }
812         }
813     ];
814         let fileSaved = component.saveToAppc();
815         expect(fileSaved).toBe(undefined)
816     })
817     it('Save to appc file - should not process if device protocol is null ', () => {
818         component.tempAllData = [
819             {
820                 action: "Configure",
821                 scope: {
822                     'vnf-type': "testVnf"
823                 }
824             }
825         ]
826         component.referenceDataObject.action = "Configure"
827         component.referenceDataObject['device-protocol'] = "test"
828         component.appData.template.templateData = { "test": "test" }
829         component.appData.template.nameValueData = { "test": "test" }
830         component.appData.pd = { "test": "test" }
831         component.actionChanged = true
832         component.currentAction = "COnfigure"
833         let fileSaved = component.saveToAppc();
834         expect(fileSaved).toBe(undefined)
835     })
836
837     //   it('uploadfile  ', () => {  let    files = { 0: {name:'foo.XLS', size:
838     // 500001} };     var mockEVet = {         target:{files:files}     }
839     // component.upload(mockEVet)     //expect(fileSaved).toBe(undefined) })
840
841     it('downloadTemplate() of reference dataform', () => {
842         component.downloadTemplate()
843         expect
844     })
845     it('downloadNameValue() of reference dataform', () => {
846         component.downloadNameValue()
847     })
848
849     it('downloadPd() of reference dataform', () => {
850         component.downloadPd()
851     })
852     it('validateTempAllData() of reference dataform', () => {
853         component.validateTempAllData()
854     })
855     it('retriveFromAppc() of reference dataform', () => {
856         sessionStorage.setItem('updateParams', JSON.stringify({ vnf: 123, userID: 'testUser' }))
857         component.retriveFromAppc()
858         expect(component.noCacheData).toBeFalsy()
859     })
860     it('retriveFromAppc() of reference dataform for false', () => {
861         sessionStorage.setItem('updateParams', 'undefined')
862         component.retriveFromAppc()
863         expect(component.noCacheData).toBeTruthy()
864     })
865     it(' cloneMessage(servermessage) of reference dataform', () => {
866         let servermessage = {
867             test: "test"
868         }
869         component.cloneMessage(servermessage)
870     })
871
872     it('resetGroupNotation() of reference dataform for false case', () => {
873         component.resetGroupNotation()
874         expect(component.disableGrpNotationValue).toBeFalsy()
875     })
876     it('resetGroupNotation() of reference dataform for true case', () => {
877         component.Sample['group-notation-type'] = "existing-group-name"
878         component.resetGroupNotation()
879         expect(component.disableGrpNotationValue).toBeTruthy()
880     })
881     it('resetVms() of reference dataform', () => {
882         component.resetVms()
883         expect(component.referenceDataObject.vm).toBeNull
884     })
885
886     it('Clear cache ', () => {
887         component.clearCache()
888         expect(component.downloadData.reference['name']).toBe(undefined);
889
890     })
891
892     it('sholud reset group notification ', () => {
893         component.Sample['group-notation-type'] = "existing-group-name"
894         component.resetGroupNotation()
895         expect(component.disableGrpNotationValue).toBe(true);
896
897     })
898     it('sholud reset group notification if value does not match ', () => {
899         component.Sample['group-notation-type'] = "123"
900         component.resetGroupNotation()
901         expect(component.disableGrpNotationValue).toBe(false);
902
903     })
904     it('add identity group', () => {
905         component.referenceDataObject['template-id-list'] = undefined
906         component.templateId = "test"
907         component.addToIdentDrp()
908         expect(component.referenceDataObject['template-id-list'].length).toBe(1);
909
910     })
911
912     it('add identity group', () => {
913
914         component.resetVms()
915         expect(component.referenceDataObject.vm.length).toBe(0);
916         //expect(fileSaved).toBe(undefined)
917     })
918     it('data modified', () => {
919
920         component.dataModified()
921
922         component.referenceDataObject.vm = [1, 2]
923         expect(component.referenceDataObject.vm.length).toBe(2);
924         //expect(fileSaved).toBe(undefined)
925     })
926
927     it("should set values on action change ConfigScaleOut", () => {
928         component.actionChange('ConfigScaleOut', { valid: true });
929
930         expect(component.groupAnotationType.length).toBe(5)
931     })
932     it("shpukd return false if its very first action", () => {
933         component.actionChange(null,{ valid: true });
934
935         expect(component.disableGrpNotationValue).toBe(false)
936     })
937     it("sholud check no configuration actions", () => {
938         component.tempAllData = [
939             {
940                 action: "Configure",
941                 scope: {
942                     'vnf-type': "testVnf"
943                 }
944             }
945         ]
946         component.actionChange("Configure", { valid: true });
947
948         expect(component.nonConfigureAction).toBe(false)
949     })
950
951     it("should set values on action change when action is HealthCheck ", () => {
952         component.populateExistinAction("HealthCheck")
953
954         expect(component.deviceProtocols.length).toBe(4)
955
956     })
957     it("should set values on action change when action is UpgradeBackout", () => {
958         component.populateExistinAction("UpgradeBackout")
959
960         expect(component.deviceProtocols.length).toBe(3)
961
962     })
963     it("should set values on action change when action is OpenStack Actions", () => {
964         component.populateExistinAction("OpenStack Actions")
965
966         expect(component.deviceProtocols.length).toBe(2)
967
968     })
969     it("should set values on action change when action is Configure", () => {
970         component.tempAllData = [
971             {
972                 action: "Configure",
973                 scope: {
974                     'vnf-type': "testVnf"
975                 }
976             }
977         ]
978         component.populateExistinAction("Configure")
979         expect(component.referenceDataObject.scope['vnf-type']).toBe('testVnf')
980
981     })
982     it("shoukd clear vnf data ", () => {
983         component.clearVnfcData()
984         expect(component.Sample['vnfc-instance']).toBe('1')
985     })
986     it("shoudl showUpload", () => {
987         component.uploadTypes = [
988             {
989                 value: 'Reference Data',
990                 display: 'Sample Json Param File'
991             },
992             {
993                 value: 'Mapping Data',
994                 display: 'Sample Json Param File'
995             }
996         ]
997         component.showUpload()
998
999         expect(component.selectedUploadType).toBe('Reference Data')
1000     })
1001     it("set vm instance", () => {
1002
1003         component.referenceDataObject.vm = [
1004             {
1005                 'vm-instance': 1
1006             }
1007         ]
1008         component.setVmInstance(0)
1009         expect(component.referenceDataObject.vm[0]['vm-instance']).toBe(1)
1010
1011     })
1012     it("set vnfc type", () => {
1013        // component.setVnfcType("test")
1014        //    expect(component.Sample['vnfc-type']).toBe("test");
1015     })
1016     it("getChange", () => {
1017        // component.getChange("vnfType")
1018         // expect(component.referenceDataObject.scope['vnfc-type']).toBe("");
1019     })
1020     it("idChange", () => {
1021         component.idChange(null, { valid: true })
1022         component.oldAction = "Configure"
1023         expect(component.actionChanged).toBeFalsy()
1024     })
1025     it("idChange", () => {
1026         component.oldAction = "Configure"
1027         component.oldtemplateIdentifier = "id1"
1028         component.templateIdentifier = "id1"
1029         component.idChange(null, { valid: true })
1030         expect(component.actionChanged).toBe(false)
1031     })
1032     it('Should test deviceProtocolChange method', () => {
1033         let spy = spyOn(BuildDesignComponent.prototype, 'getRefData');
1034         let refData = { "action": "Configure", "vnf-type": "test 1", "device-protocol": "ANSIBLE" };
1035         component.deviceProtocolChange();
1036         expect(spy).toHaveBeenCalled()
1037     });
1038
1039     it('should test uplaod function', () => {        
1040         let content = "Hello World";  
1041         let data = new Blob([content], { type: 'text/plain' });  
1042         let arrayOfBlob = new Array<Blob>();  
1043         arrayOfBlob.push(data);  
1044         let file = new File(arrayOfBlob, "Mock.XLS"); 
1045         let evnt = {target: {files: [file]}};
1046         component.upload(evnt);
1047     });
1048
1049     it('Should validatte fileChange method if file type is xml', async(() => {
1050         let reader = new FileReader();
1051         let content = "{data : 'Hello World'}";  
1052         let data = new Blob([content], { type: 'text/plain' });  
1053         let arrayOfBlob = new Array<Blob>();  
1054         arrayOfBlob.push(data);  
1055         let file = new File(arrayOfBlob, "Mock.XLS"); 
1056         let input = {target: {files: [file]}};
1057     
1058         component.fileChange(input);
1059       }));
1060
1061       it('should test validateVnfcName function with empty name value', ()=>{
1062         component.validateVnfcName('');
1063         expect(component.errorMessage).toBe('');
1064         expect(component.invalid).toBe(true);
1065     });
1066
1067     it('should test validateVnfcName function with name value leading and trailing white spaces', ()=>{
1068         component.validateVnfcName(' name ');
1069         expect(component.errorMessage).toBe('Leading and trailing spaces are not allowed');
1070         expect(component.invalid).toBe(true);
1071     });
1072
1073     it('should test validateVnfcName function with name including more than one space', ()=>{
1074         component.validateVnfcName('na  me');
1075         expect(component.errorMessage).toBe('More than one space is not allowed in VNFC Type');
1076         expect(component.invalid).toBe(true);
1077     });
1078
1079     it('should test validateVnfcName function with name length greated than 150', ()=>{
1080         component.validateVnfcName('namenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenanamenamnamenamename');
1081         expect(component.errorMessage).toBe('VNFC Type should be of minimum one character and maximum 50 character');
1082         expect(component.invalid).toBe(true);
1083     });
1084
1085     it('should test validateVnfcName function with valid name value', ()=>{
1086         component.validateVnfcName('name');
1087         expect(component.errorMessage).toBe('');
1088         expect(component.invalid).toBe(false);
1089     });
1090
1091     it('should test displayHideVnfc function', inject([MappingEditorService], (service: MappingEditorService) => {
1092         component.referenceDataObject = {
1093             action: 'ConfigScaleOut',
1094             'action-level': 'vnf',
1095             scope: {
1096                 'vnf-type': '',
1097                 'vnfc-type-list': ['346']
1098             },
1099             'template': 'Y',
1100             vm: [],
1101             'device-protocol': '',
1102             'user-name': '',
1103             'port-number': '',
1104             'artifact-list': []
1105         };
1106         service.newObject = { vnfc: false};
1107         component.displayHideVnfc();
1108         expect(component.vnfcIdentifier).toBe('346');
1109     }));
1110
1111     it('should test displayHideVnfc function vnfc is true', inject([MappingEditorService], (service: MappingEditorService) => {
1112         component.referenceDataObject = {
1113             action: 'ConfigScaleOut',
1114             'action-level': 'vnf',
1115             scope: {
1116                 'vnf-type': '',
1117                 'vnfc-type-list': ['346']
1118             },
1119             'template': 'Y',
1120             vm: [],
1121             'device-protocol': '',
1122             'user-name': '',
1123             'port-number': '',
1124             'artifact-list': []
1125         };
1126         service.newObject = { vnfc: true};
1127         component.displayHideVnfc();
1128         expect(component.vnfcIdentifier).toBe(true);
1129     }));
1130
1131     it('should test validateDataAndSaveToAppc function', ()=>{
1132         component.tempAllData = [{
1133             action: "Configure",
1134             scope: {
1135                 'vnf-type': "testVnf"
1136             }
1137         },{
1138             action: "StartApplication",
1139             scope: {
1140                 'vnf-type': "testVnf"
1141             }
1142         }
1143     ];
1144         component.actionChanged = true;
1145         component.currentAction = 'Config';
1146         let spy = spyOn(ReferenceDataformComponent.prototype, 'populateExistinAction');
1147         component.validateDataAndSaveToAppc(true, {}, {});
1148         expect(spy).toHaveBeenCalled();
1149         expect(component.referenceDataObject.action).toBe('Config')
1150     });
1151
1152
1153     // afterEach(function() {
1154     //     jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
1155     // });
1156 });