Merge pull request #3608 from RocketChat/origin/chore/migration-ts-redux-customEmoji

Chore: Migrate redux module customEmoji to Typescript
This commit is contained in:
Gleidson Daniel Silva 2022-01-26 12:16:10 -03:00 committed by GitHub
commit 596e8208b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 64 additions and 23 deletions

View File

@ -1,8 +0,0 @@
import * as types from './actionsTypes';
export function setCustomEmojis(emojis) {
return {
type: types.SET_CUSTOM_EMOJIS,
emojis
};
}

View File

@ -0,0 +1,17 @@
import { Action } from 'redux';
import { ICustomEmojis } from '../reducers/customEmojis';
import { SET_CUSTOM_EMOJIS } from './actionsTypes';
export interface ISetCustomEmojis extends Action {
emojis: ICustomEmojis;
}
export type TActionCustomEmojis = ISetCustomEmojis;
export function setCustomEmojis(emojis: ICustomEmojis): ISetCustomEmojis {
return {
type: SET_CUSTOM_EMOJIS,
emojis
};
}

View File

@ -1,4 +1,5 @@
import { TActionActiveUsers } from '../../actions/activeUsers';
import { TActionCustomEmojis } from '../../actions/customEmojis';
import { TActionEncryption } from '../../actions/encryption';
import { TActionInviteLinks } from '../../actions/inviteLinks';
import { IActionRoles } from '../../actions/roles';
@ -36,4 +37,10 @@ export interface IApplicationState {
roles: IRoles;
}
export type TApplicationActions = TActionActiveUsers & TActionSelectedUsers & TActionEncryption& TActionInviteLinks & IActionRoles & IActionSettings;
export type TApplicationActions = TActionActiveUsers &
TActionSelectedUsers &
TActionCustomEmojis &
TActionInviteLinks &
IActionRoles &
IActionSettings &
TActionEncryption;

View File

@ -1,14 +0,0 @@
import { SET_CUSTOM_EMOJIS } from '../actions/actionsTypes';
const initialState = {
customEmojis: {}
};
export default function customEmojis(state = initialState, action) {
switch (action.type) {
case SET_CUSTOM_EMOJIS:
return action.emojis;
default:
return state;
}
}

View File

@ -0,0 +1,16 @@
import { setCustomEmojis } from '../actions/customEmojis';
import { ICustomEmojis, initialState } from './customEmojis';
import { mockedStore } from './mockedStore';
describe('test reducer', () => {
it('should return initial state', () => {
const state = mockedStore.getState().customEmojis;
expect(state).toEqual(initialState);
});
it('should return modified store after action', () => {
const emojis: ICustomEmojis = { dog: { name: 'dog', extension: 'jpg' }, cat: { name: 'cat', extension: 'jpg' } };
mockedStore.dispatch(setCustomEmojis(emojis));
const state = mockedStore.getState().customEmojis;
expect(state).toEqual(emojis);
});
});

View File

@ -0,0 +1,23 @@
import { SET_CUSTOM_EMOJIS } from '../actions/actionsTypes';
import { TApplicationActions } from '../definitions';
// There are at least three interfaces for emoji, but none of them includes only this data.
interface IEmoji {
name: string;
extension: string;
}
export interface ICustomEmojis {
[key: string]: IEmoji;
}
export const initialState: ICustomEmojis = {};
export default function customEmojis(state = initialState, action: TApplicationActions): ICustomEmojis {
switch (action.type) {
case SET_CUSTOM_EMOJIS:
return action.emojis;
default:
return state;
}
}