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";
16 describe('Shared Controllers Service', () => {
18 let service: SharedControllersService;
19 let httpMock: HttpTestingController;
20 let store: NgRedux<AppState>;
21 let basicControlGenerator : ControlGeneratorUtil;
23 beforeAll(done => (async () => {
24 TestBed.configureTestingModule({
25 imports: [HttpClientTestingModule],
26 providers: [SharedControllersService,
29 {provide:FeatureFlagsService, useClass: MockFeatureFlagsService},
30 {provide: NgRedux, useClass: MockAppStore}]
32 await TestBed.compileComponents();
34 injector = getTestBed();
35 service = injector.get(SharedControllersService);
36 basicControlGenerator = injector.get(ControlGeneratorUtil);
37 httpMock = injector.get(HttpTestingController);
38 store = injector.get(NgRedux);
40 })().then(done).catch(done.fail));
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();
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]];
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));
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();
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();
101 [' checked', true, true],
102 [' not checked', false, false ]
105 test('sdn-preload checkbox is %s', (
106 description: string, checkedByDefault: boolean, expected: boolean
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);
116 [' checked', true, true],
117 [' not checked', false, false ]
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');
127 test('getlegacyRegion with AAIAIC25 - isVisible true', () => {
128 const instance = {lcpCloudRegionId : 'AAIAIC25'};
129 const legacyRegionControl: FormControlModel = service.getLegacyRegion(instance);
130 expect(legacyRegionControl.isVisible).toBeTruthy();
133 test('getlegacyRegion without AAIAIC25 - isVisible false', () => {
134 const instance = {lcpCloudRegionId : 'olson3'};
135 const legacyRegionControl: FormControlModel = service.getLegacyRegion(instance);
136 expect(legacyRegionControl.isVisible).toBeFalsy();
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);
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);
154 class MockAppStore<T> {
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
168 "serviceHierarchy": {
169 "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc": {
171 "uuid": "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc",
172 "invariantUuid": "e49fbd11-e60c-4a8e-b4bf-30fbe8f4fcc0",
173 "name": "ComplexService",
175 "toscaModelURL": null,
176 "category": "Emanuel",
179 "description": "ComplexService",
180 "serviceEcompNaming": "false",
181 "instantiationType": "Macro",
186 "uuid": "d6557200-ecf2-4641-8094-5393ae3aae60",
187 "invariantUuid": "4160458e-f648-4b30-a176-43881ffffe9e",
188 "description": "VSP_vGeraldine",
189 "name": "VF_vGeraldine",
191 "customizationUuid": "91415b44-753d-494c-926a-456a9172bbb9",
200 "modelCustomizationName": "VF_vGeraldine 0",
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",
207 "name": "VfVgeraldine..vflorence_vlc..module-1",
209 "modelCustomizationName": "VfVgeraldine..vflorence_vlc..module-1",
211 "minCountInstances": 0,
212 "maxCountInstances": null,
214 "vfModuleLabel": "vflorence_vlc"
217 "volumeGroupAllowed": true
225 "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc": {
227 "2017-388_PASQUALE-vPE 0": {
230 "rollbackOnFailure": "true",
231 "originalName": "2017-388_PASQUALE-vPE 0",
232 "isMissingData": false,
233 "trackById": "eymgwlevh54",
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",
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"
252 "instanceName": "2017-388_PASQUALE-vPEAjXzainstanceName",
253 "legacyRegion": "some legacy region",
256 "vnf_config_template_version": "17.2",
257 "bandwidth_units": "Gbps",
259 "AIC_CLLI": "ATLMY8GA",
261 "vnf_instance_name": "mtnj309me6"
268 "instantiationUI": "serviceWithVRF",
269 "modelCategory": "other",
270 "viewEditUI": "serviceWithVRF",
271 "instantiationType": "ALaCarte"
273 "uuid": "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc",
274 "invariantUuid": "7ee41ce4-4827-44b0-a48e-2707a59905d2",
275 "name": "VRF Service for Test",
277 "toscaModelURL": null,
278 "category": "Network L4+",
279 "serviceType": "INFRASTRUCTURE",
280 "serviceRole": "Configuration",
281 "description": "xxx",
282 "serviceEcompNaming": "true",
283 "instantiationType": "A-La-Carte",
294 class MockFeatureFlagsService {}