import { cleanup } from '@testing-library/react';
import { render } from '../../utils/theme-render-wrapper';
import { BrowserRouter } from 'react-router-dom';
import { ASSETS_URL } from '../../consts/common';
import { UserControls } from './user-controls';
import type { UserControlsProps } from './types';
afterEach(cleanup);
const mockUser: UserControlsProps = {
name: 'Mock User',
userRole: 'Admin'
};
describe('', () => {
it(`Should render UserControls`, () => {
const { queryByTestId } = render(
);
expect(queryByTestId('button-userInfo')?.textContent).toBe(mockUser.name + mockUser.userRole);
});
it(`Should render without search icon`, () => {
const { queryByTestId } = render(
);
expect(queryByTestId('button-search')).toBeNull();
expect(queryByTestId('link-settings')).toBeTruthy();
});
it(`Should render without settings icon`, () => {
const { queryByTestId } = render(
);
expect(queryByTestId('button-search')).toBeTruthy();
expect(queryByTestId('link-settings')).toBeNull();
});
it(`Should render with badge count 0`, () => {
// eslint-disable-next-line react/jsx-props-no-spreading
render(
);
});
it(`Should render with badge count 10`, () => {
// eslint-disable-next-line react/jsx-props-no-spreading
render(
);
});
it(`Should render with badge count 100`, () => {
// eslint-disable-next-line react/jsx-props-no-spreading
render(
);
});
it(`Should render with dividers and buttons`, () => {
const iconButtons = [
{
title: 'Text only'
},
{
icon: {
src: `${ASSETS_URL}/icons/icon_linux.svg`
},
onClick: () => alert('Icon is clicked!')
},
{
href: '/help',
title: 'Text with link'
},
{
icon: {
src: `${ASSETS_URL}/icons/icon_linux.svg`
},
title: 'Icon with text'
},
{
href: '/help',
icon: {
src: `${ASSETS_URL}/icons/icon_linux.svg`
},
title: 'Icon with text and link'
}
];
const { queryByTestId } = render(
);
expect(queryByTestId('iconsContainer')?.textContent).toBe(
iconButtons.map(item => item.title).join('')
);
});
it(`Should click on user arrow`, () => {
const userArrowCallback = jest.fn();
const { queryByTestId } = render(
);
const el = queryByTestId('button-userInfo');
el?.click();
expect(userArrowCallback).toHaveBeenCalled();
});
});