From f15b803851df75dbf4a3313224af71b9cf95ed10 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 11 Mar 2022 16:12:54 +0100 Subject: [PATCH] Created sidebar reducer test --- src/common/ShlinkVersionsContainer.tsx | 2 +- src/common/reducers/sidebar.ts | 8 ++--- test/common/ShlinkVersionsContainer.test.tsx | 4 +-- test/common/reducer/sidebar.test.ts | 31 ++++++++++++++++++++ 4 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 test/common/reducer/sidebar.test.ts diff --git a/src/common/ShlinkVersionsContainer.tsx b/src/common/ShlinkVersionsContainer.tsx index 419e77e4..378283e8 100644 --- a/src/common/ShlinkVersionsContainer.tsx +++ b/src/common/ShlinkVersionsContainer.tsx @@ -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 ( diff --git a/src/common/reducers/sidebar.ts b/src/common/reducers/sidebar.ts index cc04da3e..409ebb1e 100644 --- a/src/common/reducers/sidebar.ts +++ b/src/common/reducers/sidebar.ts @@ -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; type SidebarNotRenderedAction = Action; const initialState: Sidebar = { - hasSidebar: false, + sidebarPresent: false, }; export default buildReducer({ - [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); diff --git a/test/common/ShlinkVersionsContainer.test.tsx b/test/common/ShlinkVersionsContainer.test.tsx index b0994453..cec87fed 100644 --- a/test/common/ShlinkVersionsContainer.test.tsx +++ b/test/common/ShlinkVersionsContainer.test.tsx @@ -16,8 +16,8 @@ describe('', () => { 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); diff --git a/test/common/reducer/sidebar.test.ts b/test/common/reducer/sidebar.test.ts new file mode 100644 index 00000000..ecd31075 --- /dev/null +++ b/test/common/reducer/sidebar.test.ts @@ -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(), { 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 }); + }); + }); +});