2022-07-17 10:29:50 +03:00
|
|
|
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';
|
2022-07-17 10:29:50 +03:00
|
|
|
import { renderWithEvents } from '../__helpers__/setUpTest';
|
2021-09-24 21:04:16 +03:00
|
|
|
|
|
|
|
describe('<DropdownBtnMenu />', () => {
|
2022-07-17 10:29:50 +03:00
|
|
|
const setUp = (props: Partial<DropdownBtnMenuProps> = {}) => renderWithEvents(
|
2023-04-13 23:47:13 +03:00
|
|
|
<DropdownBtnMenu {...fromPartial<DropdownBtnMenuProps>({ toggle: jest.fn(), ...props })}>
|
|
|
|
the children
|
|
|
|
</DropdownBtnMenu>,
|
2022-07-17 10:29:50 +03:00
|
|
|
);
|
2021-09-24 21:04:16 +03:00
|
|
|
|
|
|
|
it('renders expected components', () => {
|
2022-07-17 10:29:50 +03:00
|
|
|
setUp();
|
|
|
|
const toggle = screen.getByRole('button');
|
2021-09-24 21:04:16 +03:00
|
|
|
|
2022-07-17 10:29:50 +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', () => {
|
2022-07-17 10:29:50 +03:00
|
|
|
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],
|
2022-07-17 10:29:50 +03:00
|
|
|
])('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
|
|
|
});
|
|
|
|
});
|