58ee33b5355b075decf8157b96dff3db8d477023
[vid.git] /
1 import * as _ from "lodash";
2 import {getTestBed, TestBed} from '@angular/core/testing';
3 import {SharedControllersService} from "./shared.controllers.service";
4 import {HttpClientTestingModule, HttpTestingController} from "@angular/common/http/testing";
5 import {AppState} from "../../../../store/reducers";
6 import {NgRedux} from "@angular-redux/store";
7 import {AaiService} from "../../../../services/aaiService/aai.service";
8 import {FeatureFlagsService} from "../../../../services/featureFlag/feature-flags.service";
9 import {DropdownFormControl} from "../../../../models/formControlModels/dropdownFormControl.model";
10 import {FormControlModel, ValidatorOptions} from "../../../../models/formControlModels/formControl.model";
11 import {ControlGeneratorUtil} from "../control.generator.util.service";
12
13
14
15 describe('Shared Controllers Service', () => {
16   let injector;
17   let service: SharedControllersService;
18   let httpMock: HttpTestingController;
19   let store: NgRedux<AppState>;
20   let basicControlGenerator : ControlGeneratorUtil;
21
22   beforeAll(done => (async () => {
23     TestBed.configureTestingModule({
24       imports: [HttpClientTestingModule],
25       providers: [SharedControllersService,
26         AaiService,
27         ControlGeneratorUtil,
28         {provide:FeatureFlagsService, useClass: MockFeatureFlagsService},
29         {provide: NgRedux, useClass: MockAppStore}]
30     });
31     await TestBed.compileComponents();
32
33     injector = getTestBed();
34     service = injector.get(SharedControllersService);
35     basicControlGenerator = injector.get(ControlGeneratorUtil);
36     httpMock = injector.get(HttpTestingController);
37     store = injector.get(NgRedux);
38
39   })().then(done).catch(done.fail));
40
41
42
43
44
45   test('getLineOfBusinessControl', ()=> {
46     const lineOfBusinessControl :DropdownFormControl  = service.getLineOfBusinessControl();
47     expect(lineOfBusinessControl.name).toEqual('lineOfBusiness');
48     expect(lineOfBusinessControl.controlName).toEqual('lineOfBusiness');
49     expect(lineOfBusinessControl.displayName).toEqual('Line of business');
50     expect(lineOfBusinessControl.dataTestId).toEqual('lineOfBusiness');
51     expect(lineOfBusinessControl.placeHolder).toEqual('Select Line Of Business');
52     expect(lineOfBusinessControl.onInitSelectedField).toEqual(['lineOfBusinessList']);
53     expect(lineOfBusinessControl.onInit).toBeDefined();
54     expect(lineOfBusinessControl.value).toBeNull();
55     expect(lineOfBusinessControl.validations.find((validation)=> validation.validatorName === ValidatorOptions.required)).toBeDefined();
56     expect(lineOfBusinessControl.isDisabled).toBeFalsy();
57   });
58
59   test('getTenantControl', ()=> {
60     const serviceId : string = Object.keys(store.getState().service.serviceInstance)[0];
61     const vnfs = store.getState().service.serviceInstance[serviceId].vnfs;
62     const currentVnf = vnfs[Object.keys(vnfs)[0]];
63
64     const tanantControl :DropdownFormControl  = service.getTenantControl(serviceId, currentVnf);
65     expect(tanantControl.name).toEqual('tenant');
66     expect(tanantControl.controlName).toEqual('tenantId');
67     expect(tanantControl.displayName).toEqual('Tenant');
68     expect(tanantControl.dataTestId).toEqual('tenant');
69     expect(tanantControl.placeHolder).toEqual('Select Tenant');
70     expect(tanantControl.onInitSelectedField).toEqual(['lcpRegionsTenantsMap', currentVnf.lcpCloudRegionId]);
71     expect(tanantControl.onInit).toBeDefined();
72     expect(tanantControl.validations.find((validation)=> validation.validatorName === ValidatorOptions.required)).toBeDefined();
73     expect(tanantControl.isDisabled).toEqual(_.isNil(currentVnf.lcpCloudRegionId));
74   });
75
76
77   test('getRollbackOnFailureControl', ()=> {
78     const rollbackOnFailureControl :DropdownFormControl  = service.getRollbackOnFailureControl();
79     expect(rollbackOnFailureControl.controlName).toEqual('rollbackOnFailure');
80     expect(rollbackOnFailureControl.displayName).toEqual('Rollback on failure');
81     expect(rollbackOnFailureControl.dataTestId).toEqual('rollback');
82     expect(rollbackOnFailureControl.placeHolder).toEqual('Rollback on failure');
83     expect(rollbackOnFailureControl.onInit).toBeDefined();
84     expect(rollbackOnFailureControl.validations.find((validation)=> validation.validatorName === ValidatorOptions.required)).toBeDefined();
85     expect(rollbackOnFailureControl.isDisabled).toBeFalsy();
86   });
87
88   test('getLcpRegionControl', ()=> {
89     const serviceId : string = Object.keys(store.getState().service.serviceInstance)[0];
90     const vnfs = store.getState().service.serviceInstance[serviceId].vnfs;
91     const currentVnf = vnfs[Object.keys(vnfs)[0]];
92     const lcpRegionControl :DropdownFormControl  = service.getLcpRegionControl(serviceId, currentVnf, []);
93     expect(lcpRegionControl.controlName).toEqual('lcpCloudRegionId');
94     expect(lcpRegionControl.displayName).toEqual('LCP region');
95     expect(lcpRegionControl.dataTestId).toEqual('lcpRegion');
96     expect(lcpRegionControl.placeHolder).toEqual('Select LCP Region');
97     expect(lcpRegionControl.onInit).toBeDefined();
98     expect(lcpRegionControl.onChange).toBeDefined();
99     expect(lcpRegionControl.validations.find((validation)=> validation.validatorName === ValidatorOptions.required)).toBeDefined();
100     expect(lcpRegionControl.isDisabled).toBeFalsy();
101   });
102
103   test('sdn-preload checkbox is visible', () => {
104     const instance = {};
105     const sdncPreload: FormControlModel = service.getSDNCControl(instance);
106     expect (sdncPreload.displayName).toEqual('SDN-C pre-load');
107     expect (sdncPreload.value).toBeFalsy();
108   });
109
110   test('getlegacyRegion with AAIAIC25 - isVisible true', () => {
111     const instance = {lcpCloudRegionId : 'AAIAIC25'};
112     const legacyRegionControl: FormControlModel = service.getLegacyRegion(instance);
113     expect(legacyRegionControl.isVisible).toBeTruthy();
114   });
115
116   test('getlegacyRegion without AAIAIC25 - isVisible false', () => {
117     const instance = {lcpCloudRegionId : 'olson3'};
118     const legacyRegionControl: FormControlModel = service.getLegacyRegion(instance);
119     expect(legacyRegionControl.isVisible).toBeFalsy();
120   });
121 });
122
123 class MockAppStore<T> {
124   getState() {
125     return {
126       "global": {
127         "flags": {
128           "FLAG_NETWORK_TO_ASYNC_INSTANTIATION": false,
129           "FLAG_SHOW_ASSIGNMENTS": true,
130           "FLAG_FABRIC_CONFIGURATION_ASSIGNMENTS": true,
131           "FLAG_SHOW_VERIFY_SERVICE": false,
132           "FLAG_SERVICE_MODEL_CACHE": true,
133           "FLAG_ADD_MSO_TESTAPI_FIELD": true
134         }
135       },
136       "service": {
137         "serviceHierarchy": {
138           "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc": {
139             "service": {
140               "uuid": "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc",
141               "invariantUuid": "e49fbd11-e60c-4a8e-b4bf-30fbe8f4fcc0",
142               "name": "ComplexService",
143               "version": "1.0",
144               "toscaModelURL": null,
145               "category": "Emanuel",
146               "serviceType": "",
147               "serviceRole": "",
148               "description": "ComplexService",
149               "serviceEcompNaming": "false",
150               "instantiationType": "Macro",
151               "inputs": {}
152             },
153             "vnfs": {
154               "VF_vGeraldine 0": {
155                 "uuid": "d6557200-ecf2-4641-8094-5393ae3aae60",
156                 "invariantUuid": "4160458e-f648-4b30-a176-43881ffffe9e",
157                 "description": "VSP_vGeraldine",
158                 "name": "VF_vGeraldine",
159                 "version": "2.0",
160                 "customizationUuid": "91415b44-753d-494c-926a-456a9172bbb9",
161                 "inputs": {},
162                 "commands": {},
163                 "properties": {
164                   "max_instances": 10,
165                   "min_instances": 1,
166
167                 },
168                 "type": "VF",
169                 "modelCustomizationName": "VF_vGeraldine 0",
170                 "vfModules": {
171                   "vf_vgeraldine0..VfVgeraldine..vflorence_vlc..module-1": {
172                     "uuid": "522159d5-d6e0-4c2a-aa44-5a542a12a830",
173                     "invariantUuid": "98a7c88b-b577-476a-90e4-e25a5871e02b",
174                     "customizationUuid": "55b1be94-671a-403e-a26c-667e9c47d091",
175                     "description": null,
176                     "name": "VfVgeraldine..vflorence_vlc..module-1",
177                     "version": "2",
178                     "modelCustomizationName": "VfVgeraldine..vflorence_vlc..module-1",
179                     "properties": {
180                       "minCountInstances": 0,
181                       "maxCountInstances": null,
182                       "initialCount": 0,
183                       "vfModuleLabel": "vflorence_vlc"
184                     },
185                     "inputs": {},
186                     "volumeGroupAllowed": true
187                   }
188                 }
189               }
190             }
191           }
192         },
193         "serviceInstance": {
194           "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc": {
195             "vnfs": {
196               "2017-388_PASQUALE-vPE 0": {
197                 "action": "Create",
198                 "inMaint": false,
199                 "rollbackOnFailure": "true",
200                 "originalName": "2017-388_PASQUALE-vPE 0",
201                 "isMissingData": false,
202                 "trackById": "eymgwlevh54",
203                 "vfModules": {},
204                 "vnfStoreKey": "2017-388_PASQUALE-vPE 0",
205                 "uuid": "afacccf6-397d-45d6-b5ae-94c39734b168",
206                 "productFamilyId": "e433710f-9217-458d-a79d-1c7aff376d89",
207                 "lcpCloudRegionId": "AAIAIC25",
208                 "tenantId": "092eb9e8e4b7412e8787dd091bc58e86",
209                 "lineOfBusiness": "ONAP",
210                 "platformName": "platform",
211                 "modelInfo": {
212                   "modelInvariantId": "72e465fe-71b1-4e7b-b5ed-9496118ff7a8",
213                   "modelVersionId": "afacccf6-397d-45d6-b5ae-94c39734b168",
214                   "modelName": "2017-388_PASQUALE-vPE",
215                   "modelVersion": "4.0",
216                   "modelCustomizationId": "b3c76f73-eeb5-4fb6-9d31-72a889f1811c",
217                   "modelCustomizationName": "2017-388_PASQUALE-vPE 0",
218                   "uuid": "afacccf6-397d-45d6-b5ae-94c39734b168",
219                   "modelUniqueId": "b3c76f73-eeb5-4fb6-9d31-72a889f1811c"
220                 },
221                 "instanceName": "2017-388_PASQUALE-vPEAjXzainstanceName",
222                 "legacyRegion": "some legacy region",
223                 "instanceParams": [
224                   {
225                     "vnf_config_template_version": "17.2",
226                     "bandwidth_units": "Gbps",
227                     "bandwidth": "10",
228                     "AIC_CLLI": "ATLMY8GA",
229                     "ASN": "AV_vPE",
230                     "vnf_instance_name": "mtnj309me6"
231                   }
232                 ]
233               }
234             },
235             "service": {
236               "vidNotions": {
237                 "instantiationUI": "serviceWithVRF",
238                 "modelCategory": "other",
239                 "viewEditUI": "serviceWithVRF",
240                 "instantiationType": "ALaCarte"
241               },
242               "uuid": "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc",
243               "invariantUuid": "7ee41ce4-4827-44b0-a48e-2707a59905d2",
244               "name": "VRF Service for Test",
245               "version": "1.0",
246               "toscaModelURL": null,
247               "category": "Network L4+",
248               "serviceType": "INFRASTRUCTURE",
249               "serviceRole": "Configuration",
250               "description": "xxx",
251               "serviceEcompNaming": "true",
252               "instantiationType": "A-La-Carte",
253               "inputs": {}
254             },
255             "isALaCarte": true
256           }
257         }
258       }
259     }
260   }
261 }
262
263 class MockFeatureFlagsService {}