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