chore: test redux components with jest

This commit is contained in:
Sebastian Velez
2023-01-13 18:36:39 -05:00
parent 6dfa40e026
commit 5486a69305
12 changed files with 193 additions and 119 deletions

View File

@@ -1,25 +0,0 @@
import { createSlice } from '@reduxjs/toolkit';
interface setValueAction {
payload: string;
type: string;
}
export interface ApiKey {
value: string;
}
export const initialState: ApiKey = { value: '' };
const apiKeySlice = createSlice({
initialState,
name: 'spiKey',
reducers: {
setValue: (state, action: setValueAction) => {
state.value = action.payload;
},
},
});
export const actions = apiKeySlice.actions;
export const { setValue } = apiKeySlice.actions;
export default apiKeySlice.reducer;

View File

@@ -0,0 +1,50 @@
import { createSlice } from '@reduxjs/toolkit';
import config from '../config/config';
import { ApiKeyReducer } from '../types/store';
interface SetApiKeyAction {
payload: string;
type: string;
}
interface SetLoggingEnabledAction {
payload: boolean;
type: string;
}
interface SetTotalTimeLoggedTodayAction {
payload: string;
type: string;
}
export const initialConfigState: ApiKeyReducer = {
apiKey: '',
loggingEnabled: config.loggingEnabled,
totalTimeLoggedToday: '0 minutes',
};
const apiKeySlice = createSlice({
initialState: initialConfigState,
name: 'configReducer',
reducers: {
configLogout: (state) => {
state.apiKey = '';
state.loggingEnabled = config.loggingEnabled;
state.totalTimeLoggedToday = '0 minutes';
},
setApiKey: (state, action: SetApiKeyAction) => {
state.apiKey = action.payload;
},
setLoggingEnabled: (state, action: SetLoggingEnabledAction) => {
state.loggingEnabled = action.payload;
},
setTotalTimeLoggedToday: (state, action: SetTotalTimeLoggedTodayAction) => {
state.totalTimeLoggedToday = action.payload;
},
},
});
export const actions = apiKeySlice.actions;
export const { configLogout, setApiKey, setLoggingEnabled, setTotalTimeLoggedToday } =
apiKeySlice.actions;
export default apiKeySlice.reducer;

View File

@@ -39,9 +39,12 @@ const currentUser = createSlice({
setUser: (state, action: setUserAction) => {
state.user = action.payload;
},
userLogout: (state) => {
state.user = undefined;
},
},
});
export const actions = currentUser.actions;
export const { setUser } = currentUser.actions;
export const { setUser, userLogout } = currentUser.actions;
export default currentUser.reducer;