summaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/shared/components/genericFormPopup
diff options
context:
space:
mode:
authorEylon Malin <eylon.malin@intl.att.com>2019-11-27 14:25:54 +0200
committerEylon Malin <eylon.malin@intl.att.com>2019-11-28 09:04:41 +0200
commitd366b643176e92a701107e81a2fe8839ec2b6d32 (patch)
tree2fef5b53aaeffeee108b6ef21df745add8cd63ba /vid-webpack-master/src/app/shared/components/genericFormPopup
parentdca4dd56b599c7ae44f8f256bd8ca8e8e05895f2 (diff)
update supplementaryFileContent at onSubmit of VfModule upgrade
Issue-ID: VID-603 Change-Id: I7fac657454de7a6d3674708c956eb099c11ad2ea Signed-off-by: Eylon Malin <eylon.malin@intl.att.com>
Diffstat (limited to 'vid-webpack-master/src/app/shared/components/genericFormPopup')
-rw-r--r--vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModule/vfModule.popuop.service.ts28
-rw-r--r--vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModuleUpgrade/vfModule.upgrade.popuop.service.ts12
-rw-r--r--vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModuleUpgrade/vfModule.upgrade.popup.service.spec.ts92
3 files changed, 92 insertions, 40 deletions
diff --git a/vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModule/vfModule.popuop.service.ts b/vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModule/vfModule.popuop.service.ts
index 9c900b77b..20336e5eb 100644
--- a/vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModule/vfModule.popuop.service.ts
+++ b/vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModule/vfModule.popuop.service.ts
@@ -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);
diff --git a/vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModuleUpgrade/vfModule.upgrade.popuop.service.ts b/vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModuleUpgrade/vfModule.upgrade.popuop.service.ts
index 576e63df5..01026867e 100644
--- a/vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModuleUpgrade/vfModule.upgrade.popuop.service.ts
+++ b/vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModuleUpgrade/vfModule.upgrade.popuop.service.ts
@@ -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);
diff --git a/vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModuleUpgrade/vfModule.upgrade.popup.service.spec.ts b/vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModuleUpgrade/vfModule.upgrade.popup.service.spec.ts
index 8d11caf5d..e20964d29 100644
--- a/vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModuleUpgrade/vfModule.upgrade.popup.service.spec.ts
+++ b/vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModuleUpgrade/vfModule.upgrade.popup.service.spec.ts
@@ -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);
});
});