diff --git a/app/actions/share.js b/app/actions/share.js deleted file mode 100644 index ff4d5a59..00000000 --- a/app/actions/share.js +++ /dev/null @@ -1,22 +0,0 @@ -import { SHARE } from './actionsTypes'; - -export function shareSelectServer(server) { - return { - type: SHARE.SELECT_SERVER, - server - }; -} - -export function shareSetSettings(settings) { - return { - type: SHARE.SET_SETTINGS, - settings - }; -} - -export function shareSetUser(user) { - return { - type: SHARE.SET_USER, - user - }; -} diff --git a/app/actions/share.ts b/app/actions/share.ts new file mode 100644 index 00000000..22e01268 --- /dev/null +++ b/app/actions/share.ts @@ -0,0 +1,39 @@ +import { Action } from 'redux'; + +import { IShareServer, IShareUser, TShareSettings } from '../reducers/share'; +import { SHARE } from './actionsTypes'; + +interface IShareSelectServer extends Action { + server: IShareServer; +} + +interface IShareSetSettings extends Action { + settings: TShareSettings; +} + +interface IShareSetUser extends Action { + user: IShareUser; +} + +export type TActionsShare = IShareSelectServer & IShareSetSettings & IShareSetUser; + +export function shareSelectServer(server: IShareServer): IShareSelectServer { + return { + type: SHARE.SELECT_SERVER, + server + }; +} + +export function shareSetSettings(settings: TShareSettings): IShareSetSettings { + return { + type: SHARE.SET_SETTINGS, + settings + }; +} + +export function shareSetUser(user: IShareUser): IShareSetUser { + return { + type: SHARE.SET_USER, + user + }; +} diff --git a/app/definitions/redux/index.ts b/app/definitions/redux/index.ts index 2154bdfc..723889d9 100644 --- a/app/definitions/redux/index.ts +++ b/app/definitions/redux/index.ts @@ -1,23 +1,25 @@ // ACTIONS -import { TActionServer } from '../../actions/server'; 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'; +import { TActionServer } from '../../actions/server'; import { IActionSettings } from '../../actions/settings'; +import { TActionsShare } from '../../actions/share'; import { TActionSortPreferences } from '../../actions/sortPreferences'; import { TActionUserTyping } from '../../actions/usersTyping'; // REDUCERS import { IActiveUsers } from '../../reducers/activeUsers'; +import { IConnect } from '../../reducers/connect'; import { IEncryption } from '../../reducers/encryption'; import { IInviteLinks } from '../../reducers/inviteLinks'; import { IRoles } from '../../reducers/roles'; import { ISelectedUsers } from '../../reducers/selectedUsers'; import { IServer } from '../../reducers/server'; -import { IConnect } from '../../reducers/connect'; import { ISettings } from '../../reducers/settings'; +import { IShare } from '../../reducers/share'; export interface IApplicationState { settings: ISettings; @@ -30,7 +32,7 @@ export interface IApplicationState { room: any; rooms: any; sortPreferences: any; - share: any; + share: IShare; customEmojis: any; activeUsers: IActiveUsers; usersTyping: any; @@ -52,4 +54,5 @@ export type TApplicationActions = TActionActiveUsers & TActionEncryption & TActionSortPreferences & TActionUserTyping & + TActionsShare & TActionServer; diff --git a/app/reducers/share.js b/app/reducers/share.js deleted file mode 100644 index 4f2a22a1..00000000 --- a/app/reducers/share.js +++ /dev/null @@ -1,29 +0,0 @@ -import { SHARE } from '../actions/actionsTypes'; - -const initialState = { - user: {}, - server: {}, - settings: {} -}; - -export default function share(state = initialState, action) { - switch (action.type) { - case SHARE.SELECT_SERVER: - return { - ...state, - server: action.server - }; - case SHARE.SET_USER: - return { - ...state, - user: action.user - }; - case SHARE.SET_SETTINGS: - return { - ...state, - settings: action.settings - }; - default: - return state; - } -} diff --git a/app/reducers/share.test.ts b/app/reducers/share.test.ts new file mode 100644 index 00000000..851e7ad2 --- /dev/null +++ b/app/reducers/share.test.ts @@ -0,0 +1,41 @@ +import { shareSelectServer, shareSetSettings, shareSetUser } from '../actions/share'; +import { mockedStore } from './mockedStore'; +import { initialState } from './share'; + +describe('test share reducer', () => { + it('should return initial state', () => { + const state = mockedStore.getState().share; + expect(state).toEqual(initialState); + }); + + it('should return modified store after shareSelectServer', () => { + const server = { + server: 'https://open.rocket.chat', + version: '4.4.0' + }; + mockedStore.dispatch(shareSelectServer(server)); + const state = mockedStore.getState().share.server; + expect(state).toEqual(server); + }); + + it('should return modified store after shareSetSettings', () => { + const settings = { + Admin: false + }; + mockedStore.dispatch(shareSetSettings(settings)); + const state = mockedStore.getState().share.settings; + expect(state).toEqual(settings); + }); + + it('should return modified store after shareSetUser', () => { + const user = { + id: 'dig-joy', + token: 'token', + username: 'rocket.chat', + roles: ['admin'] + }; + mockedStore.dispatch(shareSetUser(user)); + const state = mockedStore.getState().share.user; + expect(state).toEqual(user); + }); +}); diff --git a/app/reducers/share.ts b/app/reducers/share.ts new file mode 100644 index 00000000..b5737eac --- /dev/null +++ b/app/reducers/share.ts @@ -0,0 +1,50 @@ +import { TActionsShare } from '../actions/share'; +import { SHARE } from '../actions/actionsTypes'; + +export interface IShareServer { + server: string; + version: string; +} + +export type TShareSettings = Record; + +export interface IShareUser { + id: string; + token: string; + username: string; + roles: string[]; +} + +export interface IShare { + user: IShareUser | {}; + server: IShareServer | {}; + settings: TShareSettings; +} + +export const initialState: IShare = { + user: {}, + server: {}, + settings: {} +}; + +export default function share(state = initialState, action: TActionsShare): IShare { + switch (action.type) { + case SHARE.SELECT_SERVER: + return { + ...state, + server: action.server + }; + case SHARE.SET_USER: + return { + ...state, + user: action.user + }; + case SHARE.SET_SETTINGS: + return { + ...state, + settings: action.settings + }; + default: + return state; + } +}