/*
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.
*/
import * as React from 'react';
import { shallow } from 'enzyme';
import { LightTheme, createTheme, lightThemePrimitives } from '../../themes/index.js';
import { BaseButton, StartEnhancer, EndEnhancer, getStyleForKind, getStyleForShape } from '../styled-components.js';
import { KIND, SIZE, SHAPE } from '../constants.js';

function makeTest(_ref) {
  var title = _ref.title,
      Component = _ref.component,
      _ref$props = _ref.props,
      props = _ref$props === void 0 ? {} : _ref$props,
      _ref$children = _ref.children,
      children = _ref$children === void 0 ? null : _ref$children,
      _ref$snapshotName = _ref.snapshotName,
      snapshotName = _ref$snapshotName === void 0 ? 'correct styles' : _ref$snapshotName;
  // $FlowFixMe
  test(title, function () {
    // $FlowFixMe
    var shallowed = shallow(React.createElement(Component, props, children));
    expect(shallowed.instance().getStyles()).toMatchSnapshot(snapshotName);
  });
}

var allKinds = Object.values(KIND);
var allSizes = Object.values(SIZE);
var allShapes = Object.values(SHAPE);
var allLoadingStates = [false, true];
describe('Button Styled Components', function () {
  allKinds.forEach(function ($kind) {
    allLoadingStates.forEach(function ($isLoading) {
      // $FlowFixMe
      test("getStyleForKind ".concat($kind, " and loading ").concat($isLoading), function () {
        expect( // $FlowFixMe
        getStyleForKind({
          $theme: LightTheme,
          $kind: $kind,
          $isLoading: $isLoading
        })).toMatchSnapshot();
      });
    });
  });
  allShapes.forEach(function ($shape) {
    allSizes.forEach(function ($size) {
      // $FlowFixMe
      test("getStyleForShape ".concat($shape, " ").concat($size), function () {
        expect( // $FlowFixMe
        getStyleForShape({
          $theme: LightTheme,
          $shape: $shape,
          $size: $size
        })).toMatchSnapshot();
      });
    });
  });
  allShapes.forEach(function (shape) {
    makeTest({
      title: "BaseButton - basic render",
      component: BaseButton
    });
  });
  test("BaseButton - respects useRoundedCorners", function () {
    var theme = createTheme(lightThemePrimitives, {
      borders: {
        useRoundedCorners: false
      }
    });
    var rendered = shallow(React.createElement(BaseButton, {
      $theme: theme
    }, "Test"));
    expect(rendered.instance().getStyles().borderBottomLeftRadius).toMatch('0px');
    expect(rendered.instance().getStyles().borderBottomRightRadius).toMatch('0px');
    expect(rendered.instance().getStyles().borderTopLeftRadius).toMatch('0px');
    expect(rendered.instance().getStyles().borderTopRightRadius).toMatch('0px');
  });
  makeTest({
    title: 'StartEnhancer - basic render',
    component: StartEnhancer
  });
  makeTest({
    title: 'EndEnhancer - basic render',
    component: EndEnhancer
  });
});