Chore: Migrate redux actions/enterpriseModules to TS (#3698)
* migrate enterpriseModules to TS * update test file
This commit is contained in:
parent
352a718631
commit
5e60f58bb3
|
@ -1,14 +0,0 @@
|
|||
import { ENTERPRISE_MODULES } from './actionsTypes';
|
||||
|
||||
export function setEnterpriseModules(modules) {
|
||||
return {
|
||||
type: ENTERPRISE_MODULES.SET,
|
||||
payload: modules
|
||||
};
|
||||
}
|
||||
|
||||
export function clearEnterpriseModules() {
|
||||
return {
|
||||
type: ENTERPRISE_MODULES.CLEAR
|
||||
};
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
import { Action } from 'redux';
|
||||
|
||||
import { IEnterpriseModules } from '../reducers/enterpriseModules';
|
||||
import { ENTERPRISE_MODULES } from './actionsTypes';
|
||||
|
||||
interface ISetEnterpriseModules extends Action {
|
||||
payload: IEnterpriseModules[];
|
||||
}
|
||||
|
||||
export type TActionEnterpriseModules = ISetEnterpriseModules & Action;
|
||||
|
||||
export function setEnterpriseModules(modules: IEnterpriseModules[]): ISetEnterpriseModules {
|
||||
return {
|
||||
type: ENTERPRISE_MODULES.SET,
|
||||
payload: modules
|
||||
};
|
||||
}
|
||||
|
||||
export function clearEnterpriseModules(): Action {
|
||||
return {
|
||||
type: ENTERPRISE_MODULES.CLEAR
|
||||
};
|
||||
}
|
|
@ -26,6 +26,8 @@ import { ISelectedUsers } from '../../reducers/selectedUsers';
|
|||
import { IServer } from '../../reducers/server';
|
||||
import { ISettings } from '../../reducers/settings';
|
||||
import { IShare } from '../../reducers/share';
|
||||
import { IEnterpriseModules } from '../../reducers/enterpriseModules';
|
||||
import { TActionEnterpriseModules } from '../../actions/enterpriseModules';
|
||||
|
||||
export interface IApplicationState {
|
||||
settings: ISettings;
|
||||
|
@ -45,7 +47,7 @@ export interface IApplicationState {
|
|||
inviteLinks: IInviteLinks;
|
||||
createDiscussion: ICreateDiscussion;
|
||||
inquiry: any;
|
||||
enterpriseModules: any;
|
||||
enterpriseModules: IEnterpriseModules;
|
||||
encryption: IEncryption;
|
||||
permissions: any;
|
||||
roles: IRoles;
|
||||
|
@ -64,4 +66,5 @@ export type TApplicationActions = TActionActiveUsers &
|
|||
TActionCreateChannel &
|
||||
TActionsShare &
|
||||
TActionServer &
|
||||
TActionApp;
|
||||
TActionApp &
|
||||
TActionEnterpriseModules;
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
import { ENTERPRISE_MODULES } from '../actions/actionsTypes';
|
||||
|
||||
const initialState = [];
|
||||
|
||||
export default (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case ENTERPRISE_MODULES.SET:
|
||||
return action.payload;
|
||||
case ENTERPRISE_MODULES.CLEAR:
|
||||
return initialState;
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
|
@ -0,0 +1,23 @@
|
|||
import { clearEnterpriseModules, setEnterpriseModules } from '../actions/enterpriseModules';
|
||||
import { mockedStore } from './mockedStore';
|
||||
import { IEnterpriseModules, initialState } from './enterpriseModules';
|
||||
|
||||
describe('test enterpriseModules reducer', () => {
|
||||
it('should return initial state', () => {
|
||||
const state = mockedStore.getState().enterpriseModules;
|
||||
expect(state).toEqual(initialState);
|
||||
});
|
||||
|
||||
it('should return modified store after setEnterpriseModules', () => {
|
||||
const modules = ['omnichannel-mobile-enterprise', 'livechat-enterprise'] as IEnterpriseModules[];
|
||||
mockedStore.dispatch(setEnterpriseModules(modules));
|
||||
const state = mockedStore.getState().enterpriseModules;
|
||||
expect(state).toEqual(modules);
|
||||
});
|
||||
|
||||
it('should return empty store after clearEnterpriseModules', () => {
|
||||
mockedStore.dispatch(clearEnterpriseModules());
|
||||
const state = mockedStore.getState().enterpriseModules;
|
||||
expect(state).toEqual([]);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,17 @@
|
|||
import { TActionEnterpriseModules } from '../actions/enterpriseModules';
|
||||
import { ENTERPRISE_MODULES } from '../actions/actionsTypes';
|
||||
|
||||
export type IEnterpriseModules = 'omnichannel-mobile-enterprise' | 'livechat-enterprise';
|
||||
|
||||
export const initialState: IEnterpriseModules[] = [];
|
||||
|
||||
export default (state = initialState, action: TActionEnterpriseModules): IEnterpriseModules[] => {
|
||||
switch (action.type) {
|
||||
case ENTERPRISE_MODULES.SET:
|
||||
return action.payload;
|
||||
case ENTERPRISE_MODULES.CLEAR:
|
||||
return initialState;
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue