summaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/shared/storeUtil/utils/global
diff options
context:
space:
mode:
authorIttay Stern <ittay.stern@att.com>2018-08-29 17:01:32 +0300
committerIttay Stern <ittay.stern@att.com>2019-02-18 18:35:30 +0200
commit6f900cc45d7dd7f97430812b86b5c1d1693c8ae3 (patch)
tree936005c364dc5a7264d6304d4777c3d83494db22 /vid-webpack-master/src/app/shared/storeUtil/utils/global
parent67d99f816cc583643c35193197594cf78d8ce60a (diff)
merge from ecomp a88f0072 - Modern UI
Issue-ID: VID-378 Change-Id: Ibcb23dd27f550cf32ce2fe0239f0f496ae014ff6 Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-webpack-master/src/app/shared/storeUtil/utils/global')
-rw-r--r--vid-webpack-master/src/app/shared/storeUtil/utils/global/global.actions.ts37
-rw-r--r--vid-webpack-master/src/app/shared/storeUtil/utils/global/global.reducers.spec.ts48
-rw-r--r--vid-webpack-master/src/app/shared/storeUtil/utils/global/global.reducers.ts29
3 files changed, 114 insertions, 0 deletions
diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/global/global.actions.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/global/global.actions.ts
new file mode 100644
index 000000000..609ec69f4
--- /dev/null
+++ b/vid-webpack-master/src/app/shared/storeUtil/utils/global/global.actions.ts
@@ -0,0 +1,37 @@
+import {Action, ActionCreator} from "redux";
+
+export enum GlobalActions {
+ UPDATE_NAME = 'UPDATE_NAME',
+ UPDATE_FLAGS = 'UPDATE_FLAGS',
+ UPDATE_DRAWING_BOARD_STATUS = 'UPDATE_DRAWING_BOARD_STATUS'
+}
+
+export interface UpdateGlobalAction extends Action {
+ name?: string;
+}
+
+export interface UpdateFlagsAction extends Action {
+ flags?: any;
+}
+
+export interface UpdateDrawingBoardStatusAction extends Action{
+ drawingBoardStatus?: any;
+}
+
+export const updateName: ActionCreator<UpdateGlobalAction> =
+ (name) => ({
+ type: GlobalActions.UPDATE_NAME,
+ name: name
+ });
+
+export const updateFlags: ActionCreator<UpdateFlagsAction> =
+ (flags) => ({
+ type: GlobalActions.UPDATE_FLAGS,
+ flags: flags
+ });
+
+export const updateDrawingBoardStatus: ActionCreator<UpdateDrawingBoardStatusAction> =
+ (drawingBoardStatus) => ({
+ type: GlobalActions.UPDATE_DRAWING_BOARD_STATUS,
+ drawingBoardStatus: drawingBoardStatus
+ });
diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/global/global.reducers.spec.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/global/global.reducers.spec.ts
new file mode 100644
index 000000000..4fc80863a
--- /dev/null
+++ b/vid-webpack-master/src/app/shared/storeUtil/utils/global/global.reducers.spec.ts
@@ -0,0 +1,48 @@
+import {GlobalActions, UpdateFlagsAction, UpdateGlobalAction, UpdateDrawingBoardStatusAction} from "./global.actions";
+import {globalReducer} from "./global.reducers";
+
+
+describe('globalReducer', () => {
+
+ test('#UPDATE_FLAGS : should update global flags', () => {
+ const flags = {
+ 'A' : 'A',
+ 'B' : 'B',
+ 'C' : 'C',
+ 'D' : 'D'
+ };
+ let flagsState = globalReducer(<any>{global : {}},
+ <UpdateFlagsAction>{
+ type: GlobalActions.UPDATE_FLAGS,
+ flags : flags
+ }).flags;
+
+ expect(flagsState).toBeDefined();
+ expect(<any>flagsState).toEqual(<any>flags);
+ });
+
+ test('#UPDATE_NAME : should update global name', () => {
+ const name = 'name';
+ let globalState = globalReducer(<any>{global : {}},
+ <UpdateGlobalAction>{
+ type: GlobalActions.UPDATE_NAME,
+ name : name
+ });
+ expect(globalState).toBeDefined();
+ expect(globalState.name).toEqual(name);
+ });
+
+ test('#UPDATE_DRAWING_BOARD_STATUS : should update global drawing board status', ()=> {
+ const drawingBoardStatus = 'EDIT';
+ let globalDrawingBoardState = globalReducer(<any>{global : {}},
+ <UpdateDrawingBoardStatusAction>{
+ type: GlobalActions.UPDATE_DRAWING_BOARD_STATUS,
+ drawingBoardStatus : drawingBoardStatus
+ });
+ expect(globalDrawingBoardState).toBeDefined();
+ expect(globalDrawingBoardState.drawingBoardStatus).toEqual(drawingBoardStatus);
+ });
+});
+
+
+
diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/global/global.reducers.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/global/global.reducers.ts
new file mode 100644
index 000000000..f9e083414
--- /dev/null
+++ b/vid-webpack-master/src/app/shared/storeUtil/utils/global/global.reducers.ts
@@ -0,0 +1,29 @@
+import {Action} from 'redux';
+import {GlobalActions, UpdateFlagsAction, UpdateGlobalAction, UpdateDrawingBoardStatusAction} from "./global.actions";
+
+export interface GlobalState {
+ name : string;
+ flags : { [key: string]: boolean };
+ drawingBoardStatus : string;
+}
+
+const initialState: GlobalState = {
+ name : null,
+ flags : null,
+ drawingBoardStatus : null
+};
+
+export const globalReducer =
+ function (state: GlobalState = initialState, action: Action): GlobalState {
+ switch (action.type) {
+ case GlobalActions.UPDATE_NAME:
+ return Object.assign(state, state, (<UpdateGlobalAction>action));
+ case GlobalActions.UPDATE_FLAGS:
+ Object.assign(state, (<UpdateFlagsAction>action));
+ return Object.assign({}, state);
+ case GlobalActions.UPDATE_DRAWING_BOARD_STATUS:
+ return Object.assign(state, state, (<UpdateDrawingBoardStatusAction>action));
+ default:
+ return state;
+ }
+ };