mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 09:30:31 +03:00
Created sidebar reducer test
This commit is contained in:
parent
c949359d6f
commit
f15b803851
4 changed files with 38 additions and 7 deletions
|
@ -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 (
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
31
test/common/reducer/sidebar.test.ts
Normal file
31
test/common/reducer/sidebar.test.ts
Normal 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 });
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue