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

27 lines
826 B
TypeScript
Raw Normal View History

2021-01-24 20:06:11 +03:00
import { CopyToClipboardIcon } from '../../src/utils/CopyToClipboardIcon';
import { renderWithEvents } from '../__mocks__/setUpTest';
2021-01-24 20:06:11 +03:00
describe('<CopyToClipboardIcon />', () => {
const onCopy = jest.fn();
const setUp = (text = 'foo') => renderWithEvents(<CopyToClipboardIcon text={text} onCopy={onCopy} />);
afterEach(jest.clearAllMocks);
2021-01-24 20:06:11 +03:00
2021-03-06 19:25:09 +03:00
it('wraps expected components', () => {
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
expect(onCopy).not.toHaveBeenCalled();
container.firstElementChild && await user.click(container.firstElementChild);
expect(onCopy).toHaveBeenCalledWith(text, false);
2021-01-24 20:06:11 +03:00
});
});