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";
15 describe('Shared Controllers Service', () => {
17 let service: SharedControllersService;
18 let httpMock: HttpTestingController;
19 let store: NgRedux<AppState>;
20 let basicControlGenerator : ControlGeneratorUtil;
22 beforeAll(done => (async () => {
23 TestBed.configureTestingModule({
24 imports: [HttpClientTestingModule],
25 providers: [SharedControllersService,
28 {provide:FeatureFlagsService, useClass: MockFeatureFlagsService},
29 {provide: NgRedux, useClass: MockAppStore}]
31 await TestBed.compileComponents();
33 injector = getTestBed();
34 service = injector.get(SharedControllersService);
35 basicControlGenerator = injector.get(ControlGeneratorUtil);
36 httpMock = injector.get(HttpTestingController);
37 store = injector.get(NgRedux);
39 })().then(done).catch(done.fail));
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();
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]];
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));
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();
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();
105 [' checked', true, true],
106 [' not checked', false, false ]
109 test('sdn-preload checkbox is %s', (
110 description: string, checkedByDefault: boolean, expected: boolean
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);
118 test('getlegacyRegion with AAIAIC25 - isVisible true', () => {
119 const instance = {lcpCloudRegionId : 'AAIAIC25'};
120 const legacyRegionControl: FormControlModel = service.getLegacyRegion(instance);
121 expect(legacyRegionControl.isVisible).toBeTruthy();
124 test('getlegacyRegion without AAIAIC25 - isVisible false', () => {
125 const instance = {lcpCloudRegionId : 'olson3'};
126 const legacyRegionControl: FormControlModel = service.getLegacyRegion(instance);
127 expect(legacyRegionControl.isVisible).toBeFalsy();
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);
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);
143 class MockAppStore<T> {
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
157 "serviceHierarchy": {
158 "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc": {
160 "uuid": "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc",
161 "invariantUuid": "e49fbd11-e60c-4a8e-b4bf-30fbe8f4fcc0",
162 "name": "ComplexService",
164 "toscaModelURL": null,
165 "category": "Emanuel",
168 "description": "ComplexService",
169 "serviceEcompNaming": "false",
170 "instantiationType": "Macro",
175 "uuid": "d6557200-ecf2-4641-8094-5393ae3aae60",
176 "invariantUuid": "4160458e-f648-4b30-a176-43881ffffe9e",
177 "description": "VSP_vGeraldine",
178 "name": "VF_vGeraldine",
180 "customizationUuid": "91415b44-753d-494c-926a-456a9172bbb9",
189 "modelCustomizationName": "VF_vGeraldine 0",
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",
196 "name": "VfVgeraldine..vflorence_vlc..module-1",
198 "modelCustomizationName": "VfVgeraldine..vflorence_vlc..module-1",
200 "minCountInstances": 0,
201 "maxCountInstances": null,
203 "vfModuleLabel": "vflorence_vlc"
206 "volumeGroupAllowed": true
214 "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc": {
216 "2017-388_PASQUALE-vPE 0": {
219 "rollbackOnFailure": "true",
220 "originalName": "2017-388_PASQUALE-vPE 0",
221 "isMissingData": false,
222 "trackById": "eymgwlevh54",
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",
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"
241 "instanceName": "2017-388_PASQUALE-vPEAjXzainstanceName",
242 "legacyRegion": "some legacy region",
245 "vnf_config_template_version": "17.2",
246 "bandwidth_units": "Gbps",
248 "AIC_CLLI": "ATLMY8GA",
250 "vnf_instance_name": "mtnj309me6"
257 "instantiationUI": "serviceWithVRF",
258 "modelCategory": "other",
259 "viewEditUI": "serviceWithVRF",
260 "instantiationType": "ALaCarte"
262 "uuid": "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc",
263 "invariantUuid": "7ee41ce4-4827-44b0-a48e-2707a59905d2",
264 "name": "VRF Service for Test",
266 "toscaModelURL": null,
267 "category": "Network L4+",
268 "serviceType": "INFRASTRUCTURE",
269 "serviceRole": "Configuration",
270 "description": "xxx",
271 "serviceEcompNaming": "true",
272 "instantiationType": "A-La-Carte",
283 class MockFeatureFlagsService {}