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");
376 it('shoud add vms with template id when the acti0on is configscaleout ', () => {
377 component.referenceDataObject = {
378 action: 'ConfigScaleOut',
379 'action-level': 'vnf',
382 'vnfc-type-list': ['346']
395 'device-protocol': '',
401 component.refernceScopeObj.from = "3"
404 expect(component.referenceDataObject.vm.length).toBe(4);
406 it('shoud add vms with template id when the action is not configscaleout', () => {
407 component.referenceDataObject = {
409 'action-level': 'vnf',
412 'vnfc-type-list': ['346']
425 'device-protocol': '',
431 component.refernceScopeObj.from = "3"
434 expect(component.referenceDataObject.vm[0]['template-id']).toBe(undefined);
437 it('testing ngdestroy', () => {
438 this.uploadFileName = 'testing'
439 component.ngOnDestroy()
440 expect(component.uploadedDataArray.length).toBe(0);
441 expect(component.uploadFileName).toBe('');
443 it('should validate numbers', () => {
445 component.numberValidation(1)
446 expect(component.numberOfVmTest).toBe(true);
450 it('should validate numbers if input is string', () => {
452 component.numberValidation('test')
453 expect(component.numberOfVmTest).toBe(false);
457 it('testing check if elements exixts in an array', () => {
459 let x = component.checkIfelementExistsInArray(2, [1, 2, 3])
460 expect(x).toBeTruthy();
463 it('should set action in session if type is action', () => {
465 component.updateSessionValues("test event for action", "action")
467 expect(sessionStorage.getItem('action')).toBe('test event for action');
469 it('should set action in session if type is vnfType', () => {
471 component.updateSessionValues("test event for vnfType", "vnfType")
473 expect(sessionStorage.getItem('vnfType')).toBe('test event for vnfType');
476 it('should add vnfs on to reference Object ', () => {
478 component.referenceDataObject = {
480 'action-level': 'vnf',
483 'vnfc-type-list': ['346']
496 'device-protocol': '',
502 component.addVnfcData(0)
504 expect(component.referenceDataObject.vm[0].vnfc.length).toBe(2);
507 it("should remove feature from the reference object ", () => {
508 component.referenceDataObject = {
510 'action-level': 'vnf',
513 'vnfc-type-list': ['346']
533 'device-protocol': '',
539 component.removeFeature(0, 0, 0)
541 expect(component.referenceDataObject.vm.length).toBe(1)
544 it("remove templateIds vm if action is confiogscaleout", () => {
545 component.referenceDataObject = {
546 action: 'ConfigScaleOut',
547 'action-level': 'vnf',
550 'vnfc-type-list': ['346']
555 "template-id": "klmklj",
559 "vnfc-instance": "1",
560 "vnfc-function-code": "klkl",
561 "ipaddress-v4-oam-vip": "",
562 "group-notation-type": "",
563 "group-notation-value": "",
568 "template-id": "test 12",
572 "vnfc-instance": "1",
573 "vnfc-function-code": "klkl",
574 "ipaddress-v4-oam-vip": "",
575 "group-notation-type": "",
576 "group-notation-value": "",
582 'device-protocol': '',
588 component.removeFeature(0, 0, 'test 12')
590 //expect(component.referenceDataObject.vm.length).toBe(2)
594 it("should add capabilities", () => {
595 component.uploadedDataArray = [
598 component.addVmCapabilitiesData()
600 expect(component.tempAllData.length).toBe(3)
602 it("should add capabilities", () => {
603 service.latestAction = {
604 action: 'OpenStack Actions',
605 'action-level': 'vnf',
612 'device-protocol': '',
617 service.referenceNameObjects = [
621 action: "StartApplication"
625 component.prepareReferenceObject();
627 expect(component.referenceDataObject['action-level']).toBe("vnf")
630 it("should add capabilities", () => {
631 service.latestAction = {
632 action: 'OpenStack Actions',
633 'action-level': 'vnf',
640 'device-protocol': '',
646 component.referenceDataObject.action = "OpenStack Actions"
647 service.referenceNameObjects = [
651 action: "StartApplication"
655 component.prepareReferenceObject();
657 expect(component.referenceDataObject['action-level']).toBe("vnf")
660 it("should switch vms if action is configscaleout", () => {
662 component.currentAction = "ConfigScaleOut"
663 service.latestAction = {
664 action: 'OpenStack Actions',
665 'action-level': 'vnf',
672 'device-protocol': '',
677 service.referenceNameObjects = [
681 action: "StartApplication"
685 component.tempAllData = [
687 action: "ConfigScaleOut",
692 component.prepareReferenceObject();
694 expect(component.referenceDataObject.vm.length).toBe(2)
696 it("should switch vms if action is configscaleout", () => {
698 component.currentAction = "ConfigScaleOut"
699 service.latestAction = {
700 action: 'OpenStack Actions',
701 'action-level': 'vnf',
708 'device-protocol': '',
713 service.referenceNameObjects = [
717 action: "StartApplication"
721 component.tempAllData = [
723 action: "startAplicaton"
727 component.prepareReferenceObject();
729 expect(component.referenceDataObject.vm.length).toBe(0)
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);
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);
742 it('Should call get artifact', () => {
744 service.referenceNameObjects = undefined
746 expect(component.tempAllData.length).toBe(2)
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' }))
754 component.getArtifact()
756 expect(spy).toHaveBeenCalled();
757 expect(component.tempAllData.length).toBe(3);
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)
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)
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)
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 = [{
787 'vnf-type': "testVnf"
790 action: "StartApplication",
792 'vnf-type': "testVnf"
796 let fileSaved = component.saveToAppc();
797 expect(fileSaved).toBe(undefined)
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 = [{
805 'vnf-type': "testVnf"
808 action: "StartApplication",
810 'vnf-type': "testVnf"
814 let fileSaved = component.saveToAppc();
815 expect(fileSaved).toBe(undefined)
817 it('Save to appc file - should not process if device protocol is null ', () => {
818 component.tempAllData = [
822 'vnf-type': "testVnf"
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)
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) })
841 it('downloadTemplate() of reference dataform', () => {
842 component.downloadTemplate()
845 it('downloadNameValue() of reference dataform', () => {
846 component.downloadNameValue()
849 it('downloadPd() of reference dataform', () => {
850 component.downloadPd()
852 it('validateTempAllData() of reference dataform', () => {
853 component.validateTempAllData()
855 it('retriveFromAppc() of reference dataform', () => {
856 sessionStorage.setItem('updateParams', JSON.stringify({ vnf: 123, userID: 'testUser' }))
857 component.retriveFromAppc()
858 expect(component.noCacheData).toBeFalsy()
860 it('retriveFromAppc() of reference dataform for false', () => {
861 sessionStorage.setItem('updateParams', 'undefined')
862 component.retriveFromAppc()
863 expect(component.noCacheData).toBeTruthy()
865 it(' cloneMessage(servermessage) of reference dataform', () => {
866 let servermessage = {
869 component.cloneMessage(servermessage)
872 it('resetGroupNotation() of reference dataform for false case', () => {
873 component.resetGroupNotation()
874 expect(component.disableGrpNotationValue).toBeFalsy()
876 it('resetGroupNotation() of reference dataform for true case', () => {
877 component.Sample['group-notation-type'] = "existing-group-name"
878 component.resetGroupNotation()
879 expect(component.disableGrpNotationValue).toBeTruthy()
881 it('resetVms() of reference dataform', () => {
883 expect(component.referenceDataObject.vm).toBeNull
886 it('Clear cache ', () => {
887 component.clearCache()
888 expect(component.downloadData.reference['name']).toBe(undefined);
892 it('sholud reset group notification ', () => {
893 component.Sample['group-notation-type'] = "existing-group-name"
894 component.resetGroupNotation()
895 expect(component.disableGrpNotationValue).toBe(true);
898 it('sholud reset group notification if value does not match ', () => {
899 component.Sample['group-notation-type'] = "123"
900 component.resetGroupNotation()
901 expect(component.disableGrpNotationValue).toBe(false);
904 it('add identity group', () => {
905 component.referenceDataObject['template-id-list'] = undefined
906 component.templateId = "test"
907 component.addToIdentDrp()
908 expect(component.referenceDataObject['template-id-list'].length).toBe(1);
912 it('add identity group', () => {
915 expect(component.referenceDataObject.vm.length).toBe(0);
916 //expect(fileSaved).toBe(undefined)
918 it('data modified', () => {
920 component.dataModified()
922 component.referenceDataObject.vm = [1, 2]
923 expect(component.referenceDataObject.vm.length).toBe(2);
924 //expect(fileSaved).toBe(undefined)
927 it("should set values on action change ConfigScaleOut", () => {
928 component.actionChange('ConfigScaleOut', { valid: true });
930 expect(component.groupAnotationType.length).toBe(5)
932 it("shpukd return false if its very first action", () => {
933 component.actionChange(null,{ valid: true });
935 expect(component.disableGrpNotationValue).toBe(false)
937 it("sholud check no configuration actions", () => {
938 component.tempAllData = [
942 'vnf-type': "testVnf"
946 component.actionChange("Configure", { valid: true });
948 expect(component.nonConfigureAction).toBe(false)
951 it("should set values on action change when action is HealthCheck ", () => {
952 component.populateExistinAction("HealthCheck")
954 expect(component.deviceProtocols.length).toBe(4)
957 it("should set values on action change when action is UpgradeBackout", () => {
958 component.populateExistinAction("UpgradeBackout")
960 expect(component.deviceProtocols.length).toBe(3)
963 it("should set values on action change when action is OpenStack Actions", () => {
964 component.populateExistinAction("OpenStack Actions")
966 expect(component.deviceProtocols.length).toBe(2)
969 it("should set values on action change when action is Configure", () => {
970 component.tempAllData = [
974 'vnf-type': "testVnf"
978 component.populateExistinAction("Configure")
979 expect(component.referenceDataObject.scope['vnf-type']).toBe('testVnf')
982 it("shoukd clear vnf data ", () => {
983 component.clearVnfcData()
984 expect(component.Sample['vnfc-instance']).toBe('1')
986 it("shoudl showUpload", () => {
987 component.uploadTypes = [
989 value: 'Reference Data',
990 display: 'Sample Json Param File'
993 value: 'Mapping Data',
994 display: 'Sample Json Param File'
997 component.showUpload()
999 expect(component.selectedUploadType).toBe('Reference Data')
1001 it("set vm instance", () => {
1003 component.referenceDataObject.vm = [
1008 component.setVmInstance(0)
1009 expect(component.referenceDataObject.vm[0]['vm-instance']).toBe(1)
1012 it("set vnfc type", () => {
1013 // component.setVnfcType("test")
1014 // expect(component.Sample['vnfc-type']).toBe("test");
1016 it("getChange", () => {
1017 // component.getChange("vnfType")
1018 // expect(component.referenceDataObject.scope['vnfc-type']).toBe("");
1020 it("idChange", () => {
1021 component.idChange(null, { valid: true })
1022 component.oldAction = "Configure"
1023 expect(component.actionChanged).toBeFalsy()
1025 it("idChange", () => {
1026 component.oldAction = "Configure"
1027 component.oldtemplateIdentifier = "id1"
1028 component.templateIdentifier = "id1"
1029 component.idChange(null, { valid: true })
1030 expect(component.actionChanged).toBe(false)
1032 it('Should test deviceProtocolChange method', () => {
1033 let spy = spyOn(BuildDesignComponent.prototype, 'getRefData');
1034 let refData = { "action": "Configure", "vnf-type": "test 1", "device-protocol": "ANSIBLE" };
1035 component.deviceProtocolChange();
1036 expect(spy).toHaveBeenCalled()
1039 it('should test uplaod function', () => {
1040 let content = "Hello World";
1041 let data = new Blob([content], { type: 'text/plain' });
1042 let arrayOfBlob = new Array<Blob>();
1043 arrayOfBlob.push(data);
1044 let file = new File(arrayOfBlob, "Mock.XLS");
1045 let evnt = {target: {files: [file]}};
1046 component.upload(evnt);
1049 it('Should validatte fileChange method if file type is xml', async(() => {
1050 let reader = new FileReader();
1051 let content = "{data : 'Hello World'}";
1052 let data = new Blob([content], { type: 'text/plain' });
1053 let arrayOfBlob = new Array<Blob>();
1054 arrayOfBlob.push(data);
1055 let file = new File(arrayOfBlob, "Mock.XLS");
1056 let input = {target: {files: [file]}};
1058 component.fileChange(input);
1061 it('should test validateVnfcName function with empty name value', ()=>{
1062 component.validateVnfcName('');
1063 expect(component.errorMessage).toBe('');
1064 expect(component.invalid).toBe(true);
1067 it('should test validateVnfcName function with name value leading and trailing white spaces', ()=>{
1068 component.validateVnfcName(' name ');
1069 expect(component.errorMessage).toBe('Leading and trailing spaces are not allowed');
1070 expect(component.invalid).toBe(true);
1073 it('should test validateVnfcName function with name including more than one space', ()=>{
1074 component.validateVnfcName('na me');
1075 expect(component.errorMessage).toBe('More than one space is not allowed in VNFC Type');
1076 expect(component.invalid).toBe(true);
1079 it('should test validateVnfcName function with name length greated than 150', ()=>{
1080 component.validateVnfcName('namenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenanamenamnamenamename');
1081 expect(component.errorMessage).toBe('VNFC Type should be of minimum one character and maximum 50 character');
1082 expect(component.invalid).toBe(true);
1085 it('should test validateVnfcName function with valid name value', ()=>{
1086 component.validateVnfcName('name');
1087 expect(component.errorMessage).toBe('');
1088 expect(component.invalid).toBe(false);
1091 it('should test displayHideVnfc function', inject([MappingEditorService], (service: MappingEditorService) => {
1092 component.referenceDataObject = {
1093 action: 'ConfigScaleOut',
1094 'action-level': 'vnf',
1097 'vnfc-type-list': ['346']
1101 'device-protocol': '',
1106 service.newObject = { vnfc: false};
1107 component.displayHideVnfc();
1108 expect(component.vnfcIdentifier).toBe('346');
1111 it('should test displayHideVnfc function vnfc is true', inject([MappingEditorService], (service: MappingEditorService) => {
1112 component.referenceDataObject = {
1113 action: 'ConfigScaleOut',
1114 'action-level': 'vnf',
1117 'vnfc-type-list': ['346']
1121 'device-protocol': '',
1126 service.newObject = { vnfc: true};
1127 component.displayHideVnfc();
1128 expect(component.vnfcIdentifier).toBe(true);
1131 it('should test validateDataAndSaveToAppc function', ()=>{
1132 component.tempAllData = [{
1133 action: "Configure",
1135 'vnf-type': "testVnf"
1138 action: "StartApplication",
1140 'vnf-type': "testVnf"
1144 component.actionChanged = true;
1145 component.currentAction = 'Config';
1146 let spy = spyOn(ReferenceDataformComponent.prototype, 'populateExistinAction');
1147 component.validateDataAndSaveToAppc(true, {}, {});
1148 expect(spy).toHaveBeenCalled();
1149 expect(component.referenceDataObject.action).toBe('Config')
1153 // afterEach(function() {
1154 // jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;