diff --git a/app/actions/connect.js b/app/actions/connect.js deleted file mode 100644 index 57f46c71b..000000000 --- a/app/actions/connect.js +++ /dev/null @@ -1,20 +0,0 @@ -import * as types from './actionsTypes'; - -export function connectRequest() { - return { - type: types.METEOR.REQUEST - }; -} - -export function connectSuccess() { - return { - type: types.METEOR.SUCCESS - }; -} - -export function disconnect(err) { - return { - type: types.METEOR.DISCONNECT, - err - }; -} diff --git a/app/actions/connect.ts b/app/actions/connect.ts new file mode 100644 index 000000000..be566253b --- /dev/null +++ b/app/actions/connect.ts @@ -0,0 +1,21 @@ +import { Action } from 'redux'; + +import * as types from './actionsTypes'; + +export function connectRequest(): Action { + return { + type: types.METEOR.REQUEST + }; +} + +export function connectSuccess(): Action { + return { + type: types.METEOR.SUCCESS + }; +} + +export function disconnect(): Action { + return { + type: types.METEOR.DISCONNECT + }; +} diff --git a/app/definitions/redux/index.ts b/app/definitions/redux/index.ts index 0489eeaf5..2154bdfcb 100644 --- a/app/definitions/redux/index.ts +++ b/app/definitions/redux/index.ts @@ -16,12 +16,13 @@ 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'; export interface IApplicationState { settings: ISettings; login: any; - meteor: any; + meteor: IConnect; server: IServer; selectedUsers: ISelectedUsers; createChannel: any; diff --git a/app/reducers/connect.test.ts b/app/reducers/connect.test.ts new file mode 100644 index 000000000..241abf51b --- /dev/null +++ b/app/reducers/connect.test.ts @@ -0,0 +1,28 @@ +import { connectRequest, connectSuccess, disconnect } from '../actions/connect'; +import { initialState } from './connect'; +import { mockedStore } from './mockedStore'; + +describe('test reducer', () => { + it('should return initial state', () => { + const { meteor } = mockedStore.getState(); + expect(meteor).toEqual(initialState); + }); + + it('should return correct meteor state after dispatch connectRequest action', () => { + mockedStore.dispatch(connectRequest()); + const { meteor } = mockedStore.getState(); + expect(meteor).toEqual({ connecting: true, connected: false }); + }); + + it('should return correct meteor state after dispatch connectSuccess action', () => { + mockedStore.dispatch(connectSuccess()); + const { meteor } = mockedStore.getState(); + expect(meteor).toEqual({ connecting: false, connected: true }); + }); + + it('should return correct meteor state after dispatch disconnect action', () => { + mockedStore.dispatch(disconnect()); + const { meteor } = mockedStore.getState(); + expect(meteor).toEqual(initialState); + }); +}); diff --git a/app/reducers/connect.js b/app/reducers/connect.ts similarity index 63% rename from app/reducers/connect.js rename to app/reducers/connect.ts index a8ef2bea1..beffc58bd 100644 --- a/app/reducers/connect.js +++ b/app/reducers/connect.ts @@ -1,11 +1,18 @@ +import { Action } from 'redux'; + import { METEOR } from '../actions/actionsTypes'; -const initialState = { +export interface IConnect { + connecting: boolean; + connected: boolean; +} + +export const initialState: IConnect = { connecting: false, connected: false }; -export default function connect(state = initialState, action) { +export default function connect(state = initialState, action: Action): IConnect { switch (action.type) { case METEOR.REQUEST: return {