shlink-web-client/test/utils/DropdownBtnMenu.test.tsx

40 lines
1.3 KiB
TypeScript
Raw Normal View History

import { screen } from '@testing-library/react';
2021-09-24 21:04:16 +03:00
import { Mock } from 'ts-mockery';
import { DropdownBtnMenu, DropdownBtnMenuProps } from '../../src/utils/DropdownBtnMenu';
import { renderWithEvents } from '../__helpers__/setUpTest';
2021-09-24 21:04:16 +03:00
describe('<DropdownBtnMenu />', () => {
const setUp = (props: Partial<DropdownBtnMenuProps> = {}) => renderWithEvents(
<DropdownBtnMenu {...Mock.of<DropdownBtnMenuProps>({ toggle: jest.fn(), ...props })}>the children</DropdownBtnMenu>,
);
2021-09-24 21:04:16 +03:00
it('renders expected components', () => {
setUp();
const toggle = screen.getByRole('button');
2021-09-24 21:04:16 +03:00
expect(toggle).toBeInTheDocument();
expect(toggle).toHaveClass('btn-sm');
expect(toggle).toHaveClass('dropdown-btn-menu__dropdown-toggle');
expect(screen.getByRole('img', { hidden: true })).toBeInTheDocument();
2021-09-24 21:04:16 +03:00
});
it('renders expected children', () => {
setUp();
expect(screen.getByText('the children')).toBeInTheDocument();
2021-09-24 21:04:16 +03:00
});
it.each([
2022-03-26 14:17:42 +03:00
[undefined, true],
[true, true],
[false, false],
])('renders menu to the end when expected', (right, expectedEnd) => {
setUp({ right });
if (expectedEnd) {
expect(screen.getByRole('menu', { hidden: true })).toHaveClass('dropdown-menu-end');
} else {
expect(screen.getByRole('menu', { hidden: true })).not.toHaveClass('dropdown-menu-end');
}
2021-09-24 21:04:16 +03:00
});
});