summaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app
diff options
context:
space:
mode:
Diffstat (limited to 'vid-webpack-master/src/app')
-rw-r--r--vid-webpack-master/src/app/shared/storeUtil/utils/general/general.actions.ts12
-rw-r--r--vid-webpack-master/src/app/shared/storeUtil/utils/general/general.reducers.spec.ts53
-rw-r--r--vid-webpack-master/src/app/shared/storeUtil/utils/general/general.reducers.ts19
3 files changed, 64 insertions, 20 deletions
diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/general/general.actions.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/general/general.actions.ts
index 7a10eba0a..79dd3c717 100644
--- a/vid-webpack-master/src/app/shared/storeUtil/utils/general/general.actions.ts
+++ b/vid-webpack-master/src/app/shared/storeUtil/utils/general/general.actions.ts
@@ -5,6 +5,7 @@ import {ServiceType} from "../../../models/serviceType";
import {ITreeNode} from "angular-tree-component/dist/defs/api";
export enum GeneralActions {
+ MERGE_OBJECT_BY_PATH = "MERGE_OBJECT_BY_PATH",
UPDATE_LCP_REGIONS_AND_TENANTS = "UPDATE_LCP_REGIONS_AND_TENANTS",
UPDATE_SUBSCRIBERS = "UPDATE_SUBSCRIBERS",
UPDATE_PRODUCT_FAMILIES = "UPDATE_PRODUCT_FAMILIES",
@@ -78,6 +79,11 @@ export interface UpdateServiceTypesAction extends Action {
subscriberId: string;
}
+export interface MergeObjectByPathAction extends Action{
+ path: String[];
+ payload: object;
+}
+
export const updateLcpRegionsAndTenants: ActionCreator<UpdateLcpRegionsAndTenantsAction> = lcpRegionsAndTenants => ({
type: GeneralActions.UPDATE_LCP_REGIONS_AND_TENANTS,
lcpRegionsAndTenants: lcpRegionsAndTenants
@@ -147,4 +153,10 @@ export const updateServiceTypes: ActionCreator<UpdateServiceTypesAction> = (serv
subscriberId: subscriberId
});
+export const mergeObjectByPathAction : ActionCreator<MergeObjectByPathAction> = (path, payload) => ({
+ type: GeneralActions.MERGE_OBJECT_BY_PATH,
+ path,
+ payload
+});
+
diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/general/general.reducers.spec.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/general/general.reducers.spec.ts
index ed456314e..952a92842 100644
--- a/vid-webpack-master/src/app/shared/storeUtil/utils/general/general.reducers.spec.ts
+++ b/vid-webpack-master/src/app/shared/storeUtil/utils/general/general.reducers.spec.ts
@@ -1,22 +1,12 @@
import {LcpRegion} from "../../../models/lcpRegion";
import {Tenant} from "../../../models/tenant";
import {generalReducer} from "./general.reducers";
-import {
- ChangeInstanceCounterAction,
- RemoveInstanceAction,
- DuplicateBulkInstancesAction,
- GeneralActions,
- UpdateAicZonesAction,
- UpdateCategoryParametersAction,
- UpdateProductFamiliesAction,
- UpdateServiceTypesAction,
- UpdateSubscribersAction,
- UpdateUserIdAction, UpdateNetworkCollectionFunction,
-} from "./general.actions";
+import {ChangeInstanceCounterAction, DuplicateBulkInstancesAction, GeneralActions, MergeObjectByPathAction, RemoveInstanceAction, UpdateAicZonesAction, UpdateCategoryParametersAction, UpdateNetworkCollectionFunction, UpdateProductFamiliesAction, UpdateServiceTypesAction, UpdateSubscribersAction, UpdateUserIdAction,} from "./general.actions";
import {SelectOption} from "../../../models/selectOption";
import {ServiceType} from "../../../models/serviceType";
import {ITreeNode} from "angular-tree-component/dist/defs/api";
import {VnfInstance} from "../../../models/vnfInstance";
+import each from "jest-each";
describe('generalReducer', () => {
test('#UPDATE_LCP_REGIONS_AND_TENANTS : should update lcp region and tenants', () => {
@@ -370,6 +360,45 @@ describe('generalReducer', () => {
expect(state).toBeDefined();
expect(state['networkFunctions']).toBeDefined();
});
+
+ const originalMockObject = {
+ remain: 'forever',
+ obsolete: 'toBeChange'
+ };
+
+ each([
+ [
+ ['serviceInstance', 'serviceModelId', 'vnfs'],
+ {
+ remain: 'forever',
+ obsolete: 'newValue',
+ newField: 'newValue2'
+ }
+ ],
+ [
+ ['serviceInstance', 'nowhere', 'somewhere'],
+ originalMockObject
+ ],
+ ]).
+ test('#MERGE_OBJECT_BY_PATH: should update some object by path %s', (path, expected) => {
+ let state = generalReducer(<any>{serviceInstance : {
+ 'serviceModelId' : {
+ vnfs : originalMockObject,
+ existingVNFCounterMap : {}
+ }
+ }},
+ <MergeObjectByPathAction>{
+ type: GeneralActions.MERGE_OBJECT_BY_PATH,
+ path,
+ payload: {
+ obsolete: 'newValue',
+ newField: 'newValue2'
+ }
+ });
+
+ expect(state).toBeDefined();
+ expect(state.serviceInstance['serviceModelId'].vnfs).toEqual(expected);
+ });
});
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 5b265dbfd..a34322751 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
@@ -1,12 +1,5 @@
import {Action} from "redux";
-import {
- ChangeInstanceCounterAction, RemoveInstanceAction, DuplicateBulkInstancesAction,
- GeneralActions,
- UpdateAicZonesAction, UpdateCategoryParametersAction,
- UpdateLcpRegionsAndTenantsAction, UpdateNetworkCollectionFunction,
- UpdateProductFamiliesAction, UpdateServiceTypesAction,
- UpdateSubscribersAction, UpdateUserIdAction
-} from "./general.actions";
+import {ChangeInstanceCounterAction, DuplicateBulkInstancesAction, GeneralActions, MergeObjectByPathAction, RemoveInstanceAction, UpdateAicZonesAction, UpdateCategoryParametersAction, UpdateLcpRegionsAndTenantsAction, UpdateNetworkCollectionFunction, UpdateProductFamiliesAction, UpdateServiceTypesAction, UpdateSubscribersAction, UpdateUserIdAction} from "./general.actions";
import {TypeNodeInformation} from "../../../../drawingBoard/service-planning/typeNodeInformation.model";
import * as _ from "lodash";
import {ITreeNode} from "angular-tree-component/dist/defs/api";
@@ -92,6 +85,16 @@ export function generalReducer(state: ServiceState, action: Action) : ServiceSta
return newState;
}
+ case GeneralActions.MERGE_OBJECT_BY_PATH : {
+ const mergeObjectByPathAction = <MergeObjectByPathAction>action;
+ let newState = _.cloneDeep(state);
+ let targetObject = _.get(newState, <any>mergeObjectByPathAction.path);
+ if (targetObject) {
+ targetObject = _.merge(targetObject, mergeObjectByPathAction.payload);
+ }
+ return newState;
+ }
+
}
}