Merge branch 'develop' into chore/migration-ts-redux-rooms

This commit is contained in:
Gleidson Daniel Silva 2022-01-26 10:16:42 -03:00 committed by GitHub
commit 2b22463a55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 77 additions and 26 deletions

View File

@ -1,21 +0,0 @@
import { SETTINGS } from './actionsTypes';
export function addSettings(settings) {
return {
type: SETTINGS.ADD,
payload: settings
};
}
export function updateSettings(id, value) {
return {
type: SETTINGS.UPDATE,
payload: { id, value }
};
}
export function clearSettings() {
return {
type: SETTINGS.CLEAR
};
}

34
app/actions/settings.ts Normal file
View File

@ -0,0 +1,34 @@
import { Action } from 'redux';
import { ISettings, TSettings } from '../reducers/settings';
import { SETTINGS } from './actionsTypes';
interface IAddSettings extends Action {
payload: ISettings;
}
interface IUpdateSettings extends Action {
payload: { id: string; value: TSettings };
}
export type IActionSettings = IAddSettings & IUpdateSettings;
export function addSettings(settings: ISettings): IAddSettings {
return {
type: SETTINGS.ADD,
payload: settings
};
}
export function updateSettings(id: string, value: TSettings): IUpdateSettings {
return {
type: SETTINGS.UPDATE,
payload: { id, value }
};
}
export function clearSettings(): Action {
return {
type: SETTINGS.CLEAR
};
}

View File

@ -1,11 +1,13 @@
import { TActionSelectedUsers } from '../../actions/selectedUsers';
import { TActionActiveUsers } from '../../actions/activeUsers';
import { TActionSelectedUsers } from '../../actions/selectedUsers';
import { IActionSettings } from '../../actions/settings';
// REDUCERS
import { IActiveUsers } from '../../reducers/activeUsers';
import { ISelectedUsers } from '../../reducers/selectedUsers';
import { ISettings } from '../../reducers/settings';
export interface IApplicationState {
settings: any;
settings: ISettings;
login: any;
meteor: any;
server: any;
@ -28,4 +30,4 @@ export interface IApplicationState {
roles: any;
}
export type TApplicationActions = TActionActiveUsers & TActionSelectedUsers;
export type TApplicationActions = TActionActiveUsers & TActionSelectedUsers & IActionSettings;

View File

@ -0,0 +1,31 @@
import { addSettings, clearSettings, updateSettings } from '../actions/settings';
import { mockedStore } from './mockedStore';
import { initialState } from './settings';
describe('test settings reducer', () => {
it('should return initial state', () => {
const state = mockedStore.getState().settings;
expect(state).toEqual(initialState);
});
const settings = { API_Use_REST_For_DDP_Calls: true, FileUpload_MaxFileSize: 600857600, Jitsi_URL_Room_Prefix: 'RocketChat' };
it('should return modified store after call addSettings action', () => {
mockedStore.dispatch(addSettings(settings));
const state = mockedStore.getState().settings;
expect(state).toEqual(settings);
});
it('should return correctly settings after call updateSettings action', () => {
const id = 'Jitsi_URL_Room_Prefix';
mockedStore.dispatch(updateSettings(id, 'ChatRocket'));
const state = mockedStore.getState().settings;
expect(state[id]).toEqual('ChatRocket');
});
it('should return initial state after clearSettings', () => {
mockedStore.dispatch(clearSettings());
const state = mockedStore.getState().settings;
expect(state).toEqual({});
});
});

View File

@ -1,8 +1,13 @@
import { IActionSettings } from '../actions/settings';
import { SETTINGS } from '../actions/actionsTypes';
const initialState = {};
export type TSettings = string | number | boolean;
export default (state = initialState, action) => {
export type ISettings = Record<string, TSettings>;
export const initialState: ISettings = {};
export default (state = initialState, action: IActionSettings): ISettings => {
switch (action.type) {
case SETTINGS.ADD:
return {