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);
114 test('getlegacyRegion with AAIAIC25 - isVisible true', () => {
115 const instance = {lcpCloudRegionId : 'AAIAIC25'};
116 const legacyRegionControl: FormControlModel = service.getLegacyRegion(instance);
117 expect(legacyRegionControl.isVisible).toBeTruthy();
120 test('getlegacyRegion without AAIAIC25 - isVisible false', () => {
121 const instance = {lcpCloudRegionId : 'olson3'};
122 const legacyRegionControl: FormControlModel = service.getLegacyRegion(instance);
123 expect(legacyRegionControl.isVisible).toBeFalsy();
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);
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);
139 class MockAppStore<T> {
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
153 "serviceHierarchy": {
154 "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc": {
156 "uuid": "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc",
157 "invariantUuid": "e49fbd11-e60c-4a8e-b4bf-30fbe8f4fcc0",
158 "name": "ComplexService",
160 "toscaModelURL": null,
161 "category": "Emanuel",
164 "description": "ComplexService",
165 "serviceEcompNaming": "false",
166 "instantiationType": "Macro",
171 "uuid": "d6557200-ecf2-4641-8094-5393ae3aae60",
172 "invariantUuid": "4160458e-f648-4b30-a176-43881ffffe9e",
173 "description": "VSP_vGeraldine",
174 "name": "VF_vGeraldine",
176 "customizationUuid": "91415b44-753d-494c-926a-456a9172bbb9",
185 "modelCustomizationName": "VF_vGeraldine 0",
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",
192 "name": "VfVgeraldine..vflorence_vlc..module-1",
194 "modelCustomizationName": "VfVgeraldine..vflorence_vlc..module-1",
196 "minCountInstances": 0,
197 "maxCountInstances": null,
199 "vfModuleLabel": "vflorence_vlc"
202 "volumeGroupAllowed": true
210 "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc": {
212 "2017-388_PASQUALE-vPE 0": {
215 "rollbackOnFailure": "true",
216 "originalName": "2017-388_PASQUALE-vPE 0",
217 "isMissingData": false,
218 "trackById": "eymgwlevh54",
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",
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"
237 "instanceName": "2017-388_PASQUALE-vPEAjXzainstanceName",
238 "legacyRegion": "some legacy region",
241 "vnf_config_template_version": "17.2",
242 "bandwidth_units": "Gbps",
244 "AIC_CLLI": "ATLMY8GA",
246 "vnf_instance_name": "mtnj309me6"
253 "instantiationUI": "serviceWithVRF",
254 "modelCategory": "other",
255 "viewEditUI": "serviceWithVRF",
256 "instantiationType": "ALaCarte"
258 "uuid": "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc",
259 "invariantUuid": "7ee41ce4-4827-44b0-a48e-2707a59905d2",
260 "name": "VRF Service for Test",
262 "toscaModelURL": null,
263 "category": "Network L4+",
264 "serviceType": "INFRASTRUCTURE",
265 "serviceRole": "Configuration",
266 "description": "xxx",
267 "serviceEcompNaming": "true",
268 "instantiationType": "A-La-Carte",
279 class MockFeatureFlagsService {}