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