mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-31 21:38:19 +03:00
Migrated sidebar reducer to RTK
This commit is contained in:
parent
85e2aab4df
commit
f209fa2d58
3 changed files with 18 additions and 28 deletions
|
@ -1,25 +1,22 @@
|
|||
import { Action } from 'redux';
|
||||
import { buildActionCreator, buildReducer } from '../../utils/helpers/redux';
|
||||
|
||||
export const SIDEBAR_PRESENT = 'shlink/common/SIDEBAR_PRESENT';
|
||||
export const SIDEBAR_NOT_PRESENT = 'shlink/common/SIDEBAR_NOT_PRESENT';
|
||||
import { createSlice } from '@reduxjs/toolkit';
|
||||
|
||||
export interface Sidebar {
|
||||
sidebarPresent: boolean;
|
||||
}
|
||||
|
||||
type SidebarRenderedAction = Action<string>;
|
||||
type SidebarNotRenderedAction = Action<string>;
|
||||
|
||||
const initialState: Sidebar = {
|
||||
sidebarPresent: false,
|
||||
};
|
||||
|
||||
export default buildReducer<Sidebar, SidebarRenderedAction & SidebarNotRenderedAction>({
|
||||
[SIDEBAR_PRESENT]: () => ({ sidebarPresent: true }),
|
||||
[SIDEBAR_NOT_PRESENT]: () => ({ sidebarPresent: false }),
|
||||
}, initialState);
|
||||
const { actions, reducer } = createSlice({
|
||||
name: 'sidebarReducer',
|
||||
initialState,
|
||||
reducers: {
|
||||
sidebarPresent: () => ({ sidebarPresent: true }),
|
||||
sidebarNotPresent: () => ({ sidebarPresent: false }),
|
||||
},
|
||||
});
|
||||
|
||||
export const sidebarPresent = buildActionCreator(SIDEBAR_PRESENT);
|
||||
export const { sidebarPresent, sidebarNotPresent } = actions;
|
||||
|
||||
export const sidebarNotPresent = buildActionCreator(SIDEBAR_NOT_PRESENT);
|
||||
export const sidebarReducer = reducer;
|
||||
|
|
|
@ -19,7 +19,7 @@ import mercureInfoReducer from '../mercure/reducers/mercureInfo';
|
|||
import settingsReducer from '../settings/reducers/settings';
|
||||
import visitsOverviewReducer from '../visits/reducers/visitsOverview';
|
||||
import { appUpdatesReducer } from '../app/reducers/appUpdates';
|
||||
import sidebarReducer from '../common/reducers/sidebar';
|
||||
import { sidebarReducer } from '../common/reducers/sidebar';
|
||||
import { ShlinkState } from '../container/types';
|
||||
|
||||
export default (container: IContainer) => combineReducers<ShlinkState>({
|
||||
|
|
|
@ -1,31 +1,24 @@
|
|||
import { Mock } from 'ts-mockery';
|
||||
import reducer, {
|
||||
Sidebar,
|
||||
SIDEBAR_NOT_PRESENT,
|
||||
SIDEBAR_PRESENT,
|
||||
sidebarNotPresent,
|
||||
sidebarPresent,
|
||||
} from '../../../src/common/reducers/sidebar';
|
||||
import { sidebarReducer, sidebarNotPresent, sidebarPresent } from '../../../src/common/reducers/sidebar';
|
||||
|
||||
describe('sidebarReducer', () => {
|
||||
describe('reducer', () => {
|
||||
it.each([
|
||||
[SIDEBAR_PRESENT, { sidebarPresent: true }],
|
||||
[SIDEBAR_NOT_PRESENT, { sidebarPresent: false }],
|
||||
[sidebarPresent.toString(), { sidebarPresent: true }],
|
||||
[sidebarNotPresent.toString(), { sidebarPresent: false }],
|
||||
])('returns expected on %s', (type, expected) => {
|
||||
expect(reducer(Mock.all<Sidebar>(), { type })).toEqual(expected);
|
||||
expect(sidebarReducer(undefined, { type })).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('sidebarPresent', () => {
|
||||
it('returns expected action', () => {
|
||||
expect(sidebarPresent()).toEqual({ type: SIDEBAR_PRESENT });
|
||||
expect(sidebarPresent()).toEqual({ type: sidebarPresent.toString() });
|
||||
});
|
||||
});
|
||||
|
||||
describe('sidebarNotPresent', () => {
|
||||
it('returns expected action', () => {
|
||||
expect(sidebarNotPresent()).toEqual({ type: SIDEBAR_NOT_PRESENT });
|
||||
expect(sidebarNotPresent()).toEqual({ type: sidebarNotPresent.toString() });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue