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;
51 let httpMock: HttpUtilService
52 //mockingthe data for mappingEditorService
61 "output": { "data": { "block": "{\"userID\":null,\"designInfo\":null,\"statusInfo\":null,\"artifactInfo\":[{\"artifact-content\":\" {\\\"reference_data\\\":[{\\\"action\\\":\\\"Configure\\\",\\\"action-level\\\":\\\"vnf\\\",\\\"scope\\\":{\\\"vnf-type\\\":\\\"Btesting123\\\",\\\"vnfc-type\\\":\\\"\\\"},\\\"template\\\":\\\"Y\\\",\\\"vm\\\":[],\\\"device-protocol\\\":\\\"ANSIBLE\\\",\\\"user-name\\\":\\\"root\\\",\\\"port-number\\\":\\\"830\\\",\\\"artifact-list\\\":[{\\\"artifact-name\\\":\\\"template_Configure_Btesting123_0.0.1V.json\\\",\\\"artifact-type\\\":\\\"config_template\\\"},{\\\"artifact-name\\\":\\\"pd_Configure_Btesting123_0.0.1V.yaml\\\",\\\"artifact-type\\\":\\\"parameter_definitions\\\"}],\\\"scopeType\\\":\\\"vnf-type\\\"},{\\\"action\\\":\\\"AllAction\\\",\\\"action-level\\\":\\\"vnf\\\",\\\"scope\\\":{\\\"vnf-type\\\":\\\"Btesting123\\\",\\\"vnfc-type\\\":\\\"\\\"},\\\"artifact-list\\\":[{\\\"artifact-name\\\":\\\"reference_AllAction_Btesting123_0.0.1V.json\\\",\\\"artifact-type\\\":\\\"reference_template\\\"}]},{\\\"action\\\":\\\"ConfigScaleOut\\\",\\\"action-level\\\":\\\"vnf\\\",\\\"scope\\\":{\\\"vnf-type\\\":\\\"Btesting123\\\",\\\"vnfc-type\\\":\\\"\\\"},\\\"template\\\":\\\"Y\\\",\\\"vm\\\":[{\\\"template-id\\\":\\\"id1\\\",\\\"vm-instance\\\":1,\\\"vnfc\\\":[{\\\"vnfc-instance\\\":\\\"1\\\",\\\"vnfc-function-code\\\":\\\"12313\\\",\\\"ipaddress-v4-oam-vip\\\":\\\"Y\\\",\\\"group-notation-type\\\":\\\"first-vnfc-name\\\",\\\"group-notation-value\\\":\\\"pair\\\",\\\"vnfc-type\\\":\\\"vDBE-V\\\"}]},{\\\"template-id\\\":\\\"id1\\\",\\\"vm-instance\\\":2,\\\"vnfc\\\":[{\\\"vnfc-instance\\\":\\\"1\\\",\\\"vnfc-function-code\\\":\\\"12313\\\",\\\"ipaddress-v4-oam-vip\\\":\\\"Y\\\",\\\"group-notation-type\\\":\\\"first-vnfc-name\\\",\\\"group-notation-value\\\":\\\"pair\\\",\\\"vnfc-type\\\":\\\"vDBE-V\\\"}]},{\\\"template-id\\\":\\\"id1\\\",\\\"vm-instance\\\":3,\\\"vnfc\\\":[{\\\"vnfc-instance\\\":\\\"1\\\",\\\"vnfc-function-code\\\":\\\"12313\\\",\\\"ipaddress-v4-oam-vip\\\":\\\"Y\\\",\\\"group-notation-type\\\":\\\"first-vnfc-name\\\",\\\"group-notation-value\\\":\\\"pair\\\",\\\"vnfc-type\\\":\\\"vDBE-V\\\"}]}],\\\"device-protocol\\\":\\\"CHEF\\\",\\\"user-name\\\":\\\"root\\\",\\\"port-number\\\":\\\"830\\\",\\\"artifact-list\\\":[{\\\"artifact-name\\\":\\\"template_ConfigScaleOut_Btesting123_0.0.1V_id1.json\\\",\\\"artifact-type\\\":\\\"config_template\\\"},{\\\"artifact-name\\\":\\\"pd_ConfigScaleOut_Btesting123_0.0.1V_id1.yaml\\\",\\\"artifact-type\\\":\\\"parameter_definitions\\\"}],\\\"scopeType\\\":\\\"vnf-type\\\",\\\"template-id-list\\\":[\\\"id1\\\"]}]}\"}]}", "requestId": "563507520187" }, "status": { "code": "400", "message": "success" } },
63 "status": { code: "400", message: "success" }
70 class MockMappingService {
71 public latestAction; // = {"action":"Configure"}
80 downloadDataObject = {
93 referenceNameObjects = [
97 action: "StartApplication"
101 setTemplateMappingDataFromStore(data) {
110 setParamContent(data) {
113 setSessionParamData(data) {
117 saveLatestAction() { }
118 saveLatestIdentifier() { }
119 changeNavDownloadData() { }
120 changeNavAppData() { }
122 class MockreferenceDataObject { }
123 beforeEach(async(() => {
124 TestBed.configureTestingModule({
125 declarations: [ReferenceDataformComponent],
126 schemas: [NO_ERRORS_SCHEMA],
129 FormsModule, RouterTestingModule, HttpModule, NgbModule.forRoot(),
130 SharedModule.forRoot()
133 BuildDesignComponent, {
134 provide: MappingEditorService,
135 useClass: MockMappingService
139 NotificationService, {
140 provide: HttpUtilService,
145 }).compileComponents();
149 fixture = TestBed.createComponent(ReferenceDataformComponent);
150 component = fixture.componentInstance;
151 // component = new ReferenceDataformComponent(service)
152 fixture.detectChanges();
153 service = TestBed.get(MappingEditorService)
154 httpMock = TestBed.get(HttpUtilService)
155 sessionStorage.setItem('vnfParams', JSON.stringify({ vnfType: "test", vnfcType: "testVnfcType" }));
156 // component = new ReferenceDataformComponent(service)
158 it('should create reference component', () => {
159 expect(component).toBeTruthy();
161 it('Should load data from mapping sevice', () => {
163 expect(component.tempAllData.length).toBe(2)
165 it('testing init method', () => {
167 expect(component.tempAllData.length).toBe(2)
170 it("should set app data from service", () => {
172 expect(component.appData)
176 it("should set download from service", () => {
178 expect(component.downloadData)
182 it('Should reset form', () => {
183 component.resetForm()
184 expect(component.referenceDataObject['device-protocol']).toBe('')
185 expect(component.referenceDataObject['action-level']).toBe('vnf')
186 expect(component.referenceDataObject.template).toBe('Y')
187 expect(component.referenceDataObject['user-name']).toBe('')
188 expect(component.Sample['vnfc-type']).toBe('')
189 expect(component.refernceScopeObj.sourceType).toBe('')
190 expect(component.referenceDataObject['port-number']).toBe('')
192 it("prepare reference method at vnf level", () => {
194 component.referenceDataObject = {
196 'action-level': 'vnf',
203 'device-protocol': '',
208 component.vnfcIdentifier = '346';
209 component.prepareReferenceObject();
210 expect(component.referenceDataObject['action-level']).toBe("vnf")
213 it("prepare reference method at vnfc level", () => {
215 component.referenceDataObject = {
217 'action-level': 'vnf',
220 'vnfc-type-list': ['346']
224 'device-protocol': '',
229 component.vnfcIdentifier = '346';
230 component.prepareReferenceObject();
231 expect(component.referenceDataObject['action-level']).toBe("vnf")
234 it("prepare reference method at vnf and vnfc level", () => {
236 component.referenceDataObject = {
237 action: 'starttApplication',
238 'action-level': 'vnf',
241 'vnfc-type-list': ['346']
245 'device-protocol': 'ANSIBLE',
250 component.vnfcIdentifier = '346';
251 component.prepareReferenceObject();
253 expect(component.referenceDataObject['action-level']).toBe("vnf")
255 //deviceprotocols netconf
256 it("prepare reference method testing with netconf", () => {
258 component.referenceDataObject = {
259 action: 'starttApplication',
260 'action-level': 'vnf',
263 'vnfc-type-list': ['346']
267 'device-protocol': 'NETCONF-XML',
272 component.vnfcIdentifier = '346';
273 component.prepareReferenceObject();
274 expect(component.referenceDataObject['action-level']).toBe("vnf")
277 it("prepare reference method at template id list", () => {
279 component.referenceDataObject = {
280 action: 'ConfigScaleOut',
281 'action-level': 'vnf',
284 'vnfc-type-list': ['346']
288 'device-protocol': 'NETCONF-XML',
294 component.vnfcIdentifier = '346';
295 component.referenceDataObject['template-id-list'] = ['id1', 'id2']
297 component.prepareReferenceObject();
299 expect(component.referenceDataObject['action-level']).toBe("vnf")
301 it("prepare reference method at vnfc level", () => {
303 component.referenceDataObject = {
304 action: 'startApplication',
305 'action-level': 'vnfc',
308 'vnfc-type-list': ['346']
312 'device-protocol': '',
317 component.vnfcIdentifier = '346';
318 component.prepareReferenceObject();
319 expect(component.referenceDataObject['action-level']).toBe("vnf")
321 it("prepare reference method at vnf level", () => {
323 component.referenceDataObject = {
324 action: 'ConfigScaleOut',
325 'action-level': 'vnf',
328 'vnfc-type-list': ['346']
332 'device-protocol': '',
337 component.vnfcIdentifier = '346';
338 component.prepareReferenceObject();
339 expect(component.referenceDataObject['action-level']).toBe("vnf")
342 it('should create reference component', () => {
344 expect(component).toBeTruthy();
346 it('configscaleout test', () => {
347 service.latestAction = {
348 action: 'ConfigScaleOut',
349 'action-level': 'vnf',
356 'device-protocol': '',
361 service.referenceNameObjects = [
365 action: "StartApplication"
369 expect(component.referenceDataObject.action).toBe("ConfigScaleOut");
373 it('shoud add vms with template id when the acti0on is configscaleout ', () => {
374 component.referenceDataObject = {
375 action: 'ConfigScaleOut',
376 'action-level': 'vnf',
379 'vnfc-type-list': ['346']
392 'device-protocol': '',
398 component.refernceScopeObj.from = "3"
401 expect(component.referenceDataObject.vm.length).toBe(4);
403 it('shoud add vms with template id when the action is not configscaleout', () => {
404 component.referenceDataObject = {
406 'action-level': 'vnf',
409 'vnfc-type-list': ['346']
422 'device-protocol': '',
428 component.refernceScopeObj.from = "3"
431 expect(component.referenceDataObject.vm[0]['template-id']).toBe(undefined);
434 it('testing ngdestroy', () => {
435 this.uploadFileName = 'testing'
436 component.ngOnDestroy()
437 expect(component.uploadedDataArray.length).toBe(0);
438 expect(component.uploadFileName).toBe('');
440 it('should validate numbers', () => {
442 component.numberValidation(1)
443 expect(component.numberOfVmTest).toBe(true);
447 it('should validate numbers if input is string', () => {
449 component.numberValidation('test')
450 expect(component.numberOfVmTest).toBe(false);
454 it('testing check if elements exixts in an array', () => {
456 let x = component.checkIfelementExistsInArray(2, [1, 2, 3])
457 expect(x).toBeTruthy();
460 it('should set action in session if type is action', () => {
462 component.updateSessionValues("test event for action", "action")
464 expect(sessionStorage.getItem('action')).toBe('test event for action');
466 it('should set action in session if type is vnfType', () => {
468 component.updateSessionValues("test event for vnfType", "vnfType")
470 expect(sessionStorage.getItem('vnfType')).toBe('test event for vnfType');
473 it('should add vnfs on to reference Object ', () => {
475 component.referenceDataObject = {
477 'action-level': 'vnf',
480 'vnfc-type-list': ['346']
493 'device-protocol': '',
499 component.addVnfcData(0)
501 expect(component.referenceDataObject.vm[0].vnfc.length).toBe(2);
504 it("should remove feature from the reference object ", () => {
505 component.referenceDataObject = {
507 'action-level': 'vnf',
510 'vnfc-type-list': ['346']
530 'device-protocol': '',
536 component.removeFeature(0, 0, 0)
538 expect(component.referenceDataObject.vm.length).toBe(1)
541 it("remove templateIds vm if action is confiogscaleout", () => {
542 component.referenceDataObject = {
543 action: 'ConfigScaleOut',
544 'action-level': 'vnf',
547 'vnfc-type-list': ['346']
552 "template-id": "klmklj",
556 "vnfc-instance": "1",
557 "vnfc-function-code": "klkl",
558 "ipaddress-v4-oam-vip": "",
559 "group-notation-type": "",
560 "group-notation-value": "",
565 "template-id": "test 12",
569 "vnfc-instance": "1",
570 "vnfc-function-code": "klkl",
571 "ipaddress-v4-oam-vip": "",
572 "group-notation-type": "",
573 "group-notation-value": "",
579 'device-protocol': '',
585 component.removeFeature(0, 0, 'test 12')
587 //expect(component.referenceDataObject.vm.length).toBe(2)
591 it("should add capabilities", () => {
592 component.uploadedDataArray = [
595 component.addVmCapabilitiesData()
597 expect(component.tempAllData.length).toBe(3)
599 it("should add capabilities", () => {
600 service.latestAction = {
601 action: 'OpenStack Actions',
602 'action-level': 'vnf',
609 'device-protocol': '',
614 service.referenceNameObjects = [
618 action: "StartApplication"
622 component.prepareReferenceObject();
624 expect(component.referenceDataObject['action-level']).toBe("vnf")
627 it("should add capabilities", () => {
628 service.latestAction = {
629 action: 'OpenStack Actions',
630 'action-level': 'vnf',
637 'device-protocol': '',
643 component.referenceDataObject.action = "OpenStack Actions"
644 service.referenceNameObjects = [
648 action: "StartApplication"
652 component.prepareReferenceObject();
654 expect(component.referenceDataObject['action-level']).toBe("vnf")
657 it("should switch vms if action is configscaleout", () => {
659 component.currentAction = "ConfigScaleOut"
660 service.latestAction = {
661 action: 'OpenStack Actions',
662 'action-level': 'vnf',
669 'device-protocol': '',
674 service.referenceNameObjects = [
678 action: "StartApplication"
682 component.tempAllData = [
684 action: "ConfigScaleOut",
689 component.prepareReferenceObject();
691 expect(component.referenceDataObject.vm.length).toBe(2)
693 it("should switch vms if action is configscaleout", () => {
695 component.currentAction = "ConfigScaleOut"
696 service.latestAction = {
697 action: 'OpenStack Actions',
698 'action-level': 'vnf',
705 'device-protocol': '',
710 service.referenceNameObjects = [
714 action: "StartApplication"
718 component.tempAllData = [
720 action: "startAplicaton"
724 component.prepareReferenceObject();
726 expect(component.referenceDataObject.vm.length).toBe(0)
728 it('shoud show template identifier when action is config scaleout', () => {
729 let data = 'ConfigScaleOut'
730 component.toggleIdentifier(data)
731 expect(component.isConfigScaleOut).toBe(true);
733 it('shoud show template identifier when action is config scaleout', () => {
734 let data = 'startApplication'
735 component.toggleIdentifier(data)
736 expect(component.isConfigScaleOut).toBe(false);
739 it('Should call get artifact', () => {
741 service.referenceNameObjects = undefined
743 expect(component.tempAllData.length).toBe(2)
746 it('Should call get artifact', () => {
747 let spy = spyOn(BuildDesignComponent.prototype, 'getRefData');
748 let refData = { "action": "Configure", "vnf-type": "test 1", "device-protocol": "ANSIBLE" };
749 sessionStorage.setItem('updateParams', JSON.stringify({ vnf: 123, userID: 'testUser' }))
751 component.getArtifact()
753 expect(spy).toHaveBeenCalled();
754 expect(component.tempAllData.length).toBe(3);
757 it('Save file - should not process if action is null ', () => {
758 component.referenceDataObject.action = ""
759 let fileSaved = component.save({}, true)
760 expect(fileSaved).toBe(undefined)
762 it('Save file - should not process if device protocol is null ', () => {
763 component.referenceDataObject.action = "Configure"
764 component.referenceDataObject['device-protocol'] = ''
765 let fileSaved = component.save({}, true)
766 expect(fileSaved).toBe(undefined)
768 it('Save file - should not process if device protocol is null ', () => {
769 component.referenceDataObject.action = "Configure"
770 component.referenceDataObject['device-protocol'] = "test"
771 component.downloadData.template.templateData = { "test": "test" }
772 component.downloadData.template.nameValueData = { "test": "test" }
773 component.downloadData.pd.pdData = "test"
774 let fileSaved = component.save({}, true)
775 //expect(fileSaved).toBe(undefined)
778 it('Save to appc file - should not process if action is null ', () => {
779 component.referenceDataObject.action = "";
780 component.referenceDataObject.scope['vnf-type'] = '';
781 component.tempAllData = [{
784 'vnf-type': "testVnf"
787 action: "StartApplication",
789 'vnf-type': "testVnf"
793 let fileSaved = component.saveToAppc();
794 expect(fileSaved).toBe(undefined)
796 it('Save to app cfile - should not process if device protocol is null ', () => {
797 component.referenceDataObject['device-protocol'] = ""
798 component.referenceDataObject.action = "Configure"
799 component.tempAllData = [{
802 'vnf-type': "testVnf"
805 action: "StartApplication",
807 'vnf-type': "testVnf"
811 let fileSaved = component.saveToAppc();
812 expect(fileSaved).toBe(undefined)
814 it('Save to appc file - should not process if device protocol is null ', () => {
815 component.tempAllData = [
819 'vnf-type': "testVnf"
823 component.referenceDataObject.action = "Configure"
824 component.referenceDataObject['device-protocol'] = "test"
825 component.appData.template.templateData = { "test": "test" }
826 component.appData.template.nameValueData = { "test": "test" }
827 component.appData.pd = { "test": "test" }
828 component.actionChanged = true
829 component.currentAction = "COnfigure"
830 let fileSaved = component.saveToAppc();
831 expect(fileSaved).toBe(undefined)
834 // it('uploadfile ', () => { let files = { 0: {name:'foo.XLS', size:
835 // 500001} }; var mockEVet = { target:{files:files} }
836 // component.upload(mockEVet) //expect(fileSaved).toBe(undefined) })
838 it('downloadTemplate() of reference dataform', () => {
839 component.downloadTemplate()
842 it('downloadNameValue() of reference dataform', () => {
843 component.downloadNameValue()
846 it('downloadPd() of reference dataform', () => {
847 component.downloadPd()
849 it('validateTempAllData() of reference dataform', () => {
850 component.validateTempAllData()
852 it('retriveFromAppc() of reference dataform', () => {
853 sessionStorage.setItem('updateParams', JSON.stringify({ vnf: 123, userID: 'testUser' }))
854 component.retriveFromAppc()
855 expect(component.noCacheData).toBeFalsy()
857 it('retriveFromAppc() of reference dataform for false', () => {
858 sessionStorage.setItem('updateParams', 'undefined')
859 component.retriveFromAppc()
860 expect(component.noCacheData).toBeTruthy()
862 it(' cloneMessage(servermessage) of reference dataform', () => {
863 let servermessage = {
866 component.cloneMessage(servermessage)
869 it('resetGroupNotation() of reference dataform for false case', () => {
870 component.resetGroupNotation()
871 expect(component.disableGrpNotationValue).toBeFalsy()
873 it('resetGroupNotation() of reference dataform for true case', () => {
874 component.Sample['group-notation-type'] = "existing-group-name"
875 component.resetGroupNotation()
876 expect(component.disableGrpNotationValue).toBeTruthy()
878 it('resetVms() of reference dataform', () => {
880 expect(component.referenceDataObject.vm).toBeNull
883 it('Clear cache ', () => {
884 component.clearCache()
885 expect(component.downloadData.reference['name']).toBe(undefined);
889 it('sholud reset group notification ', () => {
890 component.Sample['group-notation-type'] = "existing-group-name"
891 component.resetGroupNotation()
892 expect(component.disableGrpNotationValue).toBe(true);
895 it('sholud reset group notification if value does not match ', () => {
896 component.Sample['group-notation-type'] = "123"
897 component.resetGroupNotation()
898 expect(component.disableGrpNotationValue).toBe(false);
901 it('add identity group', () => {
902 component.referenceDataObject['template-id-list'] = undefined
903 component.templateId = "test"
904 component.addToIdentDrp()
905 expect(component.referenceDataObject['template-id-list'].length).toBe(1);
909 it('add identity group', () => {
912 expect(component.referenceDataObject.vm.length).toBe(0);
913 //expect(fileSaved).toBe(undefined)
915 it('data modified', () => {
917 component.dataModified()
919 component.referenceDataObject.vm = [1, 2]
920 expect(component.referenceDataObject.vm.length).toBe(2);
921 //expect(fileSaved).toBe(undefined)
924 it("should set values on action change ConfigScaleOut", () => {
925 component.actionChange('ConfigScaleOut', { valid: true });
927 expect(component.groupAnotationType.length).toBe(5)
929 it("shpukd return false if its very first action", () => {
930 component.actionChange(null,{ valid: true });
932 expect(component.disableGrpNotationValue).toBe(false)
934 it("sholud check no configuration actions", () => {
935 component.tempAllData = [
939 'vnf-type': "testVnf"
943 component.actionChange("Configure", { valid: true });
945 expect(component.nonConfigureAction).toBe(false)
948 it("should set values on action change when action is HealthCheck ", () => {
949 component.populateExistinAction("HealthCheck")
951 expect(component.deviceProtocols.length).toBe(4)
954 it("should set values on action change when action is UpgradeBackout", () => {
955 component.populateExistinAction("UpgradeBackout")
957 expect(component.deviceProtocols.length).toBe(3)
960 it("should set values on action change when action is OpenStack Actions", () => {
961 component.populateExistinAction("OpenStack Actions")
963 expect(component.deviceProtocols.length).toBe(2)
966 it("should set values on action change when action is Configure", () => {
967 component.tempAllData = [
971 'vnf-type': "testVnf"
975 component.populateExistinAction("Configure")
976 expect(component.referenceDataObject.scope['vnf-type']).toBe('testVnf')
979 it("shoukd clear vnf data ", () => {
980 component.clearVnfcData()
981 expect(component.Sample['vnfc-instance']).toBe('1')
983 it("shoudl showUpload", () => {
984 component.uploadTypes = [
986 value: 'Reference Data',
987 display: 'Sample Json Param File'
990 value: 'Mapping Data',
991 display: 'Sample Json Param File'
994 component.showUpload()
996 expect(component.selectedUploadType).toBe('Reference Data')
998 it("set vm instance", () => {
1000 component.referenceDataObject.vm = [
1005 component.setVmInstance(0)
1006 expect(component.referenceDataObject.vm[0]['vm-instance']).toBe(1)
1009 it("set vnfc type", () => {
1010 // component.setVnfcType("test")
1011 // expect(component.Sample['vnfc-type']).toBe("test");
1013 it("getChange", () => {
1014 // component.getChange("vnfType")
1015 // expect(component.referenceDataObject.scope['vnfc-type']).toBe("");
1017 it("idChange", () => {
1018 component.idChange(null, { valid: true })
1019 component.oldAction = "Configure"
1020 expect(component.actionChanged).toBeFalsy()
1022 it("idChange", () => {
1023 component.oldAction = "Configure"
1024 component.oldtemplateIdentifier = "id1"
1025 component.templateIdentifier = "id1"
1026 component.idChange(null, { valid: true })
1027 expect(component.actionChanged).toBe(false)
1029 it('Should test deviceProtocolChange method', () => {
1030 let spy = spyOn(BuildDesignComponent.prototype, 'getRefData');
1031 let refData = { "action": "Configure", "vnf-type": "test 1", "device-protocol": "ANSIBLE" };
1032 component.deviceProtocolChange();
1033 expect(spy).toHaveBeenCalled()
1036 it('should test uplaod function', () => {
1037 let content = "Hello World";
1038 let data = new Blob([content], { type: 'text/plain' });
1039 let arrayOfBlob = new Array<Blob>();
1040 arrayOfBlob.push(data);
1041 let file = new File(arrayOfBlob, "Mock.XLS");
1042 let evnt = {target: {files: [file]}};
1043 component.upload(evnt);
1046 it('Should validatte fileChange method if file type is xml', async(() => {
1047 let reader = new FileReader();
1048 let content = "{data : 'Hello World'}";
1049 let data = new Blob([content], { type: 'text/plain' });
1050 let arrayOfBlob = new Array<Blob>();
1051 arrayOfBlob.push(data);
1052 let file = new File(arrayOfBlob, "Mock.XLS");
1053 let input = {target: {files: [file]}};
1055 component.fileChange(input);
1058 it('should test validateVnfcName function with empty name value', ()=>{
1059 component.validateVnfcName('');
1060 expect(component.errorMessage).toBe('');
1061 expect(component.invalid).toBe(true);
1064 it('should test validateVnfcName function with name value leading and trailing white spaces', ()=>{
1065 component.validateVnfcName(' name ');
1066 expect(component.errorMessage).toBe('Leading and trailing spaces are not allowed');
1067 expect(component.invalid).toBe(true);
1070 it('should test validateVnfcName function with name including more than one space', ()=>{
1071 component.validateVnfcName('na me');
1072 expect(component.errorMessage).toBe('More than one space is not allowed in VNFC Type');
1073 expect(component.invalid).toBe(true);
1076 it('should test validateVnfcName function with name length greated than 150', ()=>{
1077 component.validateVnfcName('namenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenanamenamnamenamename');
1078 expect(component.errorMessage).toBe('VNFC Type should be of minimum one character and maximum 50 character');
1079 expect(component.invalid).toBe(true);
1082 it('should test validateVnfcName function with valid name value', ()=>{
1083 component.validateVnfcName('name');
1084 expect(component.errorMessage).toBe('');
1085 expect(component.invalid).toBe(false);