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