Migrated appUpdated reducer to RTK

This commit is contained in:
Alejandro Celaya 2022-11-04 19:39:15 +01:00
parent 26c3ea19f4
commit 85e2aab4df
3 changed files with 17 additions and 24 deletions

View file

@ -1,16 +1,14 @@
import { Action } from 'redux'; import { createSlice } from '@reduxjs/toolkit';
import { buildActionCreator, buildReducer } from '../../utils/helpers/redux';
export const APP_UPDATE_AVAILABLE = 'shlink/appUpdates/APP_UPDATE_AVAILABLE'; const { actions, reducer } = createSlice({
export const RESET_APP_UPDATE = 'shlink/appUpdates/RESET_APP_UPDATE'; name: 'appUpdatesReducer',
initialState: false,
reducers: {
appUpdateAvailable: () => true,
resetAppUpdate: () => false,
},
});
const initialState = false; export const { appUpdateAvailable, resetAppUpdate } = actions;
export default buildReducer<boolean, Action<string>>({ export const appUpdatesReducer = reducer;
[APP_UPDATE_AVAILABLE]: () => true,
[RESET_APP_UPDATE]: () => false,
}, initialState);
export const appUpdateAvailable = buildActionCreator(APP_UPDATE_AVAILABLE);
export const resetAppUpdate = buildActionCreator(RESET_APP_UPDATE);

View file

@ -18,7 +18,7 @@ import tagEditReducer from '../tags/reducers/tagEdit';
import mercureInfoReducer from '../mercure/reducers/mercureInfo'; import mercureInfoReducer from '../mercure/reducers/mercureInfo';
import settingsReducer from '../settings/reducers/settings'; import settingsReducer from '../settings/reducers/settings';
import visitsOverviewReducer from '../visits/reducers/visitsOverview'; import visitsOverviewReducer from '../visits/reducers/visitsOverview';
import appUpdatesReducer from '../app/reducers/appUpdates'; import { appUpdatesReducer } from '../app/reducers/appUpdates';
import sidebarReducer from '../common/reducers/sidebar'; import sidebarReducer from '../common/reducers/sidebar';
import { ShlinkState } from '../container/types'; import { ShlinkState } from '../container/types';

View file

@ -1,30 +1,25 @@
import reducer, { import { appUpdatesReducer, appUpdateAvailable, resetAppUpdate } from '../../../src/app/reducers/appUpdates';
APP_UPDATE_AVAILABLE,
RESET_APP_UPDATE,
appUpdateAvailable,
resetAppUpdate,
} from '../../../src/app/reducers/appUpdates';
describe('appUpdatesReducer', () => { describe('appUpdatesReducer', () => {
describe('reducer', () => { describe('reducer', () => {
it('returns true on APP_UPDATE_AVAILABLE', () => { it('returns true on APP_UPDATE_AVAILABLE', () => {
expect(reducer(undefined, { type: APP_UPDATE_AVAILABLE })).toEqual(true); expect(appUpdatesReducer(undefined, { type: appUpdateAvailable.toString() })).toEqual(true);
}); });
it('returns false on RESET_APP_UPDATE', () => { it('returns false on RESET_APP_UPDATE', () => {
expect(reducer(undefined, { type: RESET_APP_UPDATE })).toEqual(false); expect(appUpdatesReducer(undefined, { type: resetAppUpdate.toString() })).toEqual(false);
}); });
}); });
describe('appUpdateAvailable', () => { describe('appUpdateAvailable', () => {
it('creates expected action', () => { it('creates expected action', () => {
expect(appUpdateAvailable()).toEqual({ type: APP_UPDATE_AVAILABLE }); expect(appUpdateAvailable()).toEqual({ type: appUpdateAvailable.toString() });
}); });
}); });
describe('resetAppUpdate', () => { describe('resetAppUpdate', () => {
it('creates expected action', () => { it('creates expected action', () => {
expect(resetAppUpdate()).toEqual({ type: RESET_APP_UPDATE }); expect(resetAppUpdate()).toEqual({ type: resetAppUpdate.toString() });
}); });
}); });
}); });