diff --git a/app/actions/connect.js b/app/actions/connect.js deleted file mode 100644 index 57f46c71..00000000 --- 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 00000000..be566253 --- /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 e95763e2..1b994197 100644 --- a/app/definitions/redux/index.ts +++ b/app/definitions/redux/index.ts @@ -3,11 +3,12 @@ import { TActionActiveUsers } from '../../actions/activeUsers'; // REDUCERS import { IActiveUsers } from '../../reducers/activeUsers'; import { ISelectedUsers } from '../../reducers/selectedUsers'; +import { IConnect } from '../../reducers/connect'; export interface IApplicationState { settings: any; login: any; - meteor: any; + meteor: IConnect; server: any; selectedUsers: ISelectedUsers; createChannel: any; diff --git a/app/reducers/connect.test.ts b/app/reducers/connect.test.ts new file mode 100644 index 00000000..bd9899d8 --- /dev/null +++ b/app/reducers/connect.test.ts @@ -0,0 +1,44 @@ +import { appInit, setMasterDetail } from '../actions/app'; +import { initialState } from './connect'; +import { mockedStore } from './mockedStore'; +// import { RootEnum } from '../definitions'; +import { APP_STATE } from '../actions/actionsTypes'; + +describe('test reducer', () => { + it('should return initial state', () => { + const { meteor } = mockedStore.getState(); + expect(meteor).toEqual(initialState); + }); + + // it('should return root state after dispatch appStart action', () => { + // mockedStore.dispatch(appStart({ root: RootEnum.ROOT_INSIDE })); + // const { root } = mockedStore.getState().app; + // expect(root).toEqual(RootEnum.ROOT_INSIDE); + // }); + + it('should return ready state after dispatch appInit action', () => { + mockedStore.dispatch(appInit()); + const { ready } = mockedStore.getState().app; + expect(ready).toEqual(false); + }); + + it('should return ready state after dispatch setMasterDetail action', () => { + mockedStore.dispatch(setMasterDetail(false)); + const { isMasterDetail } = mockedStore.getState().app; + expect(isMasterDetail).toEqual(false); + }); + + it('should return correct state after app go to foreground', () => { + mockedStore.dispatch({ type: APP_STATE.FOREGROUND }); + const { foreground, background } = mockedStore.getState().app; + expect(foreground).toEqual(true); + expect(background).toEqual(false); + }); + + it('should return correct state after app go to background', () => { + mockedStore.dispatch({ type: APP_STATE.BACKGROUND }); + const { foreground, background } = mockedStore.getState().app; + expect(foreground).toEqual(false); + expect(background).toEqual(true); + }); +}); 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 a8ef2bea..beffc58b 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 {