// @flow
import React from 'react';
import { mountWrappedComponent, itIsAccessible } from '../../../../utils/tests';
import { UnstyledButton } from './index';
import type { UnstyledButtonProps } from './unstyled-button.proptypes';

const DEFAULT_PROPS: UnstyledButtonProps = {
  onClick: jest.fn(),
};

describe('UnstyledButton', () => {
  it('calls the onClick handler when clicked', () => {
    const button = mountWrappedComponent(
      <UnstyledButton {...DEFAULT_PROPS} />,
    ).find('button');
    expect(DEFAULT_PROPS.onClick).toHaveBeenCalledTimes(0);
    button.simulate('click');
    expect(DEFAULT_PROPS.onClick).toHaveBeenCalledTimes(1);
  });

  it('sets border radius based on prop', () => {
    const BORDER_RADIUS = 30;
    const button = mountWrappedComponent(
      <UnstyledButton {...DEFAULT_PROPS} borderRadius={BORDER_RADIUS} />,
    );
    expect(button).toHaveStyleRule('border-radius', `${BORDER_RADIUS}px`);
  });

  itIsAccessible(<UnstyledButton {...DEFAULT_PROPS}>test</UnstyledButton>);
});
