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";
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();
103 test('sdn-preload checkbox is visible', () => {
105 const sdncPreload: FormControlModel = service.getSDNCControl(instance);
106 expect (sdncPreload.displayName).toEqual('SDN-C pre-load');
107 expect (sdncPreload.value).toBeFalsy();
110 test('getlegacyRegion with AAIAIC25 - isVisible true', () => {
111 const instance = {lcpCloudRegionId : 'AAIAIC25'};
112 const legacyRegionControl: FormControlModel = service.getLegacyRegion(instance);
113 expect(legacyRegionControl.isVisible).toBeTruthy();
116 test('getlegacyRegion without AAIAIC25 - isVisible false', () => {
117 const instance = {lcpCloudRegionId : 'olson3'};
118 const legacyRegionControl: FormControlModel = service.getLegacyRegion(instance);
119 expect(legacyRegionControl.isVisible).toBeFalsy();
123 class MockAppStore<T> {
128 "FLAG_NETWORK_TO_ASYNC_INSTANTIATION": false,
129 "FLAG_SHOW_ASSIGNMENTS": true,
130 "FLAG_FABRIC_CONFIGURATION_ASSIGNMENTS": true,
131 "FLAG_SHOW_VERIFY_SERVICE": false,
132 "FLAG_SERVICE_MODEL_CACHE": true,
133 "FLAG_ADD_MSO_TESTAPI_FIELD": true
137 "serviceHierarchy": {
138 "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc": {
140 "uuid": "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc",
141 "invariantUuid": "e49fbd11-e60c-4a8e-b4bf-30fbe8f4fcc0",
142 "name": "ComplexService",
144 "toscaModelURL": null,
145 "category": "Emanuel",
148 "description": "ComplexService",
149 "serviceEcompNaming": "false",
150 "instantiationType": "Macro",
155 "uuid": "d6557200-ecf2-4641-8094-5393ae3aae60",
156 "invariantUuid": "4160458e-f648-4b30-a176-43881ffffe9e",
157 "description": "VSP_vGeraldine",
158 "name": "VF_vGeraldine",
160 "customizationUuid": "91415b44-753d-494c-926a-456a9172bbb9",
169 "modelCustomizationName": "VF_vGeraldine 0",
171 "vf_vgeraldine0..VfVgeraldine..vflorence_vlc..module-1": {
172 "uuid": "522159d5-d6e0-4c2a-aa44-5a542a12a830",
173 "invariantUuid": "98a7c88b-b577-476a-90e4-e25a5871e02b",
174 "customizationUuid": "55b1be94-671a-403e-a26c-667e9c47d091",
176 "name": "VfVgeraldine..vflorence_vlc..module-1",
178 "modelCustomizationName": "VfVgeraldine..vflorence_vlc..module-1",
180 "minCountInstances": 0,
181 "maxCountInstances": null,
183 "vfModuleLabel": "vflorence_vlc"
186 "volumeGroupAllowed": true
194 "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc": {
196 "2017-388_PASQUALE-vPE 0": {
199 "rollbackOnFailure": "true",
200 "originalName": "2017-388_PASQUALE-vPE 0",
201 "isMissingData": false,
202 "trackById": "eymgwlevh54",
204 "vnfStoreKey": "2017-388_PASQUALE-vPE 0",
205 "uuid": "afacccf6-397d-45d6-b5ae-94c39734b168",
206 "productFamilyId": "e433710f-9217-458d-a79d-1c7aff376d89",
207 "lcpCloudRegionId": "AAIAIC25",
208 "tenantId": "092eb9e8e4b7412e8787dd091bc58e86",
209 "lineOfBusiness": "ONAP",
210 "platformName": "platform",
212 "modelInvariantId": "72e465fe-71b1-4e7b-b5ed-9496118ff7a8",
213 "modelVersionId": "afacccf6-397d-45d6-b5ae-94c39734b168",
214 "modelName": "2017-388_PASQUALE-vPE",
215 "modelVersion": "4.0",
216 "modelCustomizationId": "b3c76f73-eeb5-4fb6-9d31-72a889f1811c",
217 "modelCustomizationName": "2017-388_PASQUALE-vPE 0",
218 "uuid": "afacccf6-397d-45d6-b5ae-94c39734b168",
219 "modelUniqueId": "b3c76f73-eeb5-4fb6-9d31-72a889f1811c"
221 "instanceName": "2017-388_PASQUALE-vPEAjXzainstanceName",
222 "legacyRegion": "some legacy region",
225 "vnf_config_template_version": "17.2",
226 "bandwidth_units": "Gbps",
228 "AIC_CLLI": "ATLMY8GA",
230 "vnf_instance_name": "mtnj309me6"
237 "instantiationUI": "serviceWithVRF",
238 "modelCategory": "other",
239 "viewEditUI": "serviceWithVRF",
240 "instantiationType": "ALaCarte"
242 "uuid": "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc",
243 "invariantUuid": "7ee41ce4-4827-44b0-a48e-2707a59905d2",
244 "name": "VRF Service for Test",
246 "toscaModelURL": null,
247 "category": "Network L4+",
248 "serviceType": "INFRASTRUCTURE",
249 "serviceRole": "Configuration",
250 "description": "xxx",
251 "serviceEcompNaming": "true",
252 "instantiationType": "A-La-Carte",
263 class MockFeatureFlagsService {}