From b4af2036941854aa45aa9d53e06bd92de5a842d3 Mon Sep 17 00:00:00 2001 From: Alexey Sandler Date: Sun, 26 Apr 2020 16:23:57 +0300 Subject: Can't delete the second vfModule in drawing board - fix. Given two vfModules created under the same vnf, when try to delete the second vfModule its status not updated to deleted. Issue-ID: VID-819 Signed-off-by: Alexey Sandler Change-Id: Ie0c349d78940161d66a125782d917d28988e3c9d Signed-off-by: Alexey Sandler --- .../storeUtil/utils/vfModule/vfModule.actions.ts | 6 ++- .../utils/vfModule/vfModule.reducers.spec.ts | 51 +++++++++++++--------- .../storeUtil/utils/vfModule/vfModule.reducers.ts | 21 ++++----- 3 files changed, 44 insertions(+), 34 deletions(-) (limited to 'vid-webpack-master/src/app/shared/storeUtil') diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.actions.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.actions.ts index 1b80452cb..ac26ba936 100644 --- a/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.actions.ts +++ b/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.actions.ts @@ -49,6 +49,7 @@ export interface DeleteActionVfModuleInstanceAction extends Action { dynamicModelName: string; vnfStoreKey : string; serviceId?: string; + vfModuleModelName: string; } export interface UpgradeVfModuleInstanceAction extends Action { @@ -115,11 +116,12 @@ export const updateVFModuleInstance: ActionCreator vnfStoreKey : vnfStoreKey }); -export const deleteActionVfModuleInstance: ActionCreator = (dynamicModelName, vnfStoreKey, serviceId) => ({ +export const deleteActionVfModuleInstance: ActionCreator = (dynamicModelName, vnfStoreKey, serviceId, vfModuleModelName) => ({ type: VfModuleActions.DELETE_ACTION_VF_MODULE_INSTANCE, dynamicModelName: dynamicModelName, vnfStoreKey : vnfStoreKey, - serviceId: serviceId + serviceId: serviceId, + vfModuleModelName }); export const undoDeleteVfModuleInstance: ActionCreator = (dynamicModelName, vnfStoreKey, serviceId) => ({ diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.reducers.spec.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.reducers.spec.ts index 9ef440fc5..9bbcf46f7 100644 --- a/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.reducers.spec.ts +++ b/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.reducers.spec.ts @@ -1,15 +1,18 @@ import { CreateVFModuleInstanceAction, - DeleteActionVfModuleInstanceAction, DeleteVFModuleField, + DeleteActionVfModuleInstanceAction, + DeleteVFModuleField, DeleteVfModuleInstanceAction, UndoDeleteActionVfModuleInstanceAction, - UpdateVFModluePosition, UpdateVFModuleField, + UpdateVFModluePosition, + UpdateVFModuleField, UpgradeVfModuleInstanceAction, VfModuleActions } from "./vfModule.actions"; import {vfModuleReducer} from "./vfModule.reducers"; import {VfModuleInstance} from "../../../models/vfModuleInstance"; import {ServiceInstanceActions} from "../../../models/serviceInstanceActions"; +import each from "jest-each"; describe('vfModuleReducer', () => { @@ -114,12 +117,12 @@ describe('vfModuleReducer', () => { dynamicModelName: 'dynamicModelName1', vnfStoreKey: 'vnfStoreKey', serviceId: 'serviceModelId', - modelName: 'modelName', + modelName: 'vfModuleModelName', fieldName: newFieldName, fieldValue: newFieldValue }); - let vfModule = newState.serviceInstance['serviceModelId'].vnfs['vnfStoreKey'].vfModules['modelName']['dynamicModelName1']; + let vfModule = newState.serviceInstance['serviceModelId'].vnfs['vnfStoreKey'].vfModules['vfModuleModelName']['dynamicModelName1']; expect(vfModule[newFieldName]).toEqual(newFieldValue); }); @@ -200,18 +203,22 @@ test('#UPDATE_VFMODULE_POSITION: should update position', () => { expect(vfModule.position).toEqual(1); }); -test('#DELETE_ACTION_VF_MODULE_INSTANCE', () => { - let vfModule = vfModuleReducer(getReduxState(), getDeleteActionVfModule()) - .serviceInstance['serviceModelId'].vnfs['vnfStoreKey'].vfModules['modelName']['dynamicModelName1']; + each([ + ['for the first vfModule', 'dynamicModelName1', true], + ['for the second vfModule', 'dynamicModelName2', true], + ]). +test('#DELETE_ACTION_VF_MODULE_INSTANCE %s', (description, dynamicModelName: string, isMissingData: boolean) => { + let vfModule = vfModuleReducer(getReduxState(), getDeleteActionVfModule(dynamicModelName)) + .serviceInstance['serviceModelId'].vnfs['vnfStoreKey'].vfModules['vfModuleModelName'][dynamicModelName]; - expect(vfModule).toBeDefined(); - expect(vfModule.isMissingData).toBeTruthy(); - expect(vfModule.action).toEqual(ServiceInstanceActions.None_Delete); -}); + expect(vfModule).toBeDefined(); + expect(vfModule.isMissingData).toBeTruthy(); + expect(vfModule.action).toEqual(ServiceInstanceActions.None_Delete); + }); test('#DELETE_ACTION_VF_MODULE_INSTANCE set tenantId and lcpCloudRegion to VFM', () => { - let vfModule = vfModuleReducer(getReduxState(), getDeleteActionVfModule()) - .serviceInstance['serviceModelId'].vnfs['vnfStoreKey'].vfModules['modelName']['dynamicModelName1']; + let vfModule = vfModuleReducer(getReduxState(), getDeleteActionVfModule('dynamicModelName1')) + .serviceInstance['serviceModelId'].vnfs['vnfStoreKey'].vfModules['vfModuleModelName']['dynamicModelName1']; expect(vfModule).toBeDefined(); expect(vfModule.tenantId).toEqual('tenantId'); @@ -260,8 +267,8 @@ test('#UPGRADE_VFMODULE', () => { dynamicModelName: 'dynamicModelName1', vnfStoreKey: 'vnfStoreKey', serviceId: 'serviceModelId', - modelName: 'modelName' - }).serviceInstance['serviceModelId'].vnfs['vnfStoreKey'].vfModules['modelName']['dynamicModelName1']; + modelName: 'vfModuleModelName' + }).serviceInstance['serviceModelId'].vnfs['vnfStoreKey'].vfModules['vfModuleModelName']['dynamicModelName1']; expect(vfModule.action).toEqual(ServiceInstanceActions.None_Upgrade); }); @@ -312,12 +319,15 @@ function getReduxState() { tenantId: 'tenantId', lcpCloudRegionId: 'lcpCloudRegionId', vfModules: { - 'modelName': { + 'vfModuleModelName': { 'dynamicModelName1': { isMissingData: true, action: 'None', }, - 'dynamicModelName2': {}, + 'dynamicModelName2': { + action: 'None', + isMissingData: true, + }, } } } @@ -327,12 +337,13 @@ function getReduxState() { } } -function getDeleteActionVfModule() { +function getDeleteActionVfModule(dynamicModelName?: string) { return { type: VfModuleActions.DELETE_ACTION_VF_MODULE_INSTANCE, - dynamicModelName: 'dynamicModelName1', + dynamicModelName: dynamicModelName, vnfStoreKey: 'vnfStoreKey', - serviceId: 'serviceModelId' + serviceId: 'serviceModelId', + vfModuleModelName: 'vfModuleModelName', } } }); diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.reducers.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.reducers.ts index 1ab275e05..9c624b055 100644 --- a/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.reducers.ts +++ b/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.reducers.ts @@ -70,20 +70,17 @@ export function vfModuleReducer(state: ServiceState , action: Action) : ServiceS return Object.assign({}, state); } case VfModuleActions.DELETE_ACTION_VF_MODULE_INSTANCE : { + let deleteAction = (action); let newState = _.cloneDeep(state); - let vfModules = newState.serviceInstance[(action).serviceId].vnfs[(action).vnfStoreKey].vfModules; + let vfModule = newState.serviceInstance[deleteAction.serviceId].vnfs[deleteAction.vnfStoreKey] + .vfModules[deleteAction.vfModuleModelName][deleteAction.dynamicModelName]; + let oldAction = vfModule.action; + if (oldAction === ServiceInstanceActions.None_Delete || oldAction === ServiceInstanceActions.Update_Delete) return newState; + newState.serviceInstance[deleteAction.serviceId].vnfs[deleteAction.vnfStoreKey] + .vfModules[deleteAction.vfModuleModelName][deleteAction.dynamicModelName].action = (oldAction + '_Delete') as ServiceInstanceActions; + setLcpCloudRegionIdAndTenantIdFromVnf(newState, deleteAction.serviceId, deleteAction.vnfStoreKey, deleteAction.vfModuleModelName, deleteAction.dynamicModelName); + updateIsMissingDataOnDeleteVFModule(newState, (action).serviceId, (action).vnfStoreKey, deleteAction.vfModuleModelName); - for(let key in vfModules){ - let firstKey = Object.keys(vfModules[key])[0]; - if(firstKey === (action).dynamicModelName){ - let oldAction = newState.serviceInstance[(action).serviceId].vnfs[(action).vnfStoreKey].vfModules[key][firstKey].action; - if(oldAction === ServiceInstanceActions.None_Delete || oldAction === ServiceInstanceActions.Update_Delete) return newState; - newState.serviceInstance[(action).serviceId].vnfs[(action).vnfStoreKey].vfModules[key][firstKey].action = (oldAction + '_Delete') as ServiceInstanceActions; - setLcpCloudRegionIdAndTenantIdFromVnf(newState, (action).serviceId, (action).vnfStoreKey, key, firstKey); - updateIsMissingDataOnDeleteVFModule(newState, (action).serviceId, (action).vnfStoreKey, key); - return newState; - } - } return newState; } case VfModuleActions.UNDO_DELETE_ACTION_VF_MODULE_INSTANCE : { -- cgit 1.2.3-korg