Created sidebar reducer test

This commit is contained in:
Alejandro Celaya 2022-03-11 16:12:54 +01:00
parent c949359d6f
commit f15b803851
4 changed files with 38 additions and 7 deletions

View file

@ -11,7 +11,7 @@ export interface ShlinkVersionsContainerProps {
const ShlinkVersionsContainer = ({ selectedServer, sidebar }: ShlinkVersionsContainerProps) => {
const classes = classNames('text-center', {
'shlink-versions-container--with-sidebar': sidebar.hasSidebar,
'shlink-versions-container--with-sidebar': sidebar.sidebarPresent,
});
return (

View file

@ -7,19 +7,19 @@ export const SIDEBAR_NOT_PRESENT = 'shlink/common/SIDEBAR_NOT_PRESENT';
/* eslint-enable padding-line-between-statements */
export interface Sidebar {
hasSidebar: boolean;
sidebarPresent: boolean;
}
type SidebarRenderedAction = Action<string>;
type SidebarNotRenderedAction = Action<string>;
const initialState: Sidebar = {
hasSidebar: false,
sidebarPresent: false,
};
export default buildReducer<Sidebar, SidebarRenderedAction & SidebarNotRenderedAction>({
[SIDEBAR_PRESENT]: () => ({ hasSidebar: true }),
[SIDEBAR_NOT_PRESENT]: () => ({ hasSidebar: false }),
[SIDEBAR_PRESENT]: () => ({ sidebarPresent: true }),
[SIDEBAR_NOT_PRESENT]: () => ({ sidebarPresent: false }),
}, initialState);
export const sidebarPresent = buildActionCreator(SIDEBAR_PRESENT);

View file

@ -16,8 +16,8 @@ describe('<ShlinkVersionsContainer />', () => {
afterEach(() => wrapper?.unmount());
it.each([
[{ hasSidebar: false }, 'text-center' ],
[{ hasSidebar: true }, 'text-center shlink-versions-container--with-sidebar' ],
[{ sidebarPresent: false }, 'text-center' ],
[{ sidebarPresent: true }, 'text-center shlink-versions-container--with-sidebar' ],
])('renders proper col classes based on sidebar status', (sidebar, expectedClasses) => {
const wrapper = createWrapper(sidebar);

View file

@ -0,0 +1,31 @@
import { Mock } from 'ts-mockery';
import reducer, {
Sidebar,
SIDEBAR_NOT_PRESENT,
SIDEBAR_PRESENT,
sidebarNotPresent,
sidebarPresent,
} from '../../../src/common/reducers/sidebar';
describe('sidebarReducer', () => {
describe('reducer', () => {
it.each([
[ SIDEBAR_PRESENT, { sidebarPresent: true }],
[ SIDEBAR_NOT_PRESENT, { sidebarPresent: false }],
])('returns expected on %s', (type, expected) => {
expect(reducer(Mock.all<Sidebar>(), { type })).toEqual(expected);
});
});
describe('sidebarPresent', () => {
it('returns expected action', () => {
expect(sidebarPresent()).toEqual({ type: SIDEBAR_PRESENT });
});
});
describe('sidebarNotPresent', () => {
it('returns expected action', () => {
expect(sidebarNotPresent()).toEqual({ type: SIDEBAR_NOT_PRESENT });
});
});
});