Merge pull request #3603 from RocketChat/chore/migration-ts-redux-connect-v2

Chore: Migrate redux module connect to typescript
This commit is contained in:
Gleidson Daniel Silva 2022-01-26 17:05:00 -03:00 committed by GitHub
commit 19a0c1db96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 61 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

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

View File

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

View File

@ -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 {