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";
12 describe('Available Models Tree Service', () => {
15 let service: AvailableModelsTreeService;
16 let httpMock: HttpTestingController;
17 let sharedTreeService: SharedTreeService;
19 beforeAll(done => (async () => {
20 TestBed.configureTestingModule({
21 imports: [HttpClientTestingModule, NgReduxTestingModule],
22 providers: [AvailableModelsTreeService,
23 DefaultDataGeneratorService,
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));
35 test('addingAlertAddingNewVfModuleModal should open message modal', () => {
36 jest.spyOn(MessageBoxService.openModal, 'next');
37 service.addingAlertAddingNewVfModuleModal();
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,
45 {text: "Close", size: "medium", closeModal: true}
51 describe('#shouldOpenModalDialogOnAddInstance', () => {
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();
58 // add vfModule with user provided naming should return true
59 result = service.shouldOpenDialog(ServiceNodeTypes.VFmodule, [], false);
60 expect(result).toBeTruthy();
62 // add vfModule with dynamicInputs without defaultValues should return true
63 result = service.shouldOpenDialog(ServiceNodeTypes.VFmodule, [{
64 id: '2017488_pasqualevpe0_vnf_config_template_version',
66 name: '2017488_pasqualevpe0_vnf_config_template_version',
68 description: 'VPE Software Version'
70 expect(result).toBeTruthy();
72 // add vfModule with dynamicInputs with defaultValues should return false
73 result = service.shouldOpenDialog(ServiceNodeTypes.VFmodule, [{
74 id: '2017488_pasqualevpe0_vnf_config_template_version',
76 name: '2017488_pasqualevpe0_vnf_config_template_version',
79 description: 'VPE Software Version'
81 expect(result).toBeFalsy();
86 test('shouldOpenVRFModal', () => {
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",
100 "isEcompGeneratedNaming": false,
102 "componentInfoType": "VRF",
113 const serviceStore = {
114 "serviceHierarchy": {
115 "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc": {}
118 "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc": {
123 "VRF Entry Configuration": {
125 "uuid": "9cac02be-2489-4374-888d-2863b4511a59",
127 "type": "Configuration",
128 "trackById": "s0z58emiprq",
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"
140 "VRF Entry Configuration vpns 1": {
142 "instanceId": "46fcb25a-e7ba-4d96-99ba-3bb6eae6aba7",
143 "instanceName": "LPPVPN",
144 "platformName": "AVPN",
145 "instanceType": "SERVICE-INFRASTRUCTURE",
146 "region": "USA,EMEA",
147 "customerId": "VPN1271",
149 "modelCustomizationId": null,
150 "modelInvariantId": null,
151 "modelVersionId": null
153 "routeTargets": null,
158 "VRF Entry Configuration networks 1": {
160 "instanceName": "AUK51a_oam_calea_net_0",
161 "instanceType": "SR-IOV-PROVIDER2-0",
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",
171 "modelCustomizationId": "46fcb25a-e7ba-4d96-99ba-3bb6eae6aba7",
172 "modelInvariantId": "46fcb25a-e7ba-4d96-99ba-3bb6eae6aba7",
173 "modelVersionId": "7010093-df36-4dcb-8428-c3d02bf3f88d",
180 "instanceParams": [],
181 "validationCounter": 0,
183 "existingVNFCounterMap": {},
184 "existingVRFCounterMap": {},
185 "existingVnfGroupCounterMap": {},
186 "existingNetworksCounterMap": {},
187 "optionalGroupMembersMap": {},
193 "instantiationUI": "serviceWithVRF",
194 "modelCategory": "other",
195 "viewEditUI": "serviceWithVRF",
196 "instantiationType": "ALaCarte"
198 "uuid": "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc",
199 "invariantUuid": "7ee41ce4-4827-44b0-a48e-2707a59905d2",
200 "name": "VRF Service for Test",
202 "toscaModelURL": null,
203 "category": "Network L4+",
204 "serviceType": "INFRASTRUCTURE",
205 "serviceRole": "Configuration",
206 "description": "xxx",
207 "serviceEcompNaming": "true",
208 "instantiationType": "A-La-Carte",
211 "collectionResources": {},
212 "configurations": {},
213 "fabricConfigurations": {},
214 "serviceProxies": {},
219 "testApi": "VNF_API",
221 "instantiationUI": "serviceWithVVRF",
222 "modelCategory": "other",
223 "viewEditUI": "serviceWithVRF",
224 "instantiationType": "ALaCarte"
230 spyOn(sharedTreeService, 'modelByIdentifiers').and.returnValue({});
232 const serviceModelId :string = '4117a0b6-e234-467d-b5b9-fe2f68c8b0fc';
234 let result: boolean = service.shouldOpenVRFModal(nodes, serviceModelId, serviceStore);
235 expect(result).not.toBeNull();
237 serviceStore.serviceInstance[serviceModelId].existingVRFCounterMap = {
238 "dd024d73-9bd1-425d-9db5-476338d53433" : 1
241 result = service.shouldOpenVRFModal(nodes, serviceModelId, serviceStore);
242 expect(result).toBeNull();