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

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

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

describe('Link', () => {
  describe('snapshot', () => {
    it('matches the previous snapshot', () => {
      const link = renderSnapshot(
        <div>
          <Link href="https://google.com">{'<a />'} element</Link>
          <Link onClick={noop}>{'<button />'} element</Link>
        </div>,
      );
      expect(link).toMatchSnapshot();
    });
  });

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

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