"use strict";

require("@testing-library/jest-dom");
var _react = require("@testing-library/react");
var _compose = _interopRequireDefault(require("ramda/src/compose"));
var _ConsumerDecorator = _interopRequireDefault(require("../ConsumerDecorator"));
var _ProviderDecorator = require("../../ProviderDecorator");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
var componentAProps = [];
var componentBProps = [];
var componentAState = {
  componentAState: 'componentAState'
};
var componentBState = {
  componentBState: 'componentBState'
};
var BaseComponentA = function BaseComponentA(props) {
  componentAProps = props;
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ProviderDecorator.AppContext.Provider, {
    value: "defaultValue",
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {})
  });
};
var ComponentADecorator = (0, _compose["default"])((0, _ProviderDecorator.ProviderDecorator)({
  state: componentAState
}), (0, _ConsumerDecorator["default"])({
  handlers: {
    defaultHandler: jest.fn()
  },
  // added for code coverage purposes. `mount` is not accessible through props
  mount: function mount() {},
  mapStateToProps: function mapStateToProps() {
    return {
      defaultState: componentAState.componentAState
    };
  }
}));
var ComponentA = ComponentADecorator(BaseComponentA);

// ComponentB created for testing `mapStateToProps` defined as an object
var BaseComponentB = function BaseComponentB(props) {
  componentBProps = props;
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ProviderDecorator.AppContext.Provider, {
    value: "test",
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {})
  });
};
var ComponentBDecorator = (0, _compose["default"])((0, _ProviderDecorator.ProviderDecorator)({
  state: componentBState
}), (0, _ConsumerDecorator["default"])({
  mapStateToProps: {
    stringProp: 'stringProp',
    functionProp: jest.fn(function () {
      return 'functionProp';
    })
  }
}));
var ComponentB = ComponentBDecorator(BaseComponentB);
describe('ConsumerDecorator specs', function () {
  test('should pass a handler to the wrapped component', function () {
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(ComponentA, {}));
    var expected = 'function';
    var actual = typeof componentAProps.defaultHandler;
    expect(actual).toBe(expected);
  });
  test('should pass the `componentAState` state to props to the wrapped component', function () {
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(ComponentA, {}));
    var expected = 'componentAState';
    var actual = componentAProps.defaultState;
    expect(actual).toBe(expected);
  });
  test('should pass the state to props if the type is function', function () {
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(ComponentB, {}));
    var actual = componentBProps.functionProp;
    expect(actual).not.toBe(null);
  });
  test('should not pass the state to props if the type is not function', function () {
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(ComponentB, {}));
    var actual = componentBProps.stringProp;

    // eslint-disable-next-line no-undefined
    expect(actual).toBe(undefined);
  });
});