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

43 lines
1.4 KiB
TypeScript
Raw Normal View History

import { screen } from '@testing-library/react';
2023-04-13 23:47:13 +03:00
import { fromPartial } from '@total-typescript/shoehorn';
2023-02-18 12:40:37 +03:00
import type { DropdownBtnMenuProps } from '../../src/utils/DropdownBtnMenu';
import { DropdownBtnMenu } 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(
2023-04-13 23:47:13 +03:00
<DropdownBtnMenu {...fromPartial<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
});
});