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

import type { LinkProps } from './link.proptypes';
import { Link } from './index';

const DEFAULT_PROPS: LinkProps = {
  href: 'https://wealthsimple.com',
  target: '_blank',
  children: 'test',
};

describe('Link', () => {
  describe('when given an href', () => {
    it('renders a link', () => {
      const link = mountWrappedComponent(<Link {...DEFAULT_PROPS} />);
      expect(link.exists('a')).toBe(true);
      expect(link.exists('button')).toBe(false);
    });

    itIsAccessible(<Link {...DEFAULT_PROPS} />);
  });

  describe('when given an onClick', () => {
    it('renders a button', () => {
      const link = mountWrappedComponent(<Link onClick={noop} />);
      expect(link.exists('a')).toBe(false);
      expect(link.exists('button')).toBe(true);
    });

    itIsAccessible(<Link {...DEFAULT_PROPS} onClick={noop} href={undefined} />);
  });

  describe('with onClick and href', () => {
    const element = <Link {...DEFAULT_PROPS} onClick={noop} />;

    it('returns a link', () => {
      const link = mountWrappedComponent(element);

      expect(link.exists('a')).toBe(true);
      expect(link.exists('button')).toBe(false);
    });

    itIsAccessible(element);
  });
});
