// @flow
import React from 'react';
import {
  mountWrappedComponent,
  renderSnapshot,
  itIsAccessible,
} from '../../../../utils/tests';
import { BackButton } from './index';
import { type BackButtonProps } from './back-button.proptypes';

const DEFAULT_PROPS: BackButtonProps = {
  disabled: false,
  ariaLabel: 'Go Back',
  onClick: () => {},
};

describe('BackButton', () => {
  describe('snapshot', () => {
    it('matches the previous snapshot', () => {
      expect(
        renderSnapshot(<BackButton {...DEFAULT_PROPS} />),
      ).toMatchSnapshot();
    });
  });

  it('passes valid props to child button', () => {
    const backButton = mountWrappedComponent(<BackButton {...DEFAULT_PROPS} />);
    expect(backButton.find('button').props()).toEqual({
      type: 'button',
      children: expect.anything(),
      className: expect.any(String),
      'aria-label': DEFAULT_PROPS.ariaLabel,
      onClick: DEFAULT_PROPS.onClick,
      disabled: DEFAULT_PROPS.disabled,
    });
  });

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