chore: migrate connect to ts and add tests
This commit is contained in:
parent
ba2931665b
commit
1db676f424
|
@ -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
|
||||
};
|
||||
}
|
|
@ -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
|
||||
};
|
||||
}
|
|
@ -5,11 +5,12 @@ import { TActionApp } from '../../actions/app';
|
|||
import { IActiveUsers } from '../../reducers/activeUsers';
|
||||
import { ISelectedUsers } from '../../reducers/selectedUsers';
|
||||
import { IApp } from '../../reducers/app';
|
||||
import { IConnect } from '../../reducers/connect';
|
||||
|
||||
export interface IApplicationState {
|
||||
settings: any;
|
||||
login: any;
|
||||
meteor: any;
|
||||
meteor: IConnect;
|
||||
server: any;
|
||||
selectedUsers: ISelectedUsers;
|
||||
createChannel: any;
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
import { appStart, 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);
|
||||
});
|
||||
});
|
|
@ -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 {
|
Loading…
Reference in New Issue