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