From 506c9555cee90d869e4ceaa36c2c456cc89d709b Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Thu, 13 Jan 2022 17:22:57 -0300 Subject: [PATCH 1/2] chore: migrate customEmoji to typescript and add tests --- app/actions/customEmojis.js | 8 -------- app/actions/customEmojis.ts | 17 +++++++++++++++++ app/definitions/redux/index.ts | 5 +++-- app/reducers/customEmojis.js | 14 -------------- app/reducers/customEmojis.test.ts | 16 ++++++++++++++++ app/reducers/customEmojis.ts | 23 +++++++++++++++++++++++ 6 files changed, 59 insertions(+), 24 deletions(-) delete mode 100644 app/actions/customEmojis.js create mode 100644 app/actions/customEmojis.ts delete mode 100644 app/reducers/customEmojis.js create mode 100644 app/reducers/customEmojis.test.ts create mode 100644 app/reducers/customEmojis.ts 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 e95763e29..e452d1ac7 100644 --- a/app/definitions/redux/index.ts +++ b/app/definitions/redux/index.ts @@ -1,5 +1,6 @@ -import { TActionSelectedUsers } from '../../actions/selectedUsers'; import { TActionActiveUsers } from '../../actions/activeUsers'; +import { TActionCustomEmojis } from '../../actions/customEmojis'; +import { TActionSelectedUsers } from '../../actions/selectedUsers'; // REDUCERS import { IActiveUsers } from '../../reducers/activeUsers'; import { ISelectedUsers } from '../../reducers/selectedUsers'; @@ -28,4 +29,4 @@ export interface IApplicationState { roles: any; } -export type TApplicationActions = TActionActiveUsers & TActionSelectedUsers; +export type TApplicationActions = TActionActiveUsers & TActionSelectedUsers & TActionCustomEmojis; 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; + } +} From eae02672781ffc2e590f9be55120a366cf9ab7e2 Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Wed, 26 Jan 2022 11:44:41 -0300 Subject: [PATCH 2/2] fix types --- app/definitions/redux/index.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/definitions/redux/index.ts b/app/definitions/redux/index.ts index 4b558bf56..54eb6e4c4 100644 --- a/app/definitions/redux/index.ts +++ b/app/definitions/redux/index.ts @@ -1,5 +1,6 @@ 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'; import { TActionSelectedUsers } from '../../actions/selectedUsers'; @@ -36,4 +37,10 @@ export interface IApplicationState { roles: IRoles; } -export type TApplicationActions = TActionActiveUsers & TActionSelectedUsers & TActionCustomEmojis & TActionInviteLinks & IActionRoles & IActionSettings; +export type TApplicationActions = TActionActiveUsers & + TActionSelectedUsers & + TActionCustomEmojis & + TActionInviteLinks & + IActionRoles & + IActionSettings & + TActionEncryption;