clipboardTooltip.spec.tsx 923 B

12345678910111213141516171819202122232425262728293031
  1. import copy from 'copy-text-to-clipboard';
  2. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  3. import ClipboardTooltip from 'sentry/components/clipboardTooltip';
  4. jest.mock('copy-text-to-clipboard');
  5. describe('ClipboardTooltip', function () {
  6. it('renders', async function () {
  7. const title = 'tooltip content';
  8. const content = 'This text displays a tooltip when hovering';
  9. render(
  10. <ClipboardTooltip title={title}>
  11. <span>{content}</span>
  12. </ClipboardTooltip>
  13. );
  14. expect(screen.getByText(content)).toBeInTheDocument();
  15. userEvent.hover(screen.getByText(content));
  16. await screen.findByText(title);
  17. expect(screen.getByLabelText('Copy to clipboard')).toBeInTheDocument();
  18. userEvent.click(screen.getByLabelText('Copy to clipboard'), undefined, {
  19. skipPointerEventsCheck: true,
  20. });
  21. expect(copy).toHaveBeenCalledWith(title);
  22. });
  23. });