diff --git a/app/actions/customEmojis.js b/app/actions/customEmojis.js deleted file mode 100644 index 740a936ac..000000000 --- a/app/actions/customEmojis.js +++ /dev/null @@ -1,8 +0,0 @@ -import * as types from './actionsTypes'; - -export function setCustomEmojis(emojis) { - return { - type: types.SET_CUSTOM_EMOJIS, - emojis - }; -} diff --git a/app/actions/customEmojis.ts b/app/actions/customEmojis.ts new file mode 100644 index 000000000..261fbd241 --- /dev/null +++ b/app/actions/customEmojis.ts @@ -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 + }; +} diff --git a/app/definitions/redux/index.ts b/app/definitions/redux/index.ts index f3e3c792b..54eb6e4c4 100644 --- a/app/definitions/redux/index.ts +++ b/app/definitions/redux/index.ts @@ -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; diff --git a/app/reducers/customEmojis.js b/app/reducers/customEmojis.js deleted file mode 100644 index fbdaeab80..000000000 --- a/app/reducers/customEmojis.js +++ /dev/null @@ -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; - } -} diff --git a/app/reducers/customEmojis.test.ts b/app/reducers/customEmojis.test.ts new file mode 100644 index 000000000..3f507f04c --- /dev/null +++ b/app/reducers/customEmojis.test.ts @@ -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); + }); +}); diff --git a/app/reducers/customEmojis.ts b/app/reducers/customEmojis.ts new file mode 100644 index 000000000..859d634d4 --- /dev/null +++ b/app/reducers/customEmojis.ts @@ -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; + } +}