chore: migrate connect to ts and add tests

This commit is contained in:
GleidsonDaniel 2022-01-12 17:08:45 -03:00
parent f1456ff786
commit dbe8221d69
5 changed files with 76 additions and 23 deletions

View File

@ -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
};
}

21
app/actions/connect.ts Normal file
View File

@ -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
};
}

View File

@ -3,11 +3,12 @@ import { TActionActiveUsers } from '../../actions/activeUsers';
// REDUCERS // REDUCERS
import { IActiveUsers } from '../../reducers/activeUsers'; import { IActiveUsers } from '../../reducers/activeUsers';
import { ISelectedUsers } from '../../reducers/selectedUsers'; import { ISelectedUsers } from '../../reducers/selectedUsers';
import { IConnect } from '../../reducers/connect';
export interface IApplicationState { export interface IApplicationState {
settings: any; settings: any;
login: any; login: any;
meteor: any; meteor: IConnect;
server: any; server: any;
selectedUsers: ISelectedUsers; selectedUsers: ISelectedUsers;
createChannel: any; createChannel: any;

View File

@ -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);
});
});

View File

@ -1,11 +1,18 @@
import { Action } from 'redux';
import { METEOR } from '../actions/actionsTypes'; import { METEOR } from '../actions/actionsTypes';
const initialState = { export interface IConnect {
connecting: boolean;
connected: boolean;
}
export const initialState: IConnect = {
connecting: false, connecting: false,
connected: false connected: false
}; };
export default function connect(state = initialState, action) { export default function connect(state = initialState, action: Action): IConnect {
switch (action.type) { switch (action.type) {
case METEOR.REQUEST: case METEOR.REQUEST:
return { return {