Merge pull request #3603 from RocketChat/chore/migration-ts-redux-connect-v2
Chore: Migrate redux module connect to typescript
This commit is contained in:
commit
19a0c1db96
|
@ -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
|
||||
};
|
||||
}
|
|
@ -13,12 +13,14 @@ import { IEncryption } from '../../reducers/encryption';
|
|||
import { IInviteLinks } from '../../reducers/inviteLinks';
|
||||
import { IRoles } from '../../reducers/roles';
|
||||
import { ISelectedUsers } from '../../reducers/selectedUsers';
|
||||
import { IConnect } from '../../reducers/connect';
|
||||
import { ISettings } from '../../reducers/settings';
|
||||
|
||||
|
||||
export interface IApplicationState {
|
||||
settings: ISettings;
|
||||
login: any;
|
||||
meteor: any;
|
||||
meteor: IConnect;
|
||||
server: any;
|
||||
selectedUsers: ISelectedUsers;
|
||||
createChannel: any;
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
|
@ -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