2022-07-10 21:42:58 +03:00
|
|
|
import { screen } from '@testing-library/react';
|
2020-12-25 12:39:54 +03:00
|
|
|
import { PropsWithChildren } from 'react';
|
2020-12-25 12:43:36 +03:00
|
|
|
import { DropdownBtn, DropdownBtnProps } from '../../src/utils/DropdownBtn';
|
2022-07-10 21:42:58 +03:00
|
|
|
import { renderWithEvents } from '../__helpers__/setUpTest';
|
2020-12-25 12:39:54 +03:00
|
|
|
|
2020-12-25 12:43:36 +03:00
|
|
|
describe('<DropdownBtn />', () => {
|
2022-07-10 21:42:58 +03:00
|
|
|
const setUp = (props: PropsWithChildren<DropdownBtnProps>) => renderWithEvents(
|
|
|
|
<DropdownBtn children="foo" {...props} />,
|
|
|
|
);
|
2020-12-25 12:39:54 +03:00
|
|
|
|
2022-07-10 21:42:58 +03:00
|
|
|
it.each([['foo'], ['bar'], ['baz']])('displays provided text in button', (text) => {
|
|
|
|
setUp({ text });
|
|
|
|
expect(screen.getByRole('button')).toHaveTextContent(text);
|
2020-12-25 12:39:54 +03:00
|
|
|
});
|
|
|
|
|
2022-07-10 21:42:58 +03:00
|
|
|
it.each([['foo'], ['bar'], ['baz']])('displays provided children in menu', async (children) => {
|
|
|
|
const { user } = setUp({ text: '', children });
|
2020-12-25 12:39:54 +03:00
|
|
|
|
2022-07-10 21:42:58 +03:00
|
|
|
await user.click(screen.getByRole('button'));
|
|
|
|
expect(screen.getByRole('menu')).toHaveTextContent(children);
|
2020-12-25 12:39:54 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it.each([
|
2022-03-26 14:17:42 +03:00
|
|
|
[undefined, 'dropdown-btn__toggle btn-block'],
|
|
|
|
['', 'dropdown-btn__toggle btn-block'],
|
|
|
|
['foo', 'dropdown-btn__toggle btn-block foo'],
|
|
|
|
['bar', 'dropdown-btn__toggle btn-block bar'],
|
2020-12-25 12:39:54 +03:00
|
|
|
])('includes provided classes', (className, expectedClasses) => {
|
2022-07-10 21:42:58 +03:00
|
|
|
setUp({ text: '', className });
|
|
|
|
expect(screen.getByRole('button')).toHaveClass(expectedClasses);
|
2020-12-25 12:39:54 +03:00
|
|
|
});
|
2021-06-22 22:12:06 +03:00
|
|
|
|
|
|
|
it.each([
|
2022-07-10 21:42:58 +03:00
|
|
|
[100, 'min-width: 100px; '],
|
|
|
|
[250, 'min-width: 250px; '],
|
|
|
|
[undefined, ''],
|
|
|
|
])('renders proper styles when minWidth is provided', async (minWidth, expectedStyle) => {
|
|
|
|
const { user } = setUp({ text: '', minWidth });
|
|
|
|
|
|
|
|
await user.click(screen.getByRole('button'));
|
|
|
|
expect(screen.getByRole('menu')).toHaveAttribute(
|
|
|
|
'style',
|
2022-10-05 00:17:12 +03:00
|
|
|
`${expectedStyle}position: absolute; left: 0px; top: 0px; transform: translate(0px, 0px);`,
|
2022-07-10 21:42:58 +03:00
|
|
|
);
|
2021-06-22 22:12:06 +03:00
|
|
|
});
|
2020-12-25 12:39:54 +03:00
|
|
|
});
|