CopyButton.test.tsx 879 B

12345678910111213141516171819202122232425
  1. import { screen } from '@testing-library/dom'
  2. import userEvent from '@testing-library/user-event'
  3. import { expect, test, vi } from 'vitest'
  4. import CopyButton from '@/components/ui/CopyButton'
  5. import { render } from '@/tests/helpers'
  6. test('shows copied text', async () => {
  7. const callback = vi.fn()
  8. render(<CopyButton text="some text" onClick={callback} />)
  9. await userEvent.click(await screen.findByText('Copy'))
  10. await screen.findByText('Copied')
  11. expect(callback).toBeCalled()
  12. })
  13. test('does not show a green copied icon for primary buttons', async () => {
  14. const { container } = render(<CopyButton text="some text" type="primary" />)
  15. await userEvent.click(await screen.findByText('Copy'))
  16. await screen.findByText('Copied')
  17. const icon = container.querySelector('svg')
  18. expect(icon).toHaveClass('text-inherit')
  19. expect(icon).not.toHaveClass('text-brand')
  20. })