NodeInfo::getModel expects the instance-model
[vid.git] / vid-webpack-master / src / app / drawingBoard / service-planning / available-models-tree / available-models-tree.service.spec.ts
1 import {getTestBed, TestBed} from '@angular/core/testing';
2 import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
3 import {AvailableModelsTreeService} from './available-models-tree.service';
4 import {ServiceNodeTypes} from "../../../shared/models/ServiceNodeTypes";
5 import {DefaultDataGeneratorService} from "../../../shared/services/defaultDataServiceGenerator/default.data.generator.service";
6 import {MessageBoxService} from "../../../shared/components/messageBox/messageBox.service";
7 import {MessageBoxData} from "../../../shared/components/messageBox/messageBox.data";
8 import {SdcUiCommon} from "onap-ui-angular";
9 import {MockNgRedux, NgReduxTestingModule} from "@angular-redux/store/testing";
10 import {SharedTreeService} from "../objectsToTree/shared.tree.service";
11
12 describe('Available Models Tree Service', () => {
13
14   let injector;
15   let service: AvailableModelsTreeService;
16   let httpMock: HttpTestingController;
17   let sharedTreeService: SharedTreeService;
18
19   beforeAll(done => (async () => {
20     TestBed.configureTestingModule({
21       imports: [HttpClientTestingModule, NgReduxTestingModule],
22       providers: [AvailableModelsTreeService,
23         DefaultDataGeneratorService,
24         SharedTreeService,
25         MockNgRedux]
26     });
27     await TestBed.compileComponents();
28       injector = getTestBed();
29       service = injector.get(AvailableModelsTreeService);
30       httpMock = injector.get(HttpTestingController);
31       sharedTreeService = injector.get(SharedTreeService);
32   })().then(done).catch(done.fail));
33
34
35   test('addingAlertAddingNewVfModuleModal should open message modal', () => {
36     jest.spyOn(MessageBoxService.openModal, 'next');
37     service.addingAlertAddingNewVfModuleModal();
38
39     expect(MessageBoxService.openModal.next).toHaveBeenCalledWith(new MessageBoxData(
40       "Select a parent",  // modal title
41       "There are multiple instances on the right side that can contain this vf-module Please select the VNF instance, to add this vf-module to, on the right side and then click the + sign",
42       SdcUiCommon.ModalType.warning,
43       SdcUiCommon.ModalSize.medium,
44       [
45         {text: "Close", size: "medium", closeModal: true}
46       ]));
47   });
48
49
50
51   describe('#shouldOpenModalDialogOnAddInstance', () => {
52
53     test('should open popup on add instance', () => {
54       // add vnf should return true
55       let result = service.shouldOpenDialog(ServiceNodeTypes.VF, [], true);
56       expect(result).toBeTruthy();
57
58       //  add vfModule with user provided naming should return true
59       result = service.shouldOpenDialog(ServiceNodeTypes.VFmodule, [], false);
60       expect(result).toBeTruthy();
61
62       //  add vfModule with dynamicInputs without defaultValues should return true
63       result = service.shouldOpenDialog(ServiceNodeTypes.VFmodule, [{
64         id: '2017488_pasqualevpe0_vnf_config_template_version',
65         type: 'string',
66         name: '2017488_pasqualevpe0_vnf_config_template_version',
67         isRequired: true,
68         description: 'VPE Software Version'
69       }], true);
70       expect(result).toBeTruthy();
71
72       // add vfModule with dynamicInputs with defaultValues should return false
73       result = service.shouldOpenDialog(ServiceNodeTypes.VFmodule, [{
74         id: '2017488_pasqualevpe0_vnf_config_template_version',
75         type: 'string',
76         name: '2017488_pasqualevpe0_vnf_config_template_version',
77         value: '17.2',
78         isRequired: true,
79         description: 'VPE Software Version'
80       }], true);
81       expect(result).toBeFalsy();
82     });
83   });
84
85
86   test('shouldOpenVRFModal', () => {
87     const nodes = [{
88       "id": "dd024d73-9bd1-425d-9db5-476338d53433",
89       "modelCustomizationId": "dd024d73-9bd1-425d-9db5-476338d53433",
90       "modelVersionId": "9cac02be-2489-4374-888d-2863b4511a59",
91       "modelUniqueId": "dd024d73-9bd1-425d-9db5-476338d53433",
92       "name": "VRF Entry Configuration 0",
93       "tooltip": "VRF",
94       "type": "VRF",
95       "count": 0,
96       "max": 1,
97       "children": [],
98       "disabled": false,
99       "dynamicInputs": [],
100       "isEcompGeneratedNaming": false,
101       "typeName": "VRF",
102       "componentInfoType": "VRF",
103       "data": {
104       },
105       "getModel" : ()=>{
106         return  {
107           min : 1
108         }
109       }
110     }];
111
112
113     const serviceStore = {
114       "serviceHierarchy": {
115         "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc": {}
116       },
117       "serviceInstance": {
118         "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc": {
119           "action": "Create",
120           "isDirty": false,
121           "vnfs": {},
122           "vrfs": {
123             "VRF Entry Configuration": {
124               "action": "Create",
125               "uuid": "9cac02be-2489-4374-888d-2863b4511a59",
126               "inputs": {},
127               "type": "Configuration",
128               "trackById": "s0z58emiprq",
129               "modelInfo": {
130                 "modelInvariantId": "b67a289b-1688-496d-86e8-1583c828be0a",
131                 "modelVersionId": "69e09f68-8b63-4cc9-b9ff-860960b5db09",
132                 "modelName": "VRF Entry Configuration",
133                 "modelVersion": "5.0",
134                 "modelCustomizationId": "dd024d73-9bd1-425d-9db5-476338d53433",
135                 "modelUniqueId": "dd024d73-9bd1-425d-9db5-476338d53433",
136                 "modelCustomizationName": "VRF Entry Configuration",
137                 "uuid": "9cac02be-2489-4374-888d-2863b4511a59"
138               },
139               "vpns": {
140                 "VRF Entry Configuration vpns 1": {
141                   "action": "Create",
142                   "instanceId": "46fcb25a-e7ba-4d96-99ba-3bb6eae6aba7",
143                   "instanceName": "LPPVPN",
144                   "platformName": "AVPN",
145                   "instanceType": "SERVICE-INFRASTRUCTURE",
146                   "region": "USA,EMEA",
147                   "customerId": "VPN1271",
148                   "modelInfo": {
149                     "modelCustomizationId": null,
150                     "modelInvariantId": null,
151                     "modelVersionId": null
152                   },
153                   "routeTargets": null,
154                   "isSelected": true
155                 }
156               },
157               "networks": {
158                 "VRF Entry Configuration networks 1": {
159                   "action ": "Create",
160                   "instanceName": "AUK51a_oam_calea_net_0",
161                   "instanceType": "SR-IOV-PROVIDER2-0",
162                   "role": "role-1",
163                   "orchStatus": "Active",
164                   "physicalName": "sriovnet0",
165                   "instanceId": "46fcb25a-e7ba-4d96-99ba-3bb6eae6aba7",
166                   "serviceName": "LPPVPN",
167                   "serviceUUID": "VPN1271",
168                   "tenantName": "ecomp_ispt",
169                   "lcpCloudRegionId": "USA,EMEA",
170                   "modelInfo": {
171                     "modelCustomizationId": "46fcb25a-e7ba-4d96-99ba-3bb6eae6aba7",
172                     "modelInvariantId": "46fcb25a-e7ba-4d96-99ba-3bb6eae6aba7",
173                     "modelVersionId": "7010093-df36-4dcb-8428-c3d02bf3f88d",
174                     "modelType": "vpn"
175                   }
176                 }
177               }
178             }
179           },
180           "instanceParams": [],
181           "validationCounter": 0,
182           "existingNames": {},
183           "existingVNFCounterMap": {},
184           "existingVRFCounterMap": {},
185           "existingVnfGroupCounterMap": {},
186           "existingNetworksCounterMap": {},
187           "optionalGroupMembersMap": {},
188           "networks": {},
189           "vnfGroups": {},
190           "bulkSize": 1,
191           "service": {
192             "vidNotions": {
193               "instantiationUI": "serviceWithVRF",
194               "modelCategory": "other",
195               "viewEditUI": "serviceWithVRF",
196               "instantiationType": "ALaCarte"
197             },
198             "uuid": "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc",
199             "invariantUuid": "7ee41ce4-4827-44b0-a48e-2707a59905d2",
200             "name": "VRF Service for Test",
201             "version": "1.0",
202             "toscaModelURL": null,
203             "category": "Network L4+",
204             "serviceType": "INFRASTRUCTURE",
205             "serviceRole": "Configuration",
206             "description": "xxx",
207             "serviceEcompNaming": "true",
208             "instantiationType": "A-La-Carte",
209             "inputs": {}
210           },
211           "collectionResources": {},
212           "configurations": {},
213           "fabricConfigurations": {},
214           "serviceProxies": {},
215           "vfModules": {},
216           "volumeGroups": {},
217           "pnfs": {},
218           "isALaCarte": true,
219           "testApi": "VNF_API",
220           "vidNotions": {
221             "instantiationUI": "serviceWithVVRF",
222             "modelCategory": "other",
223             "viewEditUI": "serviceWithVRF",
224             "instantiationType": "ALaCarte"
225           }
226         }
227       }
228     };
229
230     spyOn(sharedTreeService, 'modelByIdentifiers').and.returnValue({});
231
232     const serviceModelId :string = '4117a0b6-e234-467d-b5b9-fe2f68c8b0fc';
233
234     let result: boolean = service.shouldOpenVRFModal(nodes,  serviceModelId, serviceStore);
235     expect(result).not.toBeNull();
236
237     serviceStore.serviceInstance[serviceModelId].existingVRFCounterMap = {
238       "dd024d73-9bd1-425d-9db5-476338d53433" : 1
239     };
240
241     result = service.shouldOpenVRFModal(nodes,  serviceModelId, serviceStore);
242     expect(result).toBeNull();
243
244   });
245
246 });