chore: migrate usersTyping to typescript
This commit is contained in:
parent
9d9553b075
commit
400673e231
|
@ -1,21 +0,0 @@
|
||||||
import { USERS_TYPING } from './actionsTypes';
|
|
||||||
|
|
||||||
export function addUserTyping(username) {
|
|
||||||
return {
|
|
||||||
type: USERS_TYPING.ADD,
|
|
||||||
username
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function removeUserTyping(username) {
|
|
||||||
return {
|
|
||||||
type: USERS_TYPING.REMOVE,
|
|
||||||
username
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function clearUserTyping() {
|
|
||||||
return {
|
|
||||||
type: USERS_TYPING.CLEAR
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
import { Action } from 'redux';
|
||||||
|
|
||||||
|
import { USERS_TYPING } from './actionsTypes';
|
||||||
|
|
||||||
|
export interface IUsersTypingGenericAction extends Action {
|
||||||
|
username: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type TActionUserTyping = IUsersTypingGenericAction & Action;
|
||||||
|
|
||||||
|
export function addUserTyping(username: string): IUsersTypingGenericAction {
|
||||||
|
return {
|
||||||
|
type: USERS_TYPING.ADD,
|
||||||
|
username
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function removeUserTyping(username: string): IUsersTypingGenericAction {
|
||||||
|
return {
|
||||||
|
type: USERS_TYPING.REMOVE,
|
||||||
|
username
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function clearUserTyping(): Action {
|
||||||
|
return {
|
||||||
|
type: USERS_TYPING.CLEAR
|
||||||
|
};
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ 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 { TActionUserTyping } from '../../actions/usersTyping';
|
||||||
|
|
||||||
export interface IApplicationState {
|
export interface IApplicationState {
|
||||||
settings: any;
|
settings: any;
|
||||||
|
@ -28,4 +29,4 @@ export interface IApplicationState {
|
||||||
roles: any;
|
roles: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TApplicationActions = TActionActiveUsers & TActionSelectedUsers;
|
export type TApplicationActions = TActionActiveUsers & TActionSelectedUsers & TActionUserTyping;
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
import { addUserTyping, removeUserTyping, clearUserTyping } from '../actions/usersTyping';
|
||||||
|
import { mockedStore } from './mockedStore';
|
||||||
|
import { initialState } from './usersTyping';
|
||||||
|
|
||||||
|
describe('test usersTyping reducer', () => {
|
||||||
|
it('should return initial state', () => {
|
||||||
|
const state = mockedStore.getState().usersTyping;
|
||||||
|
expect(state).toEqual(initialState);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return modified store after addUserTyping', () => {
|
||||||
|
mockedStore.dispatch(addUserTyping('diego'));
|
||||||
|
mockedStore.dispatch(addUserTyping('carlos'));
|
||||||
|
mockedStore.dispatch(addUserTyping('maria'));
|
||||||
|
const state = mockedStore.getState().usersTyping;
|
||||||
|
expect(state).toEqual(['diego', 'carlos', 'maria']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return modified store after removeUserTyping', () => {
|
||||||
|
mockedStore.dispatch(removeUserTyping('diego'));
|
||||||
|
const state = mockedStore.getState().usersTyping;
|
||||||
|
expect(state).toEqual(['carlos', 'maria']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return initial state after reset', () => {
|
||||||
|
mockedStore.dispatch(clearUserTyping());
|
||||||
|
const state = mockedStore.getState().usersTyping;
|
||||||
|
expect(state).toEqual(initialState);
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,8 +1,11 @@
|
||||||
import { USERS_TYPING } from '../actions/actionsTypes';
|
import { USERS_TYPING } from '../actions/actionsTypes';
|
||||||
|
import { TApplicationActions } from '../definitions';
|
||||||
|
|
||||||
const initialState = [];
|
export type IUsersTyping = string[];
|
||||||
|
|
||||||
export default function usersTyping(state = initialState, action) {
|
export const initialState: IUsersTyping = [];
|
||||||
|
|
||||||
|
export default function usersTyping(state = initialState, action: TApplicationActions): IUsersTyping {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case USERS_TYPING.ADD:
|
case USERS_TYPING.ADD:
|
||||||
if (state.findIndex(item => item === action.username) === -1) {
|
if (state.findIndex(item => item === action.username) === -1) {
|
Loading…
Reference in New Issue