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