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