summaryrefslogtreecommitdiffstats
path: root/vid-webpack-master
diff options
context:
space:
mode:
Diffstat (limited to 'vid-webpack-master')
-rw-r--r--vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModuleUpgrade/vfModule.upgrade.popuop.service.ts19
-rw-r--r--vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/vfModuleUpgrade/vfModule.upgrade.popup.service.spec.ts63
-rw-r--r--vid-webpack-master/src/app/shared/storeUtil/utils/general/general.reducers.ts3
3 files changed, 72 insertions, 13 deletions
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 b82074d9c..5de2da112 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
@@ -2,7 +2,7 @@ import {Injectable} from "@angular/core";
import {ITreeNode} from "angular-tree-component/dist/defs/api";
import {FormGroup} from "@angular/forms";
import {VfModulePopupServiceBase} from "../vfModule/vfModule.popuop.service";
-import {updateVFModuleField, upgradeVFModule} from "../../../../storeUtil/utils/vfModule/vfModule.actions";
+import {upgradeVFModule} from "../../../../storeUtil/utils/vfModule/vfModule.actions";
import {SharedTreeService} from "../../../../../drawingBoard/service-planning/objectsToTree/shared.tree.service";
import {NgRedux} from "@angular-redux/store";
import {AppState} from "../../../../store/reducers";
@@ -15,6 +15,7 @@ import {BasicPopupService} from "../basic.popup.service";
import {FormControlModel} from "../../../../models/formControlModels/formControl.model";
import {CheckboxFormControl} from "../../../../models/formControlModels/checkboxFormControl.model";
import {FormControlType} from "../../../../models/formControlModels/formControlTypes.enum";
+import {mergeObjectByPathAction} from "../../../../storeUtil/utils/general/general.actions";
export enum UpgradeFormControlNames {
RETAIN_VOLUME_GROUPS = 'retainVolumeGroups',
@@ -35,7 +36,7 @@ export class VfModuleUpgradePopupService extends VfModulePopupServiceBase {
}
node: ITreeNode;
- getDynamicInputs = () => [];
+ getDynamicInputs = () => null;
getControls(serviceId: string, vnfStoreKey: string, vfModuleStoreKey: string, isUpdateMode: boolean) {
let result: FormControlModel[] = [];
@@ -49,22 +50,18 @@ export class VfModuleUpgradePopupService extends VfModulePopupServiceBase {
onSubmit(that, form: FormGroup) {
const node = that.uuidData.vfModule;
const serviceInstanceId: string = that.uuidData.serviceId;
+ const vnfStoreKey = node.parent.data.vnfStoreKey;
+ const modelName = node.data.modelName;
+ const dynamicModelName = node.data.dynamicModelName;
- this._store.dispatch(upgradeVFModule(node.data.modelName, node.parent.data.vnfStoreKey, serviceInstanceId ,node.data.dynamicModelName));
+ 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);
- this.updateVFModuleField(UpgradeFormControlNames.RETAIN_VOLUME_GROUPS,node, serviceInstanceId, form);
- this.updateVFModuleField(UpgradeFormControlNames.RETAIN_ASSIGNMENTS,node, serviceInstanceId, form);
-
this.postSubmitIframeMessage(that);
this.onCancel(that, form);
}
- private updateVFModuleField(fieldName: string, node, serviceInstanceId: string, form: FormGroup) {
- this._store.dispatch(updateVFModuleField(node.data.modelName, node.parent.data.vnfStoreKey, serviceInstanceId, node.data.dynamicModelName, fieldName, form.controls[fieldName].value));
- }
-
-
getRetainVolumeGroupsControl = (): CheckboxFormControl => {
return new CheckboxFormControl({
type: FormControlType.CHECKBOX,
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 a7c8214b4..5feadeb8a 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
@@ -4,7 +4,7 @@ import {BasicControlGenerator} from "../../../genericForm/formControlsServices/b
import {AaiService} from "../../../../services/aaiService/aai.service";
import {HttpClient} from "@angular/common/http";
import {GenericFormService} from "../../../genericForm/generic-form.service";
-import {FormBuilder} from "@angular/forms";
+import {FormBuilder, FormGroup} from "@angular/forms";
import {IframeService} from "../../../../utils/iframe.service";
import {DefaultDataGeneratorService} from "../../../../services/defaultDataServiceGenerator/default.data.generator.service";
import {BasicPopupService} from "../basic.popup.service";
@@ -14,6 +14,11 @@ import {FeatureFlagsService} from "../../../../services/featureFlag/feature-flag
import {getTestBed, TestBed} from "@angular/core/testing";
import {UpgradeFormControlNames, VfModuleUpgradePopupService} from "./vfModule.upgrade.popuop.service";
import {SharedTreeService} from "../../../../../drawingBoard/service-planning/objectsToTree/shared.tree.service";
+import {AppState} from "../../../../store/reducers";
+import {instance, mock} from "ts-mockito";
+import {GeneralActions} from "../../../../storeUtil/utils/general/general.actions";
+import {VfModuleActions} from "../../../../storeUtil/utils/vfModule/vfModule.actions";
+import {ServiceActions} from "../../../../storeUtil/utils/service/service.actions";
class MockModalService<T> {
}
@@ -27,6 +32,8 @@ class MockReduxStore<T> {
getState() {
return {};
}
+
+ dispatch() {}
}
class MockFeatureFlagsService {
@@ -39,6 +46,7 @@ describe('VFModule popup service', () => {
let defaultDataGeneratorService: DefaultDataGeneratorService;
let fb: FormBuilder;
let iframeService: IframeService;
+ let store : NgRedux<AppState>;
beforeAll(done => (async () => {
TestBed.configureTestingModule({
@@ -68,6 +76,7 @@ describe('VFModule popup service', () => {
defaultDataGeneratorService = injector.get(DefaultDataGeneratorService);
fb = injector.get(FormBuilder);
iframeService = injector.get(IframeService);
+ store = injector.get(NgRedux);
})().then(done).catch(done.fail));
@@ -77,7 +86,7 @@ describe('VFModule popup service', () => {
test('get controls should return retainAssignments control with false i', ()=> {
- const controls = service.getControls();
+ const controls = service.getControls('a', 'b', 'c', true);
expect(controls.length).toEqual(2);
const retainAssignmentsControl = controls.find((control)=>{
@@ -95,4 +104,54 @@ describe('VFModule popup service', () => {
expect(retainVolumeGroup).toBeDefined();
expect(retainVolumeGroup.value).toBeTruthy();
});
+
+ test('on submit should call merge action of form value to vfModule', () => {
+
+ //given
+
+ const serviceId = "serviceId5";
+ const vnfStoreKey = 'vnfStoreKey3';
+ const modelName = 'modelA';
+ const dynamicModelName = 'dynamicModel';
+ const that = {
+ uuidData : {
+ vfModule : {
+ data : {
+ modelName,
+ dynamicModelName
+ },
+ parent : {
+ data: {
+ vnfStoreKey
+ }}},
+ serviceId
+ },
+ serviceModel: {
+ uuid : "someUuid"
+ },
+ _iframeService: {
+ removeClassCloseModal : jest.fn()
+ }
+ };
+
+ let mockFrom: FormGroup = mock(FormGroup);
+ let form = instance(mockFrom);
+ form.value = {
+ a: "value",
+ b: "another"
+ };
+
+ spyOn(store, 'dispatch');
+
+ //when
+ service.onSubmit(that, form);
+
+ //then
+ expect(store.dispatch).toBeCalledWith(
+ {type: GeneralActions.MERGE_OBJECT_BY_PATH, path: ['serviceInstance', serviceId, 'vnfs', vnfStoreKey, 'vfModules',modelName, dynamicModelName], payload:form.value});
+ 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"});
+
+ });
});
diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/general/general.reducers.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/general/general.reducers.ts
index a34322751..f87a97397 100644
--- a/vid-webpack-master/src/app/shared/storeUtil/utils/general/general.reducers.ts
+++ b/vid-webpack-master/src/app/shared/storeUtil/utils/general/general.reducers.ts
@@ -92,6 +92,9 @@ export function generalReducer(state: ServiceState, action: Action) : ServiceSta
if (targetObject) {
targetObject = _.merge(targetObject, mergeObjectByPathAction.payload);
}
+ else {
+ console.error(`Can't find object at ${mergeObjectByPathAction.path.join()}`)
+ }
return newState;
}