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