chore: migrate redux module sortPreferences to typescript
This commit is contained in:
parent
ceb2b331ad
commit
3cc5a7b656
|
@ -1,15 +0,0 @@
|
||||||
import * as types from './actionsTypes';
|
|
||||||
|
|
||||||
export function setAllPreferences(preferences) {
|
|
||||||
return {
|
|
||||||
type: types.SORT_PREFERENCES.SET_ALL,
|
|
||||||
preferences
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setPreference(preference) {
|
|
||||||
return {
|
|
||||||
type: types.SORT_PREFERENCES.SET,
|
|
||||||
preference
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
import { Action } from 'redux';
|
||||||
|
|
||||||
|
import { IPreferences } from '../definitions';
|
||||||
|
import { SORT_PREFERENCES } from './actionsTypes';
|
||||||
|
|
||||||
|
interface ISetAllPreferences extends Action {
|
||||||
|
preferences: IPreferences;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ISetPreference extends Action {
|
||||||
|
preference: Partial<IPreferences>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type TActionSortPreferences = ISetAllPreferences & ISetPreference;
|
||||||
|
|
||||||
|
export function setAllPreferences(preferences: IPreferences): ISetAllPreferences {
|
||||||
|
return {
|
||||||
|
type: SORT_PREFERENCES.SET_ALL,
|
||||||
|
preferences
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setPreference(preference: Partial<IPreferences>): ISetPreference {
|
||||||
|
return {
|
||||||
|
type: SORT_PREFERENCES.SET,
|
||||||
|
preference
|
||||||
|
};
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ export * from './INotification';
|
||||||
export * from './IRoom';
|
export * from './IRoom';
|
||||||
export * from './IServer';
|
export * from './IServer';
|
||||||
export * from './ISubscription';
|
export * from './ISubscription';
|
||||||
|
export * from './IPreferences';
|
||||||
|
|
||||||
export interface IBaseScreen<T extends Record<string, object | undefined>, S extends string> {
|
export interface IBaseScreen<T extends Record<string, object | undefined>, S extends string> {
|
||||||
navigation: StackNavigationProp<T, S>;
|
navigation: StackNavigationProp<T, S>;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { TActionSelectedUsers } from '../../actions/selectedUsers';
|
|
||||||
import { TActionActiveUsers } from '../../actions/activeUsers';
|
import { TActionActiveUsers } from '../../actions/activeUsers';
|
||||||
|
import { TActionSelectedUsers } from '../../actions/selectedUsers';
|
||||||
|
import { TActionSortPreferences } from '../../actions/sortPreferences';
|
||||||
// REDUCERS
|
// REDUCERS
|
||||||
import { IActiveUsers } from '../../reducers/activeUsers';
|
import { IActiveUsers } from '../../reducers/activeUsers';
|
||||||
import { ISelectedUsers } from '../../reducers/selectedUsers';
|
import { ISelectedUsers } from '../../reducers/selectedUsers';
|
||||||
|
@ -28,4 +29,4 @@ export interface IApplicationState {
|
||||||
roles: any;
|
roles: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TApplicationActions = TActionActiveUsers & TActionSelectedUsers;
|
export type TApplicationActions = TActionActiveUsers & TActionSelectedUsers & TActionSortPreferences;
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
import { IPreferences } from '../definitions';
|
||||||
|
import { setAllPreferences, setPreference } from '../actions/sortPreferences';
|
||||||
|
import { mockedStore } from './mockedStore';
|
||||||
|
import { initialState } from './sortPreferences';
|
||||||
|
import { DisplayMode, SortBy } from '../constants/constantDisplayMode';
|
||||||
|
|
||||||
|
describe('test sortPreferences reducer', () => {
|
||||||
|
it('should return initial state', () => {
|
||||||
|
const state = mockedStore.getState().sortPreferences;
|
||||||
|
expect(state).toEqual(initialState);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return correctly value after call setPreference action', () => {
|
||||||
|
const preferences: IPreferences = {
|
||||||
|
displayMode: DisplayMode.Condensed,
|
||||||
|
groupByType: true,
|
||||||
|
showAvatar: true,
|
||||||
|
showFavorites: true,
|
||||||
|
showUnread: true,
|
||||||
|
sortBy: SortBy.Activity
|
||||||
|
};
|
||||||
|
mockedStore.dispatch(setAllPreferences(preferences));
|
||||||
|
const state = mockedStore.getState().sortPreferences;
|
||||||
|
expect(state).toEqual(preferences);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return correctly value after call setPreference action', () => {
|
||||||
|
const preference: Partial<IPreferences> = {
|
||||||
|
displayMode: DisplayMode.Expanded
|
||||||
|
};
|
||||||
|
mockedStore.dispatch(setPreference(preference));
|
||||||
|
const { displayMode } = mockedStore.getState().sortPreferences;
|
||||||
|
expect(displayMode).toEqual(DisplayMode.Expanded);
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,7 +1,8 @@
|
||||||
import { SORT_PREFERENCES } from '../actions/actionsTypes';
|
import { SORT_PREFERENCES } from '../actions/actionsTypes';
|
||||||
import { DisplayMode, SortBy } from '../constants/constantDisplayMode';
|
import { DisplayMode, SortBy } from '../constants/constantDisplayMode';
|
||||||
|
import { IPreferences, TApplicationActions } from '../definitions';
|
||||||
|
|
||||||
const initialState = {
|
export const initialState: IPreferences = {
|
||||||
sortBy: SortBy.Activity,
|
sortBy: SortBy.Activity,
|
||||||
groupByType: false,
|
groupByType: false,
|
||||||
showFavorites: false,
|
showFavorites: false,
|
||||||
|
@ -10,7 +11,7 @@ const initialState = {
|
||||||
displayMode: DisplayMode.Expanded
|
displayMode: DisplayMode.Expanded
|
||||||
};
|
};
|
||||||
|
|
||||||
export default (state = initialState, action) => {
|
export default (state = initialState, action: TApplicationActions): IPreferences => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case SORT_PREFERENCES.SET_ALL:
|
case SORT_PREFERENCES.SET_ALL:
|
||||||
return {
|
return {
|
Loading…
Reference in New Issue