b141a1e79d70dd44ef50346a201a5a5eae0fa035
[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 each from "jest-each";
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   each(
104     [
105       [' checked', true, true],
106       [' not checked', false, false ]
107     ]
108   ).
109   test('sdn-preload checkbox is %s', (
110     description: string, checkedByDefault: boolean, expected: boolean
111   ) => {
112     const instance = null;
113     const sdncPreload: FormControlModel = service.getSDNCControl(instance, checkedByDefault);
114     expect (sdncPreload.displayName).toEqual('SDN-C pre-load');
115     expect (sdncPreload.value).toBe(expected);
116   });
117
118   test('getlegacyRegion with AAIAIC25 - isVisible true', () => {
119     const instance = {lcpCloudRegionId : 'AAIAIC25'};
120     const legacyRegionControl: FormControlModel = service.getLegacyRegion(instance);
121     expect(legacyRegionControl.isVisible).toBeTruthy();
122   });
123
124   test('getlegacyRegion without AAIAIC25 - isVisible false', () => {
125     const instance = {lcpCloudRegionId : 'olson3'};
126     const legacyRegionControl: FormControlModel = service.getLegacyRegion(instance);
127     expect(legacyRegionControl.isVisible).toBeFalsy();
128   });
129
130   test('multiSelectFlag is not activated should generate platform multi select control with 1 as limitSelection', ()=>{
131     const control = service.getPlatformMultiselectControl(null, [],false);
132     expect(control.dataTestId).toEqual('multi-selectPlatform');
133     expect(control.limitSelection).toEqual(1);
134   });
135
136   test('multiSelectFlag is activated should generate platform multi select control with 1000 as limitSelection', ()=>{
137     const control = service.getPlatformMultiselectControl(null, [],true);
138     expect(control.dataTestId).toEqual('multi-selectPlatform');
139     expect(control.limitSelection).toEqual(1000);
140   });
141 });
142
143 class MockAppStore<T> {
144   getState() {
145     return {
146       "global": {
147         "flags": {
148           "FLAG_NETWORK_TO_ASYNC_INSTANTIATION": false,
149           "FLAG_SHOW_ASSIGNMENTS": true,
150           "FLAG_FABRIC_CONFIGURATION_ASSIGNMENTS": true,
151           "FLAG_SHOW_VERIFY_SERVICE": false,
152           "FLAG_SERVICE_MODEL_CACHE": true,
153           "FLAG_ADD_MSO_TESTAPI_FIELD": true
154         }
155       },
156       "service": {
157         "serviceHierarchy": {
158           "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc": {
159             "service": {
160               "uuid": "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc",
161               "invariantUuid": "e49fbd11-e60c-4a8e-b4bf-30fbe8f4fcc0",
162               "name": "ComplexService",
163               "version": "1.0",
164               "toscaModelURL": null,
165               "category": "Emanuel",
166               "serviceType": "",
167               "serviceRole": "",
168               "description": "ComplexService",
169               "serviceEcompNaming": "false",
170               "instantiationType": "Macro",
171               "inputs": {}
172             },
173             "vnfs": {
174               "VF_vGeraldine 0": {
175                 "uuid": "d6557200-ecf2-4641-8094-5393ae3aae60",
176                 "invariantUuid": "4160458e-f648-4b30-a176-43881ffffe9e",
177                 "description": "VSP_vGeraldine",
178                 "name": "VF_vGeraldine",
179                 "version": "2.0",
180                 "customizationUuid": "91415b44-753d-494c-926a-456a9172bbb9",
181                 "inputs": {},
182                 "commands": {},
183                 "properties": {
184                   "max_instances": 10,
185                   "min_instances": 1,
186
187                 },
188                 "type": "VF",
189                 "modelCustomizationName": "VF_vGeraldine 0",
190                 "vfModules": {
191                   "vf_vgeraldine0..VfVgeraldine..vflorence_vlc..module-1": {
192                     "uuid": "522159d5-d6e0-4c2a-aa44-5a542a12a830",
193                     "invariantUuid": "98a7c88b-b577-476a-90e4-e25a5871e02b",
194                     "customizationUuid": "55b1be94-671a-403e-a26c-667e9c47d091",
195                     "description": null,
196                     "name": "VfVgeraldine..vflorence_vlc..module-1",
197                     "version": "2",
198                     "modelCustomizationName": "VfVgeraldine..vflorence_vlc..module-1",
199                     "properties": {
200                       "minCountInstances": 0,
201                       "maxCountInstances": null,
202                       "initialCount": 0,
203                       "vfModuleLabel": "vflorence_vlc"
204                     },
205                     "inputs": {},
206                     "volumeGroupAllowed": true
207                   }
208                 }
209               }
210             }
211           }
212         },
213         "serviceInstance": {
214           "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc": {
215             "vnfs": {
216               "2017-388_PASQUALE-vPE 0": {
217                 "action": "Create",
218                 "inMaint": false,
219                 "rollbackOnFailure": "true",
220                 "originalName": "2017-388_PASQUALE-vPE 0",
221                 "isMissingData": false,
222                 "trackById": "eymgwlevh54",
223                 "vfModules": {},
224                 "vnfStoreKey": "2017-388_PASQUALE-vPE 0",
225                 "uuid": "afacccf6-397d-45d6-b5ae-94c39734b168",
226                 "productFamilyId": "e433710f-9217-458d-a79d-1c7aff376d89",
227                 "lcpCloudRegionId": "AAIAIC25",
228                 "tenantId": "092eb9e8e4b7412e8787dd091bc58e86",
229                 "lineOfBusiness": "ONAP",
230                 "platformName": "platform",
231                 "modelInfo": {
232                   "modelInvariantId": "72e465fe-71b1-4e7b-b5ed-9496118ff7a8",
233                   "modelVersionId": "afacccf6-397d-45d6-b5ae-94c39734b168",
234                   "modelName": "2017-388_PASQUALE-vPE",
235                   "modelVersion": "4.0",
236                   "modelCustomizationId": "b3c76f73-eeb5-4fb6-9d31-72a889f1811c",
237                   "modelCustomizationName": "2017-388_PASQUALE-vPE 0",
238                   "uuid": "afacccf6-397d-45d6-b5ae-94c39734b168",
239                   "modelUniqueId": "b3c76f73-eeb5-4fb6-9d31-72a889f1811c"
240                 },
241                 "instanceName": "2017-388_PASQUALE-vPEAjXzainstanceName",
242                 "legacyRegion": "some legacy region",
243                 "instanceParams": [
244                   {
245                     "vnf_config_template_version": "17.2",
246                     "bandwidth_units": "Gbps",
247                     "bandwidth": "10",
248                     "AIC_CLLI": "ATLMY8GA",
249                     "ASN": "AV_vPE",
250                     "vnf_instance_name": "mtnj309me6"
251                   }
252                 ]
253               }
254             },
255             "service": {
256               "vidNotions": {
257                 "instantiationUI": "serviceWithVRF",
258                 "modelCategory": "other",
259                 "viewEditUI": "serviceWithVRF",
260                 "instantiationType": "ALaCarte"
261               },
262               "uuid": "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc",
263               "invariantUuid": "7ee41ce4-4827-44b0-a48e-2707a59905d2",
264               "name": "VRF Service for Test",
265               "version": "1.0",
266               "toscaModelURL": null,
267               "category": "Network L4+",
268               "serviceType": "INFRASTRUCTURE",
269               "serviceRole": "Configuration",
270               "description": "xxx",
271               "serviceEcompNaming": "true",
272               "instantiationType": "A-La-Carte",
273               "inputs": {}
274             },
275             "isALaCarte": true
276           }
277         }
278       }
279     }
280   }
281 }
282
283 class MockFeatureFlagsService {}