Chore: Migrate redux actions/enterpriseModules to TS (#3698)

* migrate enterpriseModules to TS

* update test file
This commit is contained in:
Gerzon Z 2022-02-16 18:10:09 -04:00 committed by GitHub
parent 352a718631
commit 5e60f58bb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 68 additions and 30 deletions

View File

@ -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
};
}

View File

@ -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
};
}

View File

@ -26,6 +26,8 @@ import { ISelectedUsers } from '../../reducers/selectedUsers';
import { IServer } from '../../reducers/server'; import { IServer } from '../../reducers/server';
import { ISettings } from '../../reducers/settings'; import { ISettings } from '../../reducers/settings';
import { IShare } from '../../reducers/share'; import { IShare } from '../../reducers/share';
import { IEnterpriseModules } from '../../reducers/enterpriseModules';
import { TActionEnterpriseModules } from '../../actions/enterpriseModules';
export interface IApplicationState { export interface IApplicationState {
settings: ISettings; settings: ISettings;
@ -45,7 +47,7 @@ export interface IApplicationState {
inviteLinks: IInviteLinks; inviteLinks: IInviteLinks;
createDiscussion: ICreateDiscussion; createDiscussion: ICreateDiscussion;
inquiry: any; inquiry: any;
enterpriseModules: any; enterpriseModules: IEnterpriseModules;
encryption: IEncryption; encryption: IEncryption;
permissions: any; permissions: any;
roles: IRoles; roles: IRoles;
@ -64,4 +66,5 @@ export type TApplicationActions = TActionActiveUsers &
TActionCreateChannel & TActionCreateChannel &
TActionsShare & TActionsShare &
TActionServer & TActionServer &
TActionApp; TActionApp &
TActionEnterpriseModules;

View File

@ -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;
}
};

View File

@ -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([]);
});
});

View File

@ -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;
}
};