2021-01-24 20:06:11 +03:00
|
|
|
import { CopyToClipboardIcon } from '../../src/utils/CopyToClipboardIcon';
|
2022-07-10 20:44:49 +03:00
|
|
|
import { renderWithEvents } from '../__helpers__/setUpTest';
|
2021-01-24 20:06:11 +03:00
|
|
|
|
|
|
|
describe('<CopyToClipboardIcon />', () => {
|
2023-05-27 12:57:26 +03:00
|
|
|
const onCopy = vi.fn();
|
2022-07-10 00:03:21 +03:00
|
|
|
const setUp = (text = 'foo') => renderWithEvents(<CopyToClipboardIcon text={text} onCopy={onCopy} />);
|
2022-06-10 21:29:42 +03:00
|
|
|
|
2023-05-27 12:57:26 +03:00
|
|
|
afterEach(vi.clearAllMocks);
|
2021-01-24 20:06:11 +03:00
|
|
|
|
2021-03-06 19:25:09 +03:00
|
|
|
it('wraps expected components', () => {
|
2022-06-10 21:29:42 +03:00
|
|
|
const { container } = setUp();
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it.each([
|
|
|
|
['text'],
|
|
|
|
['bar'],
|
|
|
|
['baz'],
|
|
|
|
])('copies content to clipboard when clicked', async (text) => {
|
|
|
|
const { user, container } = setUp(text);
|
2021-01-24 20:06:11 +03:00
|
|
|
|
2022-06-10 21:29:42 +03:00
|
|
|
expect(onCopy).not.toHaveBeenCalled();
|
|
|
|
container.firstElementChild && await user.click(container.firstElementChild);
|
|
|
|
expect(onCopy).toHaveBeenCalledWith(text, false);
|
2021-01-24 20:06:11 +03:00
|
|
|
});
|
|
|
|
});
|