summaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/shared/components/genericForm
diff options
context:
space:
mode:
Diffstat (limited to 'vid-webpack-master/src/app/shared/components/genericForm')
-rw-r--r--vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/pnfGenerator/pnf.control.generator.spec.ts175
-rw-r--r--vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/pnfGenerator/pnf.control.generator.ts87
2 files changed, 262 insertions, 0 deletions
diff --git a/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/pnfGenerator/pnf.control.generator.spec.ts b/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/pnfGenerator/pnf.control.generator.spec.ts
new file mode 100644
index 000000000..e510eaad2
--- /dev/null
+++ b/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/pnfGenerator/pnf.control.generator.spec.ts
@@ -0,0 +1,175 @@
+import {getTestBed, TestBed} from '@angular/core/testing';
+import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
+import {NgRedux} from '@angular-redux/store';
+import {FormControlNames} from "../service.control.generator";
+import {ControlGeneratorUtil} from "../control.generator.util.service";
+import {AaiService} from "../../../../services/aaiService/aai.service";
+import {GenericFormService} from "../../generic-form.service";
+import {FormBuilder} from "@angular/forms";
+import {FormControlModel} from "../../../../models/formControlModels/formControl.model";
+import {LogService} from "../../../../utils/log/log.service";
+import {FeatureFlagsService} from "../../../../services/featureFlag/feature-flags.service";
+import {SharedControllersService} from "../sharedControlles/shared.controllers.service";
+import {PnfControlGenerator} from "./pnf.control.generator";
+import {MockNgRedux} from "@angular-redux/store/testing";
+
+class MockFeatureFlagsService {
+}
+
+class MockAppStore<T> {
+ getState() {
+ return {
+ global: {
+ flags: {
+ "FLAG_NETWORK_TO_ASYNC_INSTANTIATION": false,
+ "FLAG_SHOW_ASSIGNMENTS": true,
+ "FLAG_FABRIC_CONFIGURATION_ASSIGNMENTS": true,
+ "FLAG_SHOW_VERIFY_SERVICE": false,
+ "FLAG_SERVICE_MODEL_CACHE": true,
+ "FLAG_ADD_MSO_TESTAPI_FIELD": true
+ }
+ },
+ service: {
+ serviceHierarchy: {
+ 'serviceId': {
+ 'pnfs': {
+ 'pnfName': {}
+ }
+ }
+ },
+ serviceInstance: {
+ 'serviceId': {
+ 'pnfs': {
+ 'pnfName': {}
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+describe('PNF Control Generator', () => {
+ let injector;
+ let service: PnfControlGenerator;
+ let httpMock: HttpTestingController;
+
+ beforeAll(done => (async () => {
+ TestBed.configureTestingModule({
+ imports: [HttpClientTestingModule],
+ providers: [
+ MockNgRedux,
+ PnfControlGenerator,
+ GenericFormService,
+ ControlGeneratorUtil,
+ SharedControllersService,
+ AaiService,
+ FormBuilder,
+ LogService,
+ {provide: FeatureFlagsService, useClass: MockFeatureFlagsService},
+ {provide: NgRedux, useClass: MockAppStore}]
+ });
+ await TestBed.compileComponents();
+
+ injector = getTestBed();
+ service = injector.get(PnfControlGenerator);
+ httpMock = injector.get(HttpTestingController);
+
+ })().then(done).catch(done.fail));
+
+ test('getMacroFormControls check for mandatory controls', () => {
+ const serviceId = "serviceId";
+ const pnfName = "pnfName";
+ const pnfStoreKey = "pnfStoreKey";
+ const mandatoryControls: string[] = [
+ FormControlNames.INSTANCE_NAME,
+ FormControlNames.PRODUCT_FAMILY_ID
+ ];
+
+ const controls: FormControlModel[] = service.getMacroFormControls(serviceId, pnfStoreKey, pnfName, []);
+
+ for (let i = 0; i < mandatoryControls.length; i++) {
+ let requiredExist = controls.find(ctrl => ctrl.controlName === mandatoryControls[i]).validations.find(item => item.validatorName === 'required');
+ expect(requiredExist).toBeDefined();
+ }
+ });
+
+ test('should provide empty array on getMacroFormControls when serviceId, pnfName and pnfStoreKey equals to null', () => {
+ let pnfStoreKey = null;
+ const serviceId = null;
+ const pnfName: string = null;
+
+ const controls: FormControlModel[] = service.getMacroFormControls(serviceId, pnfStoreKey, pnfName, []);
+
+ expect(controls).toEqual([]);
+ });
+
+ test('getAlacartFormControls check for mandatory controls', () => {
+ const serviceId = "serviceId";
+ const pnfName = "pnfName";
+ const pnfStoreKey = "pnfStoreKey";
+ const mandatoryControls: string[] = [
+ FormControlNames.INSTANCE_NAME,
+ 'platformName',
+ 'lineOfBusiness',
+ 'rollbackOnFailure'
+ ];
+
+ const controls: FormControlModel[] = service.getAlaCarteFormControls(serviceId, pnfStoreKey, pnfName, []);
+
+ for (let i = 0; i < mandatoryControls.length; i++) {
+ let requiredExist = controls.find(ctrl => ctrl.controlName === mandatoryControls[i]).validations.find(item => item.validatorName === 'required');
+ expect(requiredExist).toBeDefined();
+ }
+ });
+
+ test('should provide empty array on getAlaCarteFormControls when serviceId, pnfName and pnfStoreKey equals to null', () => {
+ let pnfStoreKey = null;
+ const serviceId = null;
+ const pnfName: string = null;
+
+ const result: FormControlModel[] = service.getAlaCarteFormControls(serviceId, pnfStoreKey, pnfName, []);
+
+ expect(result).toEqual([]);
+ });
+
+
+ test('getMacroFormControls should return the correct order of controls', () => {
+ const serviceId = "serviceId";
+ const pnfName = "pnfName";
+ const pnfStoreKey = "pnfStoreKey";
+ const controls: FormControlModel[] = service.getMacroFormControls(serviceId, pnfStoreKey, pnfName, []);
+
+ const controlsOrderNames = [
+ FormControlNames.INSTANCE_NAME,
+ FormControlNames.PRODUCT_FAMILY_ID,
+ 'platformName',
+ 'lineOfBusiness'];
+
+ expect(controls.length).toEqual(4);
+ for (let i = 0; i < controls.length; i++) {
+ expect(controls[i].controlName).toEqual(controlsOrderNames[i]);
+ }
+ });
+
+ test('getAlacarteFormControls should return the correct order of controls', () => {
+ const serviceId = "serviceId";
+ const pnfName = "pnfName";
+ const pnfStoreKey = "pnfStoreKey";
+ const controls: FormControlModel[] = service.getAlaCarteFormControls(serviceId, pnfStoreKey, pnfName, []);
+
+ const controlsOrderNames = [
+ FormControlNames.INSTANCE_NAME,
+ FormControlNames.PRODUCT_FAMILY_ID,
+ 'platformName',
+ 'lineOfBusiness',
+ 'rollbackOnFailure'
+ ];
+
+ expect(controls.length).toEqual(5);
+ for (let i = 0; i < controls.length; i++) {
+ expect(controls[i].controlName).toEqual(controlsOrderNames[i]);
+ }
+ });
+});
+
diff --git a/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/pnfGenerator/pnf.control.generator.ts b/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/pnfGenerator/pnf.control.generator.ts
new file mode 100644
index 000000000..7e3381701
--- /dev/null
+++ b/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/pnfGenerator/pnf.control.generator.ts
@@ -0,0 +1,87 @@
+import {Injectable} from "@angular/core";
+import {GenericFormService} from "../../generic-form.service";
+import {AaiService} from "../../../../services/aaiService/aai.service";
+import {NgRedux} from "@angular-redux/store";
+import {HttpClient} from "@angular/common/http";
+import {ControlGeneratorUtil} from "../control.generator.util.service";
+import {FormControlModel} from "../../../../models/formControlModels/formControl.model";
+import {LogService} from "../../../../utils/log/log.service";
+import {PNFModel} from "../../../../models/pnfModel";
+import {AppState} from "../../../../store/reducers";
+import * as _ from 'lodash';
+import {SharedControllersService} from "../sharedControlles/shared.controllers.service";
+
+@Injectable()
+export class PnfControlGenerator {
+ aaiService: AaiService;
+ constructor(private genericFormService: GenericFormService,
+ private _basicControlGenerator: ControlGeneratorUtil,
+ private _sharedControllersService : SharedControllersService,
+ private store: NgRedux<AppState>,
+ private http: HttpClient,
+ private _aaiService: AaiService,
+ private _logService: LogService) {
+ this.aaiService = _aaiService;
+ }
+
+ getPnfInstance = (serviceId: string, pnfStoreKey: string): any => {
+ let pnfInstance = null;
+ if (this.store.getState().service.serviceInstance[serviceId] && _.has(this.store.getState().service.serviceInstance[serviceId].pnfs, pnfStoreKey)) {
+ pnfInstance = Object.assign({}, this.store.getState().service.serviceInstance[serviceId].pnfs[pnfStoreKey]);
+ }
+ return pnfInstance;
+ };
+
+ getMacroFormControls(serviceId: string, pnfStoreKey: string, pnfName: string, dynamicInputs?: any[]): FormControlModel[] {
+ pnfStoreKey = _.isNil(pnfStoreKey) ? pnfName : pnfStoreKey;
+
+ if (_.isNil(serviceId) || _.isNil(pnfStoreKey) || _.isNil(pnfName)) {
+ this._logService.error('should provide serviceId, pnfName, pnfStoreKey', serviceId);
+ return [];
+ }
+ const pnfInstance = this._basicControlGenerator.retrieveInstanceIfUpdateMode(this.store,this.getPnfInstance(serviceId, pnfStoreKey));
+ const pnfModel = new PNFModel(this.store.getState().service.serviceHierarchy[serviceId].pnfs[pnfName]);
+ let result: FormControlModel[] = [];
+ const flags = this.store.getState().global.flags;
+
+ if (!_.isNil(pnfModel)) {
+ const isPlatformMultiSelected = flags['FLAG_2002_PNF_PLATFORM_MULTI_SELECT'];
+ const isLobMultiSelected = flags['FLAG_2006_PNF_LOB_MULTI_SELECT'];
+
+ result.push(this.getInstanceName(pnfInstance, serviceId, pnfName, pnfModel.isEcompGeneratedNaming));
+ result.push(this._sharedControllersService.getProductFamilyControl(pnfInstance, result, true));
+ result.push(this._sharedControllersService.getPlatformMultiselectControl(pnfInstance, result, isPlatformMultiSelected));
+ result.push(this._sharedControllersService.getLobMultiselectControl(pnfInstance, isLobMultiSelected));
+ }
+ return result;
+ }
+
+ getAlaCarteFormControls(serviceId: string, pnfStoreKey: string, pnfName: string, dynamicInputs?: any[]): FormControlModel[] {
+ pnfStoreKey = _.isNil(pnfStoreKey) ? pnfName : pnfStoreKey;
+ if (_.isNil(serviceId) || _.isNil(pnfStoreKey) || _.isNil(pnfName)) {
+ this._logService.error('should provide serviceId, pnfName, pnfStoreKey', serviceId);
+ return [];
+ }
+
+ let result: FormControlModel[] = [];
+ const pnfInstance = this._basicControlGenerator.retrieveInstanceIfUpdateMode(this.store,this.getPnfInstance(serviceId, pnfStoreKey));
+ const pnfModel = new PNFModel(this.store.getState().service.serviceHierarchy[serviceId].pnfs[pnfName]);
+ const flags = this.store.getState().global.flags;
+
+ if (!_.isNil(pnfModel)) {
+ const isPlatformMultiSelected = flags['FLAG_2002_VNF_PLATFORM_MULTI_SELECT'];
+ const isLobMultiSelected = flags['FLAG_2006_VNF_LOB_MULTI_SELECT'];
+ result.push(this.getInstanceName(pnfInstance, serviceId, pnfName, pnfModel.isEcompGeneratedNaming));
+ result.push(this._sharedControllersService.getProductFamilyControl(pnfInstance, result, true));
+ result.push(this._sharedControllersService.getPlatformMultiselectControl(pnfInstance, result, isPlatformMultiSelected));
+ result.push(this._sharedControllersService.getLobMultiselectControl(pnfInstance,isLobMultiSelected));
+ result.push(this._sharedControllersService.getRollbackOnFailureControl(pnfInstance));
+ }
+ return result;
+ }
+
+ getInstanceName(instance : any, serviceId : string, pnfName : string, isEcompGeneratedNaming: boolean): FormControlModel {
+ const pnfModel : PNFModel = this.store.getState().service.serviceHierarchy[serviceId].pnfs[pnfName];
+ return this._sharedControllersService.getInstanceNameController(instance, serviceId, isEcompGeneratedNaming, pnfModel);
+ }
+}