"use strict";

var _react = _interopRequireDefault(require("react"));

var _enzyme = require("enzyme");

var _styledComponents = require("../styled-components");

var _button = _interopRequireDefault(require("../button"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/*
Copyright (c) 2018 Uber Technologies, Inc.

This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
describe('Button Component', function () {
  test('basic render', function () {
    var component = (0, _enzyme.mount)(_react.default.createElement(_button.default, null));
    expect(component.find(_styledComponents.StartEnhancer)).not.toExist();
    expect(component.find(_styledComponents.EndEnhancer)).not.toExist();
    component.setProps({
      startEnhancer: 'start',
      endEnhancer: 'end'
    });
    expect(component.find(_styledComponents.StartEnhancer)).toExist();
    expect(component.find(_styledComponents.EndEnhancer)).toExist();
  });
  test('renders with components overrides', function () {
    var NewStartEnhancer = function NewStartEnhancer() {
      return _react.default.createElement("div", null);
    };

    var props = {
      startEnhancer: function startEnhancer() {
        return null;
      },
      overrides: {
        StartEnhancer: NewStartEnhancer
      }
    };
    var component = (0, _enzyme.mount)(_react.default.createElement(_button.default, props));
    expect(component.find(_styledComponents.StartEnhancer)).not.toExist();
    expect(component.find(NewStartEnhancer)).toExist();
  });
  test('renders with loading spinner', function () {
    var component = (0, _enzyme.mount)(_react.default.createElement(_button.default, null));
    expect(component.find(_styledComponents.LoadingSpinner)).not.toExist();
    component.setProps({
      isLoading: true
    });
    expect(component.find(_styledComponents.LoadingSpinner)).toExist();
  });
  test('onClick called with event', function () {
    var onClick = jest.fn();
    var component = (0, _enzyme.mount)(_react.default.createElement(_button.default, {
      onClick: onClick
    }));
    component.simulate('click', {
      target: 'foo'
    });
    expect(onClick).toHaveBeenCalledTimes(1);
    expect(onClick.mock.calls[0][0]).toMatchObject({
      target: 'foo'
    });
  });
  test('internalOnClick prevents external onClick while loading', function () {
    var props = {
      onClick: jest.fn(),
      isLoading: true
    };
    var component = (0, _enzyme.mount)(_react.default.createElement(_button.default, props));
    component.instance().internalOnClick();
    expect(props.onClick.mock.calls.length).toBe(0);
    component.setProps({
      isLoading: false
    });
    component.instance().internalOnClick();
    expect(props.onClick.mock.calls.length).toBe(1);
  });
});