chore: test redux components with jest
This commit is contained in:
@@ -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;
|
||||
50
src/reducers/configReducer.ts
Normal file
50
src/reducers/configReducer.ts
Normal 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;
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user