2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6 Modification Copyright (C) 2018 IBM.
7 ===================================================================
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
14 http://www.apache.org/licenses/LICENSE-2.0
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.
22 ============LICENSE_END============================================
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';
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';
46 describe('ReferenceDataformComponent', () => {
47 let component: ReferenceDataformComponent;
48 let fixture: ComponentFixture<ReferenceDataformComponent>;
49 let service: MockMappingService;
52 let httpMock: HttpUtilService
53 //mockingthe data for mappingEditorService
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" } },
64 "status": { code: "400", message: "success" }
71 class MockMappingService {
72 public latestAction; // = {"action":"Configure"}
81 downloadDataObject = {
94 referenceNameObjects = [
98 action: "StartApplication"
102 setTemplateMappingDataFromStore(data) {
111 setParamContent(data) {
114 setSessionParamData(data) {
118 saveLatestAction() { }
119 saveLatestIdentifier() { }
120 changeNavDownloadData() { }
121 changeNavAppData() { }
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],
132 FormsModule, RouterTestingModule, HttpModule, NgbModule.forRoot(),
133 SharedModule.forRoot()
136 BuildDesignComponent, {
137 provide: MappingEditorService,
138 useClass: MockMappingService
142 NotificationService, {
143 provide: HttpUtilService,
148 }).compileComponents();
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)
161 it('should create reference component', () => {
162 expect(component).toBeTruthy();
164 it('Should load data from mapping sevice', () => {
166 expect(component.tempAllData.length).toBe(2)
168 it('testing init method', () => {
170 expect(component.tempAllData.length).toBe(2)
173 it("should set app data from service", () => {
175 expect(component.appData)
179 it("should set download from service", () => {
181 expect(component.downloadData)
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('')
195 it("prepare reference method at vnf level", () => {
197 component.referenceDataObject = {
199 'action-level': 'vnf',
206 'device-protocol': '',
211 component.vnfcIdentifier = '346';
212 component.prepareReferenceObject();
213 expect(component.referenceDataObject['action-level']).toBe("vnf")
216 it("prepare reference method at vnfc level", () => {
218 component.referenceDataObject = {
220 'action-level': 'vnf',
223 'vnfc-type-list': ['346']
227 'device-protocol': '',
232 component.vnfcIdentifier = '346';
233 component.prepareReferenceObject();
234 expect(component.referenceDataObject['action-level']).toBe("vnf")
237 it("prepare reference method at vnf and vnfc level", () => {
239 component.referenceDataObject = {
240 action: 'starttApplication',
241 'action-level': 'vnf',
244 'vnfc-type-list': ['346']
248 'device-protocol': 'ANSIBLE',
253 component.vnfcIdentifier = '346';
254 component.prepareReferenceObject();
256 expect(component.referenceDataObject['action-level']).toBe("vnf")
258 //deviceprotocols netconf
259 it("prepare reference method testing with netconf", () => {
261 component.referenceDataObject = {
262 action: 'starttApplication',
263 'action-level': 'vnf',
266 'vnfc-type-list': ['346']
270 'device-protocol': 'NETCONF-XML',
275 component.vnfcIdentifier = '346';
276 component.prepareReferenceObject();
277 expect(component.referenceDataObject['action-level']).toBe("vnf")
280 it("prepare reference method at template id list", () => {
282 component.referenceDataObject = {
283 action: 'ConfigScaleOut',
284 'action-level': 'vnf',
287 'vnfc-type-list': ['346']
291 'device-protocol': 'NETCONF-XML',
297 component.vnfcIdentifier = '346';
298 component.referenceDataObject['template-id-list'] = ['id1', 'id2']
300 component.prepareReferenceObject();
302 expect(component.referenceDataObject['action-level']).toBe("vnf")
304 it("prepare reference method at vnfc level", () => {
306 component.referenceDataObject = {
307 action: 'startApplication',
308 'action-level': 'vnfc',
311 'vnfc-type-list': ['346']
315 'device-protocol': '',
320 component.vnfcIdentifier = '346';
321 component.prepareReferenceObject();
322 expect(component.referenceDataObject['action-level']).toBe("vnf")
324 it("prepare reference method at vnf level", () => {
326 component.referenceDataObject = {
327 action: 'ConfigScaleOut',
328 'action-level': 'vnf',
331 'vnfc-type-list': ['346']
335 'device-protocol': '',
340 component.vnfcIdentifier = '346';
341 component.prepareReferenceObject();
342 expect(component.referenceDataObject['action-level']).toBe("vnf")
345 it('should create reference component', () => {
347 expect(component).toBeTruthy();
349 it('configscaleout test', () => {
350 service.latestAction = {
351 action: 'ConfigScaleOut',
352 'action-level': 'vnf',
359 'device-protocol': '',
364 service.referenceNameObjects = [
368 action: "StartApplication"
372 expect(component.referenceDataObject.action).toBe("ConfigScaleOut");
375 it('configscalein test', () => {
376 service.latestAction = {
377 action: 'ConfigScaleIn',
378 'action-level': 'vnf',
385 'device-protocol': '',
390 service.referenceNameObjects = [
394 action: "StartApplication"
398 expect(component.referenceDataObject.action).toBe("ConfigScaleIn");
401 it('shoud add vms with template id when the action is configscaleout ', () => {
402 component.referenceDataObject = {
403 action: 'ConfigScaleOut',
404 'action-level': 'vnf',
407 'vnfc-type-list': ['346']
420 'device-protocol': '',
426 component.refernceScopeObj.from = "3"
429 expect(component.referenceDataObject.vm.length).toBe(4);
431 it('shoud add vms with template id when the action is configscalein ', () => {
432 component.referenceDataObject = {
433 action: 'ConfigScaleIn',
434 'action-level': 'vnf',
437 'vnfc-type-list': ['346']
450 'device-protocol': '',
456 component.refernceScopeObj.from = "3"
459 expect(component.referenceDataObject.vm.length).toBe(4);
461 it('shoud add vms with template id when the action is not configscaleout or configscalein', () => {
462 component.referenceDataObject = {
464 'action-level': 'vnf',
467 'vnfc-type-list': ['346']
480 'device-protocol': '',
486 component.refernceScopeObj.from = "3"
489 expect(component.referenceDataObject.vm[0]['template-id']).toBe(undefined);
492 it('testing ngdestroy', () => {
493 this.uploadFileName = 'testing'
494 component.ngOnDestroy()
495 expect(component.uploadedDataArray.length).toBe(0);
496 expect(component.uploadFileName).toBe('');
498 it('should validate numbers', () => {
500 component.numberValidation(1)
501 expect(component.numberOfVmTest).toBe(true);
505 it('should validate numbers if input is string', () => {
507 component.numberValidation('test')
508 expect(component.numberOfVmTest).toBe(false);
512 it('testing check if elements exixts in an array', () => {
514 let x = component.checkIfelementExistsInArray(2, [1, 2, 3])
515 expect(x).toBeTruthy();
518 it('should set action in session if type is action', () => {
520 component.updateSessionValues("test event for action", "action")
522 expect(sessionStorage.getItem('action')).toBe('test event for action');
524 it('should set action in session if type is vnfType', () => {
526 component.updateSessionValues("test event for vnfType", "vnfType")
528 expect(sessionStorage.getItem('vnfType')).toBe('test event for vnfType');
531 it('should add vnfs on to reference Object ', () => {
533 component.referenceDataObject = {
535 'action-level': 'vnf',
538 'vnfc-type-list': ['346']
551 'device-protocol': '',
557 component.addVnfcData(0)
559 expect(component.referenceDataObject.vm[0].vnfc.length).toBe(2);
562 it("should remove feature from the reference object ", () => {
563 component.referenceDataObject = {
565 'action-level': 'vnf',
568 'vnfc-type-list': ['346']
588 'device-protocol': '',
594 component.removeFeature(0, 0, 0)
596 expect(component.referenceDataObject.vm.length).toBe(1)
599 it("remove templateIds vm if action is confiogscaleout", () => {
600 component.referenceDataObject = {
601 action: 'ConfigScaleOut',
602 'action-level': 'vnf',
605 'vnfc-type-list': ['346']
610 "template-id": "klmklj",
614 "vnfc-instance": "1",
615 "vnfc-function-code": "klkl",
616 "ipaddress-v4-oam-vip": "",
617 "group-notation-type": "",
618 "group-notation-value": "",
623 "template-id": "test 12",
627 "vnfc-instance": "1",
628 "vnfc-function-code": "klkl",
629 "ipaddress-v4-oam-vip": "",
630 "group-notation-type": "",
631 "group-notation-value": "",
637 'device-protocol': '',
643 component.removeFeature(0, 0, 'test 12')
645 //expect(component.referenceDataObject.vm.length).toBe(2)
649 it("remove templateIds vm if action is configscalein", () => {
650 component.referenceDataObject = {
651 action: 'ConfigScaleIn',
652 'action-level': 'vnf',
655 'vnfc-type-list': ['346']
660 "template-id": "klmklj",
664 "vnfc-instance": "1",
665 "vnfc-function-code": "klkl",
666 "ipaddress-v4-oam-vip": "",
667 "group-notation-type": "",
668 "group-notation-value": "",
673 "template-id": "test 12",
677 "vnfc-instance": "1",
678 "vnfc-function-code": "klkl",
679 "ipaddress-v4-oam-vip": "",
680 "group-notation-type": "",
681 "group-notation-value": "",
687 'device-protocol': '',
693 component.removeFeature(0, 0, 'test 12')
695 //expect(component.referenceDataObject.vm.length).toBe(2)
699 it("should add capabilities", () => {
700 component.uploadedDataArray = [
703 component.addVmCapabilitiesData()
705 expect(component.tempAllData.length).toBe(3)
707 it("should add capabilities", () => {
708 service.latestAction = {
709 action: 'OpenStack Actions',
710 'action-level': 'vnf',
717 'device-protocol': '',
722 service.referenceNameObjects = [
726 action: "StartApplication"
730 component.prepareReferenceObject();
732 expect(component.referenceDataObject['action-level']).toBe("vnf")
735 it("should add capabilities", () => {
736 service.latestAction = {
737 action: 'OpenStack Actions',
738 'action-level': 'vnf',
745 'device-protocol': '',
751 component.referenceDataObject.action = "OpenStack Actions"
752 service.referenceNameObjects = [
756 action: "StartApplication"
760 component.prepareReferenceObject();
762 expect(component.referenceDataObject['action-level']).toBe("vnf")
765 it("should switch vms if action is configscaleout", () => {
767 component.currentAction = "ConfigScaleOut"
768 service.latestAction = {
769 action: 'OpenStack Actions',
770 'action-level': 'vnf',
777 'device-protocol': '',
782 service.referenceNameObjects = [
786 action: "StartApplication"
790 component.tempAllData = [
792 action: "ConfigScaleOut",
797 component.prepareReferenceObject();
799 expect(component.referenceDataObject.vm.length).toBe(2)
801 it("should switch vms if action is configscalein", () => {
803 component.currentAction = "ConfigScaleIn"
804 service.latestAction = {
805 action: 'OpenStack Actions',
806 'action-level': 'vnf',
813 'device-protocol': '',
818 service.referenceNameObjects = [
822 action: "StartApplication"
826 component.tempAllData = [
828 action: "ConfigScaleIn",
833 component.prepareReferenceObject();
835 expect(component.referenceDataObject.vm.length).toBe(2)
837 it("should switch vms if action is configscaleout", () => {
839 component.currentAction = "ConfigScaleOut"
840 service.latestAction = {
841 action: 'OpenStack Actions',
842 'action-level': 'vnf',
849 'device-protocol': '',
854 service.referenceNameObjects = [
858 action: "StartApplication"
862 component.tempAllData = [
864 action: "startAplicaton"
868 component.prepareReferenceObject();
870 expect(component.referenceDataObject.vm.length).toBe(0)
872 it("should switch vms if action is configscalein", () => {
874 component.currentAction = "ConfigScaleIn"
875 service.latestAction = {
876 action: 'OpenStack Actions',
877 'action-level': 'vnf',
884 'device-protocol': '',
889 service.referenceNameObjects = [
893 action: "StartApplication"
897 component.tempAllData = [
899 action: "startAplicaton"
903 component.prepareReferenceObject();
905 expect(component.referenceDataObject.vm.length).toBe(0)
907 it('shoud show template identifier when action is config scaleout', () => {
908 let data = 'ConfigScaleOut'
909 component.toggleIdentifier(data)
910 expect(component.isConfigScaleOut).toBe(true);
912 it('shoud show template identifier when action is configscalein', () => {
913 let data = 'ConfigScaleIn'
914 component.toggleIdentifier(data)
915 expect(component.isConfigScaleIn).toBe(true);
917 it('shoud show template identifier when action is not configscaleout', () => {
918 let data = 'startApplication'
919 component.toggleIdentifier(data)
920 expect(component.isConfigScaleOut).toBe(false);
922 it('shoud show template identifier when action is not configscalein', () => {
923 let data = 'startApplication'
924 component.toggleIdentifier(data)
925 expect(component.isConfigScaleIn).toBe(false);
928 it('Should call get artifact', () => {
930 service.referenceNameObjects = undefined
932 expect(component.tempAllData.length).toBe(2)
935 it('Should call get artifact', () => {
936 let spy = spyOn(BuildDesignComponent.prototype, 'getRefData');
937 let refData = { "action": "Configure", "vnf-type": "test 1", "device-protocol": "ANSIBLE" };
938 sessionStorage.setItem('updateParams', JSON.stringify({ vnf: 123, userID: 'testUser' }))
940 component.getArtifact()
942 expect(spy).toHaveBeenCalled();
943 expect(component.tempAllData.length).toBe(3);
946 it('Save file - should not process if action is null ', () => {
947 component.referenceDataObject.action = ""
948 let fileSaved = component.save({}, true)
949 expect(fileSaved).toBe(undefined)
951 it('Save file - should not process if device protocol is null ', () => {
952 component.referenceDataObject.action = "Configure"
953 component.referenceDataObject['device-protocol'] = ''
954 let fileSaved = component.save({}, true)
955 expect(fileSaved).toBe(undefined)
957 it('Save file - should not process if device protocol is null ', () => {
958 component.referenceDataObject.action = "Configure"
959 component.referenceDataObject['device-protocol'] = "test"
960 component.downloadData.template.templateData = { "test": "test" }
961 component.downloadData.template.nameValueData = { "test": "test" }
962 component.downloadData.pd.pdData = "test"
963 let fileSaved = component.save({}, true)
964 //expect(fileSaved).toBe(undefined)
967 it('Save to appc file - should not process if action is null ', () => {
968 component.referenceDataObject.action = "";
969 component.referenceDataObject.scope['vnf-type'] = '';
970 component.tempAllData = [{
973 'vnf-type': "testVnf"
976 action: "StartApplication",
978 'vnf-type': "testVnf"
982 let fileSaved = component.saveToAppc();
983 expect(fileSaved).toBe(undefined)
985 it('Save to app cfile - should not process if device protocol is null ', () => {
986 component.referenceDataObject['device-protocol'] = ""
987 component.referenceDataObject.action = "Configure"
988 component.tempAllData = [{
991 'vnf-type': "testVnf"
994 action: "StartApplication",
996 'vnf-type': "testVnf"
1000 let fileSaved = component.saveToAppc();
1001 expect(fileSaved).toBe(undefined)
1003 it('Save to appc file - should not process if device protocol is null ', () => {
1004 component.tempAllData = [
1006 action: "Configure",
1008 'vnf-type': "testVnf"
1012 component.referenceDataObject.action = "Configure"
1013 component.referenceDataObject['device-protocol'] = "test"
1014 component.appData.template.templateData = { "test": "test" }
1015 component.appData.template.nameValueData = { "test": "test" }
1016 component.appData.pd = { "test": "test" }
1017 component.actionChanged = true
1018 component.currentAction = "COnfigure"
1019 let fileSaved = component.saveToAppc();
1020 expect(fileSaved).toBe(undefined)
1023 // it('uploadfile ', () => { let files = { 0: {name:'foo.XLS', size:
1024 // 500001} }; var mockEVet = { target:{files:files} }
1025 // component.upload(mockEVet) //expect(fileSaved).toBe(undefined) })
1027 it('validateTempAllData() of reference dataform', () => {
1028 component.validateTempAllData()
1030 it('retriveFromAppc() of reference dataform', () => {
1031 sessionStorage.setItem('updateParams', JSON.stringify({ vnf: 123, userID: 'testUser' }))
1032 component.retriveFromAppc()
1033 expect(component.noCacheData).toBeFalsy()
1035 it('retriveFromAppc() of reference dataform for false', () => {
1036 sessionStorage.setItem('updateParams', 'undefined')
1037 component.retriveFromAppc()
1038 expect(component.noCacheData).toBeTruthy()
1041 it('resetGroupNotation() of reference dataform for false case', () => {
1042 component.resetGroupNotation()
1043 expect(component.disableGrpNotationValue).toBeFalsy()
1045 it('resetGroupNotation() of reference dataform for true case', () => {
1046 component.Sample['group-notation-type'] = "existing-group-name"
1047 component.resetGroupNotation()
1048 expect(component.disableGrpNotationValue).toBeTruthy()
1050 it('resetVms() of reference dataform', () => {
1051 component.resetVms()
1052 expect(component.referenceDataObject.vm).toBeNull
1055 it('Clear cache ', () => {
1056 component.clearCache()
1057 expect(component.downloadData.reference['name']).toBe(undefined);
1061 it('sholud reset group notification ', () => {
1062 component.Sample['group-notation-type'] = "existing-group-name"
1063 component.resetGroupNotation()
1064 expect(component.disableGrpNotationValue).toBe(true);
1067 it('sholud reset group notification if value does not match ', () => {
1068 component.Sample['group-notation-type'] = "123"
1069 component.resetGroupNotation()
1070 expect(component.disableGrpNotationValue).toBe(false);
1073 it('add identity group', () => {
1074 component.referenceDataObject['template-id-list'] = undefined
1075 component.templateId = "test"
1076 component.addToIdentDrp()
1077 expect(component.referenceDataObject['template-id-list'].length).toBe(1);
1081 it('add identity group', () => {
1083 component.resetVms()
1084 expect(component.referenceDataObject.vm.length).toBe(0);
1085 //expect(fileSaved).toBe(undefined)
1087 it('data modified', () => {
1089 component.dataModified()
1091 component.referenceDataObject.vm = [1, 2]
1092 expect(component.referenceDataObject.vm.length).toBe(2);
1093 //expect(fileSaved).toBe(undefined)
1096 it("should set values on action change ConfigScaleOut", () => {
1097 component.actionChange('ConfigScaleOut', { valid: true });
1099 expect(component.groupAnotationType.length).toBe(5)
1101 it("shpukd return false if its very first action", () => {
1102 component.actionChange(null,{ valid: true });
1104 expect(component.disableGrpNotationValue).toBe(false)
1106 it("sholud check no configuration actions", () => {
1107 component.tempAllData = [
1109 action: "Configure",
1111 'vnf-type': "testVnf"
1115 component.actionChange("Configure", { valid: true });
1117 expect(component.nonConfigureAction).toBe(false)
1120 it("should set values on action change when action is HealthCheck ", () => {
1121 component.populateExistinAction("HealthCheck")
1123 expect(component.deviceProtocols.length).toBe(4)
1126 it("should set values on action change when action is UpgradeBackout", () => {
1127 component.populateExistinAction("UpgradeBackout")
1129 expect(component.deviceProtocols.length).toBe(3)
1132 it("should set values on action change when action is OpenStack Actions", () => {
1133 component.populateExistinAction("OpenStack Actions")
1135 expect(component.deviceProtocols.length).toBe(2)
1138 it("should set values on action change when action is Configure", () => {
1139 component.tempAllData = [
1141 action: "Configure",
1143 'vnf-type': "testVnf"
1147 component.populateExistinAction("Configure")
1148 expect(component.referenceDataObject.scope['vnf-type']).toBe('testVnf')
1151 it("shoukd clear vnf data ", () => {
1152 component.clearVnfcData()
1153 expect(component.Sample['vnfc-instance']).toBe('1')
1155 it("shoudl showUpload", () => {
1156 component.uploadTypes = [
1158 value: 'Reference Data',
1159 display: 'Sample Json Param File'
1162 value: 'Mapping Data',
1163 display: 'Sample Json Param File'
1166 component.showUpload()
1168 expect(component.selectedUploadType).toBe('Reference Data')
1170 it("set vm instance", () => {
1172 component.referenceDataObject.vm = [
1177 component.setVmInstance(0)
1178 expect(component.referenceDataObject.vm[0]['vm-instance']).toBe(1)
1181 it("set vnfc type", () => {
1182 // component.setVnfcType("test")
1183 // expect(component.Sample['vnfc-type']).toBe("test");
1185 it("getChange", () => {
1186 // component.getChange("vnfType")
1187 // expect(component.referenceDataObject.scope['vnfc-type']).toBe("");
1189 it("idChange", () => {
1190 component.idChange(null, { valid: true })
1191 component.oldAction = "Configure"
1192 expect(component.actionChanged).toBeFalsy()
1194 it("idChange", () => {
1195 component.oldAction = "Configure"
1196 component.oldtemplateIdentifier = "id1"
1197 component.templateIdentifier = "id1"
1198 component.idChange(null, { valid: true })
1199 expect(component.actionChanged).toBe(false)
1201 it('Should test deviceProtocolChange method', () => {
1202 let spy = spyOn(BuildDesignComponent.prototype, 'getRefData');
1203 let refData = { "action": "Configure", "vnf-type": "test 1", "device-protocol": "ANSIBLE" };
1204 component.deviceProtocolChange();
1205 expect(spy).toHaveBeenCalled()
1208 it('should test uplaod function', () => {
1209 let content = "Hello World";
1210 let data = new Blob([content], { type: 'text/plain' });
1211 let arrayOfBlob = new Array<Blob>();
1212 arrayOfBlob.push(data);
1213 let file = new File(arrayOfBlob, "Mock.XLS");
1214 let evnt = {target: {files: [file]}};
1215 component.upload(evnt);
1218 it('Should validatte fileChange method if file type is xml', async(() => {
1219 let reader = new FileReader();
1220 let content = "{data : 'Hello World'}";
1221 let data = new Blob([content], { type: 'text/plain' });
1222 let arrayOfBlob = new Array<Blob>();
1223 arrayOfBlob.push(data);
1224 let file = new File(arrayOfBlob, "Mock.XLS");
1225 let input = {target: {files: [file]}};
1227 component.fileChange(input);
1230 it('should test validateVnfcName function with empty name value', ()=>{
1231 component.validateVnfcName('');
1232 expect(component.errorMessage).toBe('');
1233 expect(component.invalid).toBe(true);
1236 it('should test validateVnfcName function with name value leading and trailing white spaces', ()=>{
1237 component.validateVnfcName(' name ');
1238 expect(component.errorMessage).toBe('Leading and trailing spaces are not allowed');
1239 expect(component.invalid).toBe(true);
1242 it('should test validateVnfcName function with name including more than one space', ()=>{
1243 component.validateVnfcName('na me');
1244 expect(component.errorMessage).toBe('More than one space is not allowed in VNFC Type');
1245 expect(component.invalid).toBe(true);
1248 it('should test validateVnfcName function with name length greated than 150', ()=>{
1249 component.validateVnfcName('namenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenanamenamnamenamename');
1250 expect(component.errorMessage).toBe('VNFC Type should be of minimum one character and maximum 50 character');
1251 expect(component.invalid).toBe(true);
1254 it('should test validateVnfcName function with valid name value', ()=>{
1255 component.validateVnfcName('name');
1256 expect(component.errorMessage).toBe('');
1257 expect(component.invalid).toBe(false);
1260 it('should test displayHideVnfc function', inject([MappingEditorService], (service: MappingEditorService) => {
1261 component.referenceDataObject = {
1262 action: 'ConfigScaleOut',
1263 'action-level': 'vnf',
1266 'vnfc-type-list': ['346']
1270 'device-protocol': '',
1275 service.newObject = { vnfc: false};
1276 component.displayHideVnfc();
1277 expect(component.vnfcIdentifier).toBe('346');
1280 it('should test displayHideVnfc function vnfc is true', inject([MappingEditorService], (service: MappingEditorService) => {
1281 component.referenceDataObject = {
1282 action: 'ConfigScaleOut',
1283 'action-level': 'vnf',
1286 'vnfc-type-list': ['346']
1290 'device-protocol': '',
1295 service.newObject = { vnfc: true};
1296 component.displayHideVnfc();
1297 expect(component.vnfcIdentifier).toBe(true);
1300 it('should test validateDataAndSaveToAppc function', ()=>{
1301 component.tempAllData = [{
1302 action: "Configure",
1304 'vnf-type': "testVnf"
1307 action: "StartApplication",
1309 'vnf-type': "testVnf"
1313 component.actionChanged = true;
1314 component.currentAction = 'Config';
1315 let spy = spyOn(ReferenceDataformComponent.prototype, 'populateExistinAction');
1316 component.validateDataAndSaveToAppc(true, {}, {});
1317 expect(spy).toHaveBeenCalled();
1318 expect(component.referenceDataObject.action).toBe('Config')
1322 // afterEach(function() {
1323 // jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;