chore: migrate settings to typescript
This commit is contained in:
parent
9d9553b075
commit
4249eef653
|
@ -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
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
import { Action } from 'redux';
|
||||||
|
|
||||||
|
import { ISettings } from '../reducers/settings';
|
||||||
|
import { SETTINGS } from './actionsTypes';
|
||||||
|
|
||||||
|
interface IAddSettings extends Action {
|
||||||
|
payload: ISettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IUpdateSettings extends Action {
|
||||||
|
payload: { id: string; value: string };
|
||||||
|
}
|
||||||
|
|
||||||
|
export type IActionSettings = IAddSettings & IUpdateSettings;
|
||||||
|
|
||||||
|
export function addSettings(settings: ISettings): IAddSettings {
|
||||||
|
return {
|
||||||
|
type: SETTINGS.ADD,
|
||||||
|
payload: settings
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function updateSettings(id: string, value: string): IUpdateSettings {
|
||||||
|
return {
|
||||||
|
type: SETTINGS.UPDATE,
|
||||||
|
payload: { id, value }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function clearSettings(): Action {
|
||||||
|
return {
|
||||||
|
type: SETTINGS.CLEAR
|
||||||
|
};
|
||||||
|
}
|
|
@ -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({});
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,8 +1,12 @@
|
||||||
|
import { IActionSettings } from '../actions/settings';
|
||||||
import { SETTINGS } from '../actions/actionsTypes';
|
import { SETTINGS } from '../actions/actionsTypes';
|
||||||
|
|
||||||
const initialState = {};
|
// TODO UPDATE SETTINGS TYPE
|
||||||
|
export type ISettings = Record<string, any>;
|
||||||
|
|
||||||
export default (state = initialState, action) => {
|
export const initialState: ISettings = {};
|
||||||
|
|
||||||
|
export default (state = initialState, action: IActionSettings): ISettings => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case SETTINGS.ADD:
|
case SETTINGS.ADD:
|
||||||
return {
|
return {
|
Loading…
Reference in New Issue