From 76c41474a6eb2b92f875513f8108242034c00980 Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Wed, 8 Mar 2023 14:36:49 -0300 Subject: [PATCH] create videoConf reducer --- app/reducers/index.js | 4 ++- app/reducers/videoConf.test.ts | 48 ++++++++++++++++++++++++++++++++++ app/reducers/videoConf.ts | 33 +++++++++++++++++++++++ 3 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 app/reducers/videoConf.test.ts create mode 100644 app/reducers/videoConf.ts diff --git a/app/reducers/index.js b/app/reducers/index.js index 7aad41aa0..1e05aa24c 100644 --- a/app/reducers/index.js +++ b/app/reducers/index.js @@ -21,6 +21,7 @@ import enterpriseModules from './enterpriseModules'; import encryption from './encryption'; import permissions from './permissions'; import roles from './roles'; +import videoConf from './videoConf'; export default combineReducers({ settings, @@ -43,5 +44,6 @@ export default combineReducers({ enterpriseModules, encryption, permissions, - roles + roles, + videoConf }); diff --git a/app/reducers/videoConf.test.ts b/app/reducers/videoConf.test.ts new file mode 100644 index 000000000..3d5f9f3f2 --- /dev/null +++ b/app/reducers/videoConf.test.ts @@ -0,0 +1,48 @@ +import { clearVideoConfCalls, removeVideoConfCall, setVideoConfCall } from '../actions/videoConf'; +import { mockedStore } from './mockedStore'; +import { initialState, ICallInfo } from './videoConf'; + +describe('test videoConf reducer', () => { + it('should return initial state', () => { + const state = mockedStore.getState().settings; + expect(state).toEqual(initialState); + }); + + const call1: ICallInfo = { + callId: '123', + rid: '123', + type: 'accepted', + uid: '123' + }; + + const call2: ICallInfo = { + callId: '321', + rid: '321', + type: 'accepted', + uid: '321' + }; + + it('should return call1 after call addSettings action with call1 as parameter', () => { + mockedStore.dispatch(setVideoConfCall(call1)); + const state = mockedStore.getState().videoConf; + expect(state[call1.callId]).toEqual(call1); + }); + + it('should return call2 after call addSettings action with call2 as parameter', () => { + mockedStore.dispatch(setVideoConfCall(call2)); + const state = mockedStore.getState().videoConf; + expect(state[call2.callId]).toEqual(call2); + }); + + it('should remove call1 after call removeVideoConfCall action with call1 as parameter', () => { + mockedStore.dispatch(removeVideoConfCall(call1)); + const state = mockedStore.getState().videoConf; + expect(state[call1.callId]).toEqual(undefined); + }); + + it('should return initial state after clearSettings', () => { + mockedStore.dispatch(clearVideoConfCalls()); + const state = mockedStore.getState().videoConf; + expect(state).toEqual({}); + }); +}); diff --git a/app/reducers/videoConf.ts b/app/reducers/videoConf.ts new file mode 100644 index 000000000..7a1328e09 --- /dev/null +++ b/app/reducers/videoConf.ts @@ -0,0 +1,33 @@ +import { VIDEO_CONF } from '../actions/actionsTypes'; +import { TActionVideoConf } from '../actions/videoConf'; + +export type TSupportedCallStatus = 'call' | 'canceled' | 'accepted' | 'rejected' | 'confirmed' | 'join' | 'end'; + +export interface ICallInfo { + callId: string; + rid: string; + uid: string; + type: TSupportedCallStatus; +} + +interface ICallInfoRecord { + [key: string]: ICallInfo; +} + +export const initialState: ICallInfoRecord = {}; + +export default (state = initialState, action: TActionVideoConf): ICallInfoRecord => { + switch (action.type) { + case VIDEO_CONF.SET: + return { + ...state, + [action.payload.callId]: action.payload + }; + case VIDEO_CONF.REMOVE: + return Object.fromEntries(Object.entries(state).filter(([key]) => key !== action.payload.callId)); + case VIDEO_CONF.CLEAR: + return initialState; + default: + return state; + } +};