// @flow
import React from 'react';
import { renderSnapshot, mountWrappedComponent } from '../../../../utils/tests';

import type { SecondaryButtonProps } from './secondary-button.proptypes';
import { SecondaryButton } from './index';

const ACTUAL_BUTTON_PROPS: SecondaryButtonProps = {
  disabled: false,
  onClick() {},
};

const LINK_BUTTON_PROPS: SecondaryButtonProps = {
  href: 'https://google.com',
};

describe('SecondaryButton', () => {
  describe('ActualButton', () => {
    it('renders a button element if given an onClick', () => {
      const secondaryButton = mountWrappedComponent(
        <SecondaryButton {...ACTUAL_BUTTON_PROPS} />,
      );
      expect(secondaryButton.exists('button')).toBe(true);
      expect(secondaryButton.exists('a')).toBe(false);
    });

    it('matches the previous snapshot', () => {
      const secondaryButton = renderSnapshot(
        <SecondaryButton {...ACTUAL_BUTTON_PROPS} />,
      );
      expect(secondaryButton).toMatchSnapshot();
    });
  });

  describe('LinkButton', () => {
    it('renders an anchor element if given an href', () => {
      const secondaryButton = mountWrappedComponent(
        <SecondaryButton {...LINK_BUTTON_PROPS} />,
      );
      expect(secondaryButton.exists('button')).toBe(false);
      expect(secondaryButton.exists('a')).toBe(true);
    });

    it('matches the previous snapshot', () => {
      const secondaryButton = renderSnapshot(
        <SecondaryButton {...LINK_BUTTON_PROPS} />,
      );
      expect(secondaryButton).toMatchSnapshot();
    });
  });
});
