import IconButton from './IconButton';
import { mockMatchMedia, render, screen, userEvent } from '../test-utils';
import { Edit } from '@transferwise/icons';

mockMatchMedia();

describe('IconButton', () => {
  describe('onClick', () => {
    it('should respect onClick if rendered as HTML button', async () => {
      const handleClick = jest.fn();
      render(
        <IconButton onClick={handleClick}>
          <Edit />
        </IconButton>,
      );
      await userEvent.click(screen.getByRole('button'));
      expect(handleClick).toHaveBeenCalledTimes(1);
    });

    it('should respect onClick if rendered as HTML anchor', async () => {
      const handleClick = jest.fn();
      render(
        <IconButton href="#target" onClick={handleClick}>
          <Edit />
        </IconButton>,
      );
      await userEvent.click(screen.getByRole('link'));
      expect(handleClick).toHaveBeenCalledTimes(1);
    });
  });
});
