update supplementaryFileContent at onSubmit of VfModule upgrade 15/98915/2
authorEylon Malin <eylon.malin@intl.att.com>
Wed, 27 Nov 2019 12:25:54 +0000 (14:25 +0200)
committerEylon Malin <eylon.malin@intl.att.com>
Thu, 28 Nov 2019 07:04:41 +0000 (09:04 +0200)
Issue-ID: VID-603
Change-Id: I7fac657454de7a6d3674708c956eb099c11ad2ea
Signed-off-by: Eylon Malin <eylon.malin@intl.att.com>
vid-app-common/src/test/resources/payload_jsons/vfmodule/upgrade_vfmodule_e2e__fe_input_cypress.json
vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/basic.control.generator.ts
vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModule/vfModule.popuop.service.ts
vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModuleUpgrade/vfModule.upgrade.popuop.service.ts
vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModuleUpgrade/vfModule.upgrade.popup.service.spec.ts

index e7a6405..748b5f2 100644 (file)
             "platformName": null,
             "trackById": "b0732bed-3ddf-43cc-b193-7f18db84e476",
             "isBase": true,
-            "volumeGroupName": null
+            "volumeGroupName": null,
+            "supplementaryFile": null,
+            "supplementaryFile_hidden": null,
+            "supplementaryFile_hidden_content" : null
           }
         }
       },
index 3e94b4b..7ab6475 100644 (file)
@@ -1,12 +1,7 @@
 import {Injectable} from "@angular/core";
 import {DropdownFormControl} from "../../../models/formControlModels/dropdownFormControl.model";
 import {FormGroup} from "@angular/forms";
-import {
-  CustomValidatorOptions,
-  FormControlModel,
-  ValidatorModel,
-  ValidatorOptions
-} from "../../../models/formControlModels/formControl.model";
+import {CustomValidatorOptions, FormControlModel, ValidatorModel, ValidatorOptions} from "../../../models/formControlModels/formControl.model";
 import {InputFormControl} from "../../../models/formControlModels/inputFormControl.model";
 import {AppState} from "../../../store/reducers";
 import {NgRedux} from "@angular-redux/store";
@@ -24,7 +19,7 @@ import {Constants} from "../../../utils/constants";
 import {FileUnit} from "../../formControls/component/file/fileUnit.enum";
 import {CheckboxFormControl} from "../../../models/formControlModels/checkboxFormControl.model";
 
-const SUPPLEMENTARY_FILE = 'supplementaryFile';
+export const SUPPLEMENTARY_FILE = 'supplementaryFile';
 export const SDN_C_PRE_LOAD = 'sdncPreLoad';
 
 @Injectable()
index 9c900b7..20336e5 100644 (file)
@@ -137,6 +137,20 @@ export abstract class VfModulePopupServiceBase {
       }
     );
   }
+
+  updateFormValueWithSupplementaryFile(form: FormGroup, that) {
+    if (!_.isNil(form.controls['supplementaryFile_hidden_content']) && form.controls['supplementaryFile_hidden_content'].value) {
+      form.value['supplementaryFileContent'] = JSON.parse(form.controls['supplementaryFile_hidden_content'].value);
+      if (!_.isNil(form.controls['supplementaryFile_hidden'].value)) {
+        form.value['supplementaryFileName'] = form.controls['supplementaryFile_hidden'].value.name;
+      } else {
+        form.value['supplementaryFileName'] = that.instance.supplementaryFileName;
+      }
+    } else {
+      delete form.value['supplementaryFileContent'];
+      delete form.value['supplementaryFileName'];
+    }
+  }
 }
 
 @Injectable()
@@ -184,19 +198,7 @@ export class VfModulePopuopService extends VfModulePopupServiceBase implements G
 
   onSubmit(that, form: FormGroup) {
     form.value['instanceParams'] = form.value['instanceParams'] && [form.value['instanceParams']];
-    if (!_.isNil(form.controls['supplementaryFile_hidden_content']) && form.controls['supplementaryFile_hidden_content'].value) {
-      form.value['supplementaryFileContent'] = JSON.parse(form.controls['supplementaryFile_hidden_content'].value);
-      if (!_.isNil(form.controls['supplementaryFile_hidden'].value)) {
-        form.value['supplementaryFileName'] = form.controls['supplementaryFile_hidden'].value.name;
-      }
-      else {
-        form.value['supplementaryFileName'] = that.instance.supplementaryFileName;
-      }
-    }
-    else {
-      delete form.value['supplementaryFileContent'];
-      delete form.value['supplementaryFileName'];
-    }
+    this.updateFormValueWithSupplementaryFile(form, that);
     that.storeVFModule(that, form.value);
     this.postSubmitIframeMessage(that);
     this.onCancel(that, form);
index 576e63d..0102686 100644 (file)
@@ -40,12 +40,16 @@ export class VfModuleUpgradePopupService extends VfModulePopupServiceBase {
 
   getDynamicInputs = () => null;
 
-  getControls = (): FormControlModel[] => {
-    return [
+  getControls(serviceId: string, vnfStoreKey: string, vfModuleStoreKey: string, isUpdateMode: boolean)  {
+    let result: FormControlModel[] =[
       this.getRetainAssignmentsControl(),
       this.getRetainVolumeGroupsControl(),
       this._basicControlGenerator.getSDNCControl(null)
-    ]
+    ];
+
+    const vfModuleInstance = this._vfModuleControlGenerator.getVfModuleInstance(serviceId, vnfStoreKey, this.uuidData, isUpdateMode);
+    result = this._basicControlGenerator.concatSupplementaryFile(result, vfModuleInstance);
+    return result;
   };
 
   getTitle = (): string => 'Upgrade Module';
@@ -57,6 +61,8 @@ export class VfModuleUpgradePopupService extends VfModulePopupServiceBase {
     const modelName = node.data.modelName;
     const dynamicModelName = node.data.dynamicModelName;
 
+    this.updateFormValueWithSupplementaryFile(form, that);
+
     this._store.dispatch(upgradeVFModule(modelName, vnfStoreKey, serviceInstanceId, dynamicModelName));
     this._store.dispatch(mergeObjectByPathAction(['serviceInstance', serviceInstanceId, 'vnfs', vnfStoreKey, 'vfModules', modelName, dynamicModelName], form.value));
     this._sharedTreeService.upgradeBottomUp(node, serviceInstanceId);
index 8d11caf..e20964d 100644 (file)
@@ -1,6 +1,6 @@
 import {LogService} from "../../../../utils/log/log.service";
 import {NgRedux} from "@angular-redux/store";
-import {BasicControlGenerator} from "../../../genericForm/formControlsServices/basic.control.generator";
+import {BasicControlGenerator, SDN_C_PRE_LOAD, SUPPLEMENTARY_FILE} from "../../../genericForm/formControlsServices/basic.control.generator";
 import {AaiService} from "../../../../services/aaiService/aai.service";
 import {HttpClient} from "@angular/common/http";
 import {GenericFormService} from "../../../genericForm/generic-form.service";
@@ -26,8 +26,20 @@ class MockAppStore<T> {}
 
 class MockReduxStore<T> {
   getState() {
-    return {};
+    return {
+      service: {
+        serviceInstance : {
+          serviceId : {
+            vnfs : {
+              vnfStoreKey : {
+                vfModules: {
+                  vfModuleName: {
+                    vfModuleId : {
+                      supplementaryFileName: "myFileName"
+                    }}}}}}}}
+    };
   }
+
   dispatch() {}
 }
 
@@ -71,33 +83,53 @@ describe('VFModule popup service', () => {
     fb = injector.get(FormBuilder);
     iframeService = injector.get(IframeService);
     store = injector.get(NgRedux);
+    service.uuidData = {
+      modelName: 'vfModuleName',
+      vFModuleStoreKey: 'vfModuleId'
+    };
+
   })().then(done).catch(done.fail));
 
   test('getTitle should return the correct title', () => {
     expect(service.getTitle()).toBe("Upgrade Module")
   });
 
-  test('get controls should return retainAssignments control with true i', ()=> {
+  function findControlByName(controls, controlName) {
+    return controls.find((control) => {
+      return control.controlName === controlName;
+    });
+  }
+
+  function getControlByNameAndCheckValue(controlName, expectedValue ) {
+    const controls = service.getControls('serviceId', 'vnfStoreKey', 'vfModuleId', true);
+    const control = findControlByName(controls, controlName);
+    expect(control).toBeDefined();
+    expect(control.value).toEqual(expectedValue);
+  }
 
-    const controls = service.getControls();
-    expect(controls.length).toEqual(3);
+  test('get controls should return retainAssignments control with true value', ()=> {
+    getControlByNameAndCheckValue(UpgradeFormControlNames.RETAIN_ASSIGNMENTS, true);
+  });
 
-    const retainAssignmentsControl = controls.find((control)=>{
-      return control.controlName === UpgradeFormControlNames.RETAIN_ASSIGNMENTS;
-    });
+  test('get controls should return retainVolumeGroup control with true value', ()=> {
+    getControlByNameAndCheckValue(UpgradeFormControlNames.RETAIN_VOLUME_GROUPS, true);
+  });
 
-    expect(retainAssignmentsControl).toBeDefined();
-    expect(retainAssignmentsControl.value).toBeTruthy();
+  test('get controls should contain SUPPLEMENTARY_FILE controller', ()=> {
 
-    const retainVolumeGroup = controls.find((control)=>{
-      return control.controlName === UpgradeFormControlNames.RETAIN_VOLUME_GROUPS;
-    });
+    //when
+    const controls = service.getControls('serviceId', 'vnfStoreKey', 'vfModuleId', true);
 
-    expect(retainVolumeGroup).toBeDefined();
-    expect(retainVolumeGroup.value).toBeTruthy();
+    //then
+    const control = findControlByName(controls, SUPPLEMENTARY_FILE);
+    expect(control).toBeDefined();
+    expect(control.selectedFile).toBe("myFileName");
   });
 
   test('on submit should call merge action of form value to vfModule', () => {
+
+    //given
+
     const serviceId = "serviceId5";
     const vnfStoreKey = 'vnfStoreKey3';
     const modelName = 'modelA';
@@ -125,10 +157,27 @@ describe('VFModule popup service', () => {
 
     let mockFrom: FormGroup = mock(FormGroup);
     let form = instance(mockFrom);
-    form.setValue({
+    form.value = {
       a: "value",
       b: "another"
-    });
+    };
+    form.controls = {
+      supplementaryFile_hidden_content : {
+        value: '{"c": "c", "d": 1}'
+        },
+      supplementaryFile_hidden : {
+        value: {
+          name: "name"
+        }
+      }
+    };
+
+    let expectedMergePayload = {
+      a: "value",
+      b: "another",
+      supplementaryFileContent: {c: "c", d: 1},
+      supplementaryFileName: "name"
+    };
 
     spyOn(store, 'dispatch');
 
@@ -137,7 +186,7 @@ describe('VFModule popup service', () => {
 
     //then
     expect(store.dispatch).toBeCalledWith(
-      {type: GeneralActions.MERGE_OBJECT_BY_PATH, path: ['serviceInstance', serviceId, 'vnfs', vnfStoreKey, 'vfModules',modelName, dynamicModelName], payload:form.value});
+      {type: GeneralActions.MERGE_OBJECT_BY_PATH, path: ['serviceInstance', serviceId, 'vnfs', vnfStoreKey, 'vfModules',modelName, dynamicModelName], payload:expectedMergePayload});
     expect(store.dispatch).toBeCalledWith(
       {type: VfModuleActions.UPGRADE_VFMODULE, dynamicModelName: "dynamicModel", modelName: "modelA", serviceId: "serviceId5", vnfStoreKey: "vnfStoreKey3"});
     expect(store.dispatch).toBeCalledWith({type: ServiceActions.UPGRADE_SERVICE_ACTION, serviceUuid: "serviceId5"});
@@ -146,11 +195,6 @@ describe('VFModule popup service', () => {
 
 
   test( 'get controls should return usePreload with false value', () => {
-    const controls = service.getControls();
-    const usePreloadControl = controls.find((control)=>{
-      return control.controlName === 'sdncPreLoad';
-    });
-    expect(usePreloadControl).toBeDefined();
-    expect(usePreloadControl.value).toBeFalsy();
+    getControlByNameAndCheckValue(SDN_C_PRE_LOAD, false);
   });
 });