/*
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.
*/

/* eslint-disable */
import React from 'react';
import { mount } from 'enzyme';
import styled from '../styled.js';
import { withStyletronProvider, withThemeProvider } from '../../test/test-utils.js';
import { LightTheme } from '../../themes/index.js';
jest.unmock('../styled.js');
test('styled', function () {
  var StyledMockButton = styled('button', function (_ref) {
    var $theme = _ref.$theme;
    return {
      backgroundColor: $theme.colors.primary400
    };
  });
  var TestComponent = withStyletronProvider(withThemeProvider(function () {
    return React.createElement(StyledMockButton, {
      id: "testButton"
    });
  }));
  var wrapper = mount(React.createElement(TestComponent, null));
  var button = wrapper.find('#testButton').children().at(0);
  expect(button.props().$theme).toBe(LightTheme);
  wrapper.unmount();
});
test('styled override prop', function () {
  var StyledMockButton = styled('button', {
    color: 'red'
  });

  var styleFn = function styleFn(props) {
    return {
      color: props.$color
    };
  };

  var TestComponent = withStyletronProvider(withThemeProvider(function () {
    return React.createElement("div", null, React.createElement(StyledMockButton, {
      id: "testButton1"
    }), React.createElement(StyledMockButton, {
      id: "testButton2",
      $style: {
        color: 'blue'
      }
    }), React.createElement(StyledMockButton, {
      id: "testButton3",
      $style: {
        borderRadius: '2px'
      }
    }), React.createElement(StyledMockButton, {
      id: "testButton4",
      $color: "red",
      $style: styleFn
    }), React.createElement(StyledMockButton, {
      id: "testButton5",
      $color: "blue",
      $style: styleFn
    }));
  }));
  var wrapper = mount(React.createElement(TestComponent, null)); // First button (no overrides) should have single class for red text color

  var button1 = wrapper.find('button#testButton1').getDOMNode();
  expect(button1.classList).toHaveLength(1);
  var colorRedClass = button1.classList.item(0); // Second button should have single class for blue text

  var button2 = wrapper.find('button#testButton2').getDOMNode();
  expect(button2.classList).toHaveLength(1);
  expect(button2.classList.item(0)).not.toBe(colorRedClass);
  var colorBlueClass = button2.classList.item(0); // Third button should have 2 classes, one for red text, one for border radius

  var button3 = wrapper.find('button#testButton3').getDOMNode();
  expect(button3.classList).toHaveLength(2);
  expect(button3.classList).toContain(colorRedClass); // Fourth button should have single red class

  var button4 = wrapper.find('button#testButton4').getDOMNode();
  expect(button4.classList).toHaveLength(1);
  expect(button4.classList).toContain(colorRedClass); // Fifth button should have single blue class

  var button5 = wrapper.find('button#testButton5').getDOMNode();
  expect(button5.classList).toHaveLength(1);
  expect(button5.classList).toContain(colorBlueClass);
  wrapper.unmount();
});
test('styled override styled component', function () {
  var StyledBase = styled('div', {
    color: 'red'
  });
  var StyledBaseOverride = styled(StyledBase, {
    color: 'blue'
  });

  var BaseComp = function BaseComp(props) {
    return React.createElement("div", props);
  };

  var StyledBaseComp = styled(BaseComp, {
    color: 'black'
  });
  var TestComponent = withStyletronProvider(function () {
    return React.createElement("div", null, React.createElement(StyledBase, null), React.createElement(StyledBaseOverride, null), React.createElement(StyledBaseComp, null));
  });
  var wrapper = mount(React.createElement(TestComponent, null));
  var base = wrapper.find(StyledBase).getDOMNode();
  expect(base.classList).toHaveLength(1);
  var redColorClass = base.classList.item(0); // BaseOverride should not have red color class

  var override = wrapper.find(StyledBaseOverride).getDOMNode();
  expect(override.classList).toHaveLength(1);
  expect(override.classList).not.toContain(redColorClass); // Making sure this doesn't throw an error

  var styledBase = wrapper.find(StyledBaseComp).getDOMNode();
  expect(styledBase.classList).toHaveLength(1);
  wrapper.unmount();
});