reference-dataform- added test case
[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
51     let httpMock: HttpUtilService
52     //mockingthe data for mappingEditorService
53
54     class HttpMock {
55         post(req) {
56
57             return Observable.of(
58
59
60                 {
61                     "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" } },
62
63                     "status": { code: "400", message: "success" }
64                 }
65
66
67             )
68         }
69     }
70     class MockMappingService {
71         public latestAction; // = {"action":"Configure"}
72         appDataObject = {
73             reference: {},
74             template: {
75                 templateData: {},
76                 nameValueData: {}
77             },
78             pd: {}
79         };
80         downloadDataObject = {
81             reference: {},
82             template: {
83                 templateData: {},
84                 nameValueData: {},
85                 templateFileName: '',
86                 nameValueFileName: ''
87             },
88             pd: {
89                 pdData: '',
90                 pdFileName: ''
91             }
92         }
93         referenceNameObjects = [
94             {
95                 action: "Configure"
96             }, {
97                 action: "StartApplication"
98             }
99         ]
100
101         setTemplateMappingDataFromStore(data) {
102             return "test"
103         }
104         getReferenceList() {
105             return ["test data"]
106         }
107         changeNav() {
108             return "test data"
109         }
110         setParamContent(data) {
111             return "test"
112         }
113         setSessionParamData(data) {
114             return "test"
115         }
116
117         saveLatestAction() { }
118         saveLatestIdentifier() { }
119         changeNavDownloadData() { }
120         changeNavAppData() { }
121     }
122     class MockreferenceDataObject { }
123     beforeEach(async(() => {
124         TestBed.configureTestingModule({
125             declarations: [ReferenceDataformComponent],
126             schemas: [NO_ERRORS_SCHEMA],
127             imports: [
128
129                 FormsModule, RouterTestingModule, HttpModule, NgbModule.forRoot(),
130                 SharedModule.forRoot()
131             ],
132             providers: [
133                 BuildDesignComponent, {
134                     provide: MappingEditorService,
135                     useClass: MockMappingService
136                 },
137                 ParamShareService,
138                 DialogService,
139                 NotificationService, {
140                     provide: HttpUtilService,
141                     useClass: HttpMock
142                 }
143
144             ]
145         }).compileComponents();
146     }));
147     beforeEach(() => {
148
149         fixture = TestBed.createComponent(ReferenceDataformComponent);
150         component = fixture.componentInstance;
151         //  component = new ReferenceDataformComponent(service)
152         fixture.detectChanges();
153         service = TestBed.get(MappingEditorService)
154         httpMock = TestBed.get(HttpUtilService)
155         sessionStorage.setItem('vnfParams', JSON.stringify({ vnfType: "test", vnfcType: "testVnfcType" }));
156         // component = new ReferenceDataformComponent(service)
157     });
158     it('should create reference component', () => {
159         expect(component).toBeTruthy();
160     });
161     it('Should load data from mapping sevice', () => {
162         component.ngOnInit()
163         expect(component.tempAllData.length).toBe(2)
164     })
165     it('testing init method', () => {
166         component.ngOnInit()
167         expect(component.tempAllData.length).toBe(2)
168     })
169
170     it("should set app data from service", () => {
171         component.ngOnInit()
172         expect(component.appData)
173             .not
174             .toBe(undefined)
175     })
176     it("should set download from service", () => {
177         component.ngOnInit()
178         expect(component.downloadData)
179             .not
180             .toBe(undefined)
181     })
182     it('Should reset form', () => {
183         component.resetForm()
184         expect(component.referenceDataObject['device-protocol']).toBe('')
185         expect(component.referenceDataObject['action-level']).toBe('vnf')
186         expect(component.referenceDataObject.template).toBe('Y')
187         expect(component.referenceDataObject['user-name']).toBe('')
188         expect(component.Sample['vnfc-type']).toBe('')
189         expect(component.refernceScopeObj.sourceType).toBe('')
190         expect(component.referenceDataObject['port-number']).toBe('')
191     })
192     it("prepare reference method at vnf level", () => {
193
194         component.referenceDataObject = {
195             action: 'Configure',
196             'action-level': 'vnf',
197             scope: {
198                 'vnf-type': '',
199                 'vnfc-type-list': []
200             },
201             'template': 'Y',
202             vm: [],
203             'device-protocol': '',
204             'user-name': '',
205             'port-number': '',
206             'artifact-list': []
207         };
208         component.vnfcIdentifier = '346';
209         component.prepareReferenceObject();
210         expect(component.referenceDataObject['action-level']).toBe("vnf")
211     })
212
213     it("prepare reference method at vnfc level", () => {
214
215         component.referenceDataObject = {
216             action: 'Configure',
217             'action-level': 'vnf',
218             scope: {
219                 'vnf-type': '123',
220                 'vnfc-type-list': ['346']
221             },
222             'template': 'Y',
223             vm: [],
224             'device-protocol': '',
225             'user-name': '',
226             'port-number': '',
227             'artifact-list': []
228         }
229         component.vnfcIdentifier = '346';
230         component.prepareReferenceObject();
231         expect(component.referenceDataObject['action-level']).toBe("vnf")
232     })
233
234     it("prepare reference method at vnf and vnfc level", () => {
235
236         component.referenceDataObject = {
237             action: 'starttApplication',
238             'action-level': 'vnf',
239             scope: {
240                 'vnf-type': '123',
241                 'vnfc-type-list': ['346']
242             },
243             'template': 'Y',
244             vm: [],
245             'device-protocol': 'ANSIBLE',
246             'user-name': '',
247             'port-number': '',
248             'artifact-list': []
249         };
250         component.vnfcIdentifier = '346';
251         component.prepareReferenceObject();
252
253         expect(component.referenceDataObject['action-level']).toBe("vnf")
254     })
255     //deviceprotocols netconf
256     it("prepare reference method testing with netconf", () => {
257
258         component.referenceDataObject = {
259             action: 'starttApplication',
260             'action-level': 'vnf',
261             scope: {
262                 'vnf-type': '123',
263                 'vnfc-type-list': ['346']
264             },
265             'template': 'Y',
266             vm: [],
267             'device-protocol': 'NETCONF-XML',
268             'user-name': '',
269             'port-number': '',
270             'artifact-list': []
271         }
272         component.vnfcIdentifier = '346';
273         component.prepareReferenceObject();
274         expect(component.referenceDataObject['action-level']).toBe("vnf")
275     })
276     //template id list
277     it("prepare reference method at template id list", () => {
278
279         component.referenceDataObject = {
280             action: 'ConfigScaleOut',
281             'action-level': 'vnf',
282             scope: {
283                 'vnf-type': '123',
284                 'vnfc-type-list': ['346']
285             },
286             'template': 'Y',
287             vm: [],
288             'device-protocol': 'NETCONF-XML',
289             'user-name': '',
290             'port-number': '',
291             'artifact-list': []
292
293         }
294         component.vnfcIdentifier = '346';
295         component.referenceDataObject['template-id-list'] = ['id1', 'id2']
296
297         component.prepareReferenceObject();
298
299         expect(component.referenceDataObject['action-level']).toBe("vnf")
300     })
301     it("prepare reference method at vnfc level", () => {
302
303         component.referenceDataObject = {
304             action: 'startApplication',
305             'action-level': 'vnfc',
306             scope: {
307                 'vnf-type': '',
308                 'vnfc-type-list': ['346']
309             },
310             'template': 'Y',
311             vm: [],
312             'device-protocol': '',
313             'user-name': '',
314             'port-number': '',
315             'artifact-list': []
316         };
317         component.vnfcIdentifier = '346';
318         component.prepareReferenceObject();
319         expect(component.referenceDataObject['action-level']).toBe("vnf")
320     })
321     it("prepare reference method at vnf level", () => {
322
323         component.referenceDataObject = {
324             action: 'ConfigScaleOut',
325             'action-level': 'vnf',
326             scope: {
327                 'vnf-type': '',
328                 'vnfc-type-list': ['346']
329             },
330             'template': 'Y',
331             vm: [],
332             'device-protocol': '',
333             'user-name': '',
334             'port-number': '',
335             'artifact-list': []
336         };
337         component.vnfcIdentifier = '346';
338         component.prepareReferenceObject();
339         expect(component.referenceDataObject['action-level']).toBe("vnf")
340     })
341
342     it('should create reference component', () => {
343
344         expect(component).toBeTruthy();
345     });
346     it('configscaleout test', () => {
347         service.latestAction = {
348             action: 'ConfigScaleOut',
349             'action-level': 'vnf',
350             scope: {
351                 'vnf-type': '',
352                 'vnfc-type': ''
353             },
354             'template': 'Y',
355             vm: [],
356             'device-protocol': '',
357             'user-name': '',
358             'port-number': '',
359             'artifact-list': []
360         }
361         service.referenceNameObjects = [
362             {
363                 action: "Configure"
364             }, {
365                 action: "StartApplication"
366             }
367         ]
368         component.ngOnInit()
369         expect(component.referenceDataObject.action).toBe("ConfigScaleOut");
370
371     });
372
373     it('shoud add vms with template id when the acti0on is configscaleout ', () => {
374         component.referenceDataObject = {
375             action: 'ConfigScaleOut',
376             'action-level': 'vnf',
377             scope: {
378                 'vnf-type': '',
379                 'vnfc-type-list': ['346']
380             },
381             'template': 'Y',
382             vm: [
383                 {
384                     vnfc: [
385                         {
386                             test: "123"
387                         }
388                     ]
389
390                 }
391             ],
392             'device-protocol': '',
393             'user-name': '',
394             'port-number': '',
395             'artifact-list': []
396         }
397
398         component.refernceScopeObj.from = "3"
399         // let arr = [1, 2];
400         component.addVms()
401         expect(component.referenceDataObject.vm.length).toBe(4);
402     });
403     it('shoud add vms with template id when the action is not configscaleout', () => {
404         component.referenceDataObject = {
405             action: 'Config',
406             'action-level': 'vnf',
407             scope: {
408                 'vnf-type': '',
409                 'vnfc-type-list': ['346']
410             },
411             'template': 'Y',
412             vm: [
413                 {
414                     vnfc: [
415                         {
416                             test: "123"
417                         }
418                     ]
419
420                 }
421             ],
422             'device-protocol': '',
423             'user-name': '',
424             'port-number': '',
425             'artifact-list': []
426         }
427
428         component.refernceScopeObj.from = "3"
429         // let arr = [1, 2];
430         component.addVms()
431         expect(component.referenceDataObject.vm[0]['template-id']).toBe(undefined);
432     });
433
434     it('testing ngdestroy', () => {
435         this.uploadFileName = 'testing'
436         component.ngOnDestroy()
437         expect(component.uploadedDataArray.length).toBe(0);
438         expect(component.uploadFileName).toBe('');
439     });
440     it('should validate numbers', () => {
441
442         component.numberValidation(1)
443         expect(component.numberOfVmTest).toBe(true);
444
445     });
446
447     it('should validate numbers if input is string', () => {
448
449         component.numberValidation('test')
450         expect(component.numberOfVmTest).toBe(false);
451
452     });
453
454     it('testing check if elements exixts in an array', () => {
455
456         let x = component.checkIfelementExistsInArray(2, [1, 2, 3])
457         expect(x).toBeTruthy();
458     });
459
460     it('should set action in session if type is action', () => {
461
462         component.updateSessionValues("test event for action", "action")
463
464         expect(sessionStorage.getItem('action')).toBe('test event for action');
465     });
466     it('should set action in session if type is vnfType', () => {
467
468         component.updateSessionValues("test event for vnfType", "vnfType")
469
470         expect(sessionStorage.getItem('vnfType')).toBe('test event for vnfType');
471     });
472
473     it('should add vnfs on to reference Object ', () => {
474
475         component.referenceDataObject = {
476             action: '',
477             'action-level': 'vnf',
478             scope: {
479                 'vnf-type': '',
480                 'vnfc-type-list': ['346']
481             },
482             'template': 'Y',
483             vm: [
484                 {
485                     vnfc: [
486                         {
487                             test: "123"
488                         }
489                     ]
490
491                 }
492             ],
493             'device-protocol': '',
494             'user-name': '',
495             'port-number': '',
496             'artifact-list': []
497         };
498
499         component.addVnfcData(0)
500
501         expect(component.referenceDataObject.vm[0].vnfc.length).toBe(2);
502     });
503
504     it("should remove feature from the reference object ", () => {
505         component.referenceDataObject = {
506             action: 'Configure',
507             'action-level': 'vnf',
508             scope: {
509                 'vnf-type': '',
510                 'vnfc-type-list': ['346']
511             },
512             'template': 'Y',
513             vm: [
514                 {
515                     vnfc: [
516                         {
517                             test: "123"
518                         }
519                     ]
520
521                 }, {
522                     vnfc: [
523                         {
524                             test: "123"
525                         }
526                     ]
527
528                 }
529             ],
530             'device-protocol': '',
531             'user-name': '',
532             'port-number': '',
533             'artifact-list': []
534         };
535
536         component.removeFeature(0, 0, 0)
537
538         expect(component.referenceDataObject.vm.length).toBe(1)
539     })
540
541     it("remove templateIds vm if action is confiogscaleout", () => {
542         component.referenceDataObject = {
543             action: 'ConfigScaleOut',
544             'action-level': 'vnf',
545             scope: {
546                 'vnf-type': '',
547                 'vnfc-type-list': ['346']
548             },
549             'template': 'Y',
550             "vm": [
551                 {
552                     "template-id": "klmklj",
553                     "vm-instance": 1,
554                     "vnfc": [
555                         {
556                             "vnfc-instance": "1",
557                             "vnfc-function-code": "klkl",
558                             "ipaddress-v4-oam-vip": "",
559                             "group-notation-type": "",
560                             "group-notation-value": "",
561                             "vnfc-type": "nnk"
562                         }
563                     ]
564                 }, {
565                     "template-id": "test 12",
566                     "vm-instance": 2,
567                     "vnfc": [
568                         {
569                             "vnfc-instance": "1",
570                             "vnfc-function-code": "klkl",
571                             "ipaddress-v4-oam-vip": "",
572                             "group-notation-type": "",
573                             "group-notation-value": "",
574                             "vnfc-type": "nnk"
575                         }
576                     ]
577                 }
578             ],
579             'device-protocol': '',
580             'user-name': '',
581             'port-number': '',
582             'artifact-list': []
583         };
584
585         component.removeFeature(0, 0, 'test 12')
586
587         //expect(component.referenceDataObject.vm.length).toBe(2)
588
589     })
590
591     it("should add capabilities", () => {
592         component.uploadedDataArray = [
593             ['y', 'n']
594         ]
595         component.addVmCapabilitiesData()
596
597         expect(component.tempAllData.length).toBe(3)
598     })
599     it("should add capabilities", () => {
600         service.latestAction = {
601             action: 'OpenStack Actions',
602             'action-level': 'vnf',
603             scope: {
604                 'vnf-type': '',
605                 'vnfc-type': ''
606             },
607             'template': 'Y',
608             vm: [],
609             'device-protocol': '',
610             'user-name': '',
611             'port-number': '',
612             'artifact-list': []
613         }
614         service.referenceNameObjects = [
615             {
616                 action: "Configure"
617             }, {
618                 action: "StartApplication"
619             }
620         ]
621
622         component.prepareReferenceObject();
623
624         expect(component.referenceDataObject['action-level']).toBe("vnf")
625     })
626
627     it("should add capabilities", () => {
628         service.latestAction = {
629             action: 'OpenStack Actions',
630             'action-level': 'vnf',
631             scope: {
632                 'vnf-type': '',
633                 'vnfc-type': ''
634             },
635             'template': 'Y',
636             vm: [],
637             'device-protocol': '',
638             'user-name': '',
639             'port-number': '',
640             'artifact-list': []
641         }
642
643         component.referenceDataObject.action = "OpenStack Actions"
644         service.referenceNameObjects = [
645             {
646                 action: "Configure"
647             }, {
648                 action: "StartApplication"
649             }
650         ]
651
652         component.prepareReferenceObject();
653
654         expect(component.referenceDataObject['action-level']).toBe("vnf")
655     })
656
657     it("should switch vms if action is configscaleout", () => {
658
659         component.currentAction = "ConfigScaleOut"
660         service.latestAction = {
661             action: 'OpenStack Actions',
662             'action-level': 'vnf',
663             scope: {
664                 'vnf-type': '',
665                 'vnfc-type': ''
666             },
667             'template': 'Y',
668             vm: [],
669             'device-protocol': '',
670             'user-name': '',
671             'port-number': '',
672             'artifact-list': []
673         }
674         service.referenceNameObjects = [
675             {
676                 action: "Configure"
677             }, {
678                 action: "StartApplication"
679             }
680         ]
681
682         component.tempAllData = [
683             {
684                 action: "ConfigScaleOut",
685                 vm: [{}, {}]
686             }
687         ]
688
689         component.prepareReferenceObject();
690
691         expect(component.referenceDataObject.vm.length).toBe(2)
692     })
693     it("should switch vms if action is configscaleout", () => {
694
695         component.currentAction = "ConfigScaleOut"
696         service.latestAction = {
697             action: 'OpenStack Actions',
698             'action-level': 'vnf',
699             scope: {
700                 'vnf-type': '',
701                 'vnfc-type': ''
702             },
703             'template': 'Y',
704             vm: [],
705             'device-protocol': '',
706             'user-name': '',
707             'port-number': '',
708             'artifact-list': []
709         }
710         service.referenceNameObjects = [
711             {
712                 action: "Configure"
713             }, {
714                 action: "StartApplication"
715             }
716         ]
717
718         component.tempAllData = [
719             {
720                 action: "startAplicaton"
721             }
722         ]
723
724         component.prepareReferenceObject();
725
726         expect(component.referenceDataObject.vm.length).toBe(0)
727     })
728     it('shoud show template identifier when action is config scaleout', () => {
729         let data = 'ConfigScaleOut'
730         component.toggleIdentifier(data)
731         expect(component.isConfigScaleOut).toBe(true);
732     });
733     it('shoud show template identifier when action is config scaleout', () => {
734         let data = 'startApplication'
735         component.toggleIdentifier(data)
736         expect(component.isConfigScaleOut).toBe(false);
737     });
738
739     it('Should call get artifact', () => {
740
741         service.referenceNameObjects = undefined
742         component.ngOnInit()
743         expect(component.tempAllData.length).toBe(2)
744     })
745
746     it('Should call get artifact', () => {
747         let spy = spyOn(BuildDesignComponent.prototype, 'getRefData');
748         let refData = { "action": "Configure", "vnf-type": "test 1", "device-protocol": "ANSIBLE" };
749         sessionStorage.setItem('updateParams', JSON.stringify({ vnf: 123, userID: 'testUser' }))
750
751         component.getArtifact()
752
753         expect(spy).toHaveBeenCalled();
754         expect(component.tempAllData.length).toBe(3);
755     })
756
757     it('Save file - should not process if action is null ', () => {
758         component.referenceDataObject.action = ""
759         let fileSaved = component.save({}, true)
760         expect(fileSaved).toBe(undefined)
761     })
762     it('Save file - should not process if device protocol is null ', () => {
763         component.referenceDataObject.action = "Configure"
764         component.referenceDataObject['device-protocol'] = ''
765         let fileSaved = component.save({}, true)
766         expect(fileSaved).toBe(undefined)
767     })
768     it('Save file - should not process if device protocol is null ', () => {
769         component.referenceDataObject.action = "Configure"
770         component.referenceDataObject['device-protocol'] = "test"
771         component.downloadData.template.templateData = { "test": "test" }
772         component.downloadData.template.nameValueData = { "test": "test" }
773         component.downloadData.pd.pdData = "test"
774         let fileSaved = component.save({}, true)
775         //expect(fileSaved).toBe(undefined)
776     })
777
778     it('Save to appc file - should not process if action is null ', () => {
779         component.referenceDataObject.action = "";
780         component.referenceDataObject.scope['vnf-type'] = '';
781         component.tempAllData = [{
782             action: "Configure",
783             scope: {
784                 'vnf-type': "testVnf"
785             }
786         },{
787             action: "StartApplication",
788             scope: {
789                 'vnf-type': "testVnf"
790             }
791         }
792     ];
793         let fileSaved = component.saveToAppc();
794         expect(fileSaved).toBe(undefined)
795     })
796     it('Save to app cfile - should not process if device protocol is null ', () => {
797         component.referenceDataObject['device-protocol'] = ""
798         component.referenceDataObject.action = "Configure"
799         component.tempAllData = [{
800             action: "Configure",
801             scope: {
802                 'vnf-type': "testVnf"
803             }
804         },{
805             action: "StartApplication",
806             scope: {
807                 'vnf-type': "testVnf"
808             }
809         }
810     ];
811         let fileSaved = component.saveToAppc();
812         expect(fileSaved).toBe(undefined)
813     })
814     it('Save to appc file - should not process if device protocol is null ', () => {
815         component.tempAllData = [
816             {
817                 action: "Configure",
818                 scope: {
819                     'vnf-type': "testVnf"
820                 }
821             }
822         ]
823         component.referenceDataObject.action = "Configure"
824         component.referenceDataObject['device-protocol'] = "test"
825         component.appData.template.templateData = { "test": "test" }
826         component.appData.template.nameValueData = { "test": "test" }
827         component.appData.pd = { "test": "test" }
828         component.actionChanged = true
829         component.currentAction = "COnfigure"
830         let fileSaved = component.saveToAppc();
831         expect(fileSaved).toBe(undefined)
832     })
833
834     //   it('uploadfile  ', () => {  let    files = { 0: {name:'foo.XLS', size:
835     // 500001} };     var mockEVet = {         target:{files:files}     }
836     // component.upload(mockEVet)     //expect(fileSaved).toBe(undefined) })
837
838     it('downloadTemplate() of reference dataform', () => {
839         component.downloadTemplate()
840         expect
841     })
842     it('downloadNameValue() of reference dataform', () => {
843         component.downloadNameValue()
844     })
845
846     it('downloadPd() of reference dataform', () => {
847         component.downloadPd()
848     })
849     it('validateTempAllData() of reference dataform', () => {
850         component.validateTempAllData()
851     })
852     it('retriveFromAppc() of reference dataform', () => {
853         sessionStorage.setItem('updateParams', JSON.stringify({ vnf: 123, userID: 'testUser' }))
854         component.retriveFromAppc()
855         expect(component.noCacheData).toBeFalsy()
856     })
857     it('retriveFromAppc() of reference dataform for false', () => {
858         sessionStorage.setItem('updateParams', 'undefined')
859         component.retriveFromAppc()
860         expect(component.noCacheData).toBeTruthy()
861     })
862     it(' cloneMessage(servermessage) of reference dataform', () => {
863         let servermessage = {
864             test: "test"
865         }
866         component.cloneMessage(servermessage)
867     })
868
869     it('resetGroupNotation() of reference dataform for false case', () => {
870         component.resetGroupNotation()
871         expect(component.disableGrpNotationValue).toBeFalsy()
872     })
873     it('resetGroupNotation() of reference dataform for true case', () => {
874         component.Sample['group-notation-type'] = "existing-group-name"
875         component.resetGroupNotation()
876         expect(component.disableGrpNotationValue).toBeTruthy()
877     })
878     it('resetVms() of reference dataform', () => {
879         component.resetVms()
880         expect(component.referenceDataObject.vm).toBeNull
881     })
882
883     it('Clear cache ', () => {
884         component.clearCache()
885         expect(component.downloadData.reference['name']).toBe(undefined);
886
887     })
888
889     it('sholud reset group notification ', () => {
890         component.Sample['group-notation-type'] = "existing-group-name"
891         component.resetGroupNotation()
892         expect(component.disableGrpNotationValue).toBe(true);
893
894     })
895     it('sholud reset group notification if value does not match ', () => {
896         component.Sample['group-notation-type'] = "123"
897         component.resetGroupNotation()
898         expect(component.disableGrpNotationValue).toBe(false);
899
900     })
901     it('add identity group', () => {
902         component.referenceDataObject['template-id-list'] = undefined
903         component.templateId = "test"
904         component.addToIdentDrp()
905         expect(component.referenceDataObject['template-id-list'].length).toBe(1);
906
907     })
908
909     it('add identity group', () => {
910
911         component.resetVms()
912         expect(component.referenceDataObject.vm.length).toBe(0);
913         //expect(fileSaved).toBe(undefined)
914     })
915     it('data modified', () => {
916
917         component.dataModified()
918
919         component.referenceDataObject.vm = [1, 2]
920         expect(component.referenceDataObject.vm.length).toBe(2);
921         //expect(fileSaved).toBe(undefined)
922     })
923
924     it("should set values on action change ConfigScaleOut", () => {
925         component.actionChange('ConfigScaleOut', { valid: true });
926
927         expect(component.groupAnotationType.length).toBe(5)
928     })
929     it("shpukd return false if its very first action", () => {
930         component.actionChange(null,{ valid: true });
931
932         expect(component.disableGrpNotationValue).toBe(false)
933     })
934     it("sholud check no configuration actions", () => {
935         component.tempAllData = [
936             {
937                 action: "Configure",
938                 scope: {
939                     'vnf-type': "testVnf"
940                 }
941             }
942         ]
943         component.actionChange("Configure", { valid: true });
944
945         expect(component.nonConfigureAction).toBe(false)
946     })
947
948     it("should set values on action change when action is HealthCheck ", () => {
949         component.populateExistinAction("HealthCheck")
950
951         expect(component.deviceProtocols.length).toBe(4)
952
953     })
954     it("should set values on action change when action is UpgradeBackout", () => {
955         component.populateExistinAction("UpgradeBackout")
956
957         expect(component.deviceProtocols.length).toBe(3)
958
959     })
960     it("should set values on action change when action is OpenStack Actions", () => {
961         component.populateExistinAction("OpenStack Actions")
962
963         expect(component.deviceProtocols.length).toBe(2)
964
965     })
966     it("should set values on action change when action is Configure", () => {
967         component.tempAllData = [
968             {
969                 action: "Configure",
970                 scope: {
971                     'vnf-type': "testVnf"
972                 }
973             }
974         ]
975         component.populateExistinAction("Configure")
976         expect(component.referenceDataObject.scope['vnf-type']).toBe('testVnf')
977
978     })
979     it("shoukd clear vnf data ", () => {
980         component.clearVnfcData()
981         expect(component.Sample['vnfc-instance']).toBe('1')
982     })
983     it("shoudl showUpload", () => {
984         component.uploadTypes = [
985             {
986                 value: 'Reference Data',
987                 display: 'Sample Json Param File'
988             },
989             {
990                 value: 'Mapping Data',
991                 display: 'Sample Json Param File'
992             }
993         ]
994         component.showUpload()
995
996         expect(component.selectedUploadType).toBe('Reference Data')
997     })
998     it("set vm instance", () => {
999
1000         component.referenceDataObject.vm = [
1001             {
1002                 'vm-instance': 1
1003             }
1004         ]
1005         component.setVmInstance(0)
1006         expect(component.referenceDataObject.vm[0]['vm-instance']).toBe(1)
1007
1008     })
1009     it("set vnfc type", () => {
1010        // component.setVnfcType("test")
1011        //    expect(component.Sample['vnfc-type']).toBe("test");
1012     })
1013     it("getChange", () => {
1014        // component.getChange("vnfType")
1015         // expect(component.referenceDataObject.scope['vnfc-type']).toBe("");
1016     })
1017     it("idChange", () => {
1018         component.idChange(null, { valid: true })
1019         component.oldAction = "Configure"
1020         expect(component.actionChanged).toBeFalsy()
1021     })
1022     it("idChange", () => {
1023         component.oldAction = "Configure"
1024         component.oldtemplateIdentifier = "id1"
1025         component.templateIdentifier = "id1"
1026         component.idChange(null, { valid: true })
1027         expect(component.actionChanged).toBe(false)
1028     })
1029     it('Should test deviceProtocolChange method', () => {
1030         let spy = spyOn(BuildDesignComponent.prototype, 'getRefData');
1031         let refData = { "action": "Configure", "vnf-type": "test 1", "device-protocol": "ANSIBLE" };
1032         component.deviceProtocolChange();
1033         expect(spy).toHaveBeenCalled()
1034     });
1035
1036     it('should test uplaod function', () => {        
1037         let content = "Hello World";  
1038         let data = new Blob([content], { type: 'text/plain' });  
1039         let arrayOfBlob = new Array<Blob>();  
1040         arrayOfBlob.push(data);  
1041         let file = new File(arrayOfBlob, "Mock.XLS"); 
1042         let evnt = {target: {files: [file]}};
1043         component.upload(evnt);
1044     });
1045
1046     it('Should validatte fileChange method if file type is xml', async(() => {
1047         let reader = new FileReader();
1048         let content = "{data : 'Hello World'}";  
1049         let data = new Blob([content], { type: 'text/plain' });  
1050         let arrayOfBlob = new Array<Blob>();  
1051         arrayOfBlob.push(data);  
1052         let file = new File(arrayOfBlob, "Mock.XLS"); 
1053         let input = {target: {files: [file]}};
1054     
1055         component.fileChange(input);
1056       }));
1057
1058       it('should test validateVnfcName function with empty name value', ()=>{
1059         component.validateVnfcName('');
1060         expect(component.errorMessage).toBe('');
1061         expect(component.invalid).toBe(true);
1062     });
1063
1064     it('should test validateVnfcName function with name value leading and trailing white spaces', ()=>{
1065         component.validateVnfcName(' name ');
1066         expect(component.errorMessage).toBe('Leading and trailing spaces are not allowed');
1067         expect(component.invalid).toBe(true);
1068     });
1069
1070     it('should test validateVnfcName function with name including more than one space', ()=>{
1071         component.validateVnfcName('na  me');
1072         expect(component.errorMessage).toBe('More than one space is not allowed in VNFC Type');
1073         expect(component.invalid).toBe(true);
1074     });
1075
1076     it('should test validateVnfcName function with name length greated than 150', ()=>{
1077         component.validateVnfcName('namenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenanamenamnamenamename');
1078         expect(component.errorMessage).toBe('VNFC Type should be of minimum one character and maximum 50 character');
1079         expect(component.invalid).toBe(true);
1080     });
1081
1082     it('should test validateVnfcName function with valid name value', ()=>{
1083         component.validateVnfcName('name');
1084         expect(component.errorMessage).toBe('');
1085         expect(component.invalid).toBe(false);
1086     });
1087 });