function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
import React from 'react';
import PropTypes from 'prop-types';
import { render } from '@testing-library/react';
import has from 'lodash/fp/has';
import { mockTranslate } from '@coorpacademy/translate';
import Provider, { WebContext } from '../atom/provider';
export const renderWithContext = (component, options = {}) => {
  const {
    context = {},
    useLegacyProvider = false,
    ...renderOptions
  } = options;
  // uses mockTranslate as a default translate function
  const {
    translate = mockTranslate,
    ...rest
  } = context;
  const wrapper = ({
    children
  }) => {
    const hasContextTypes = useLegacyProvider || has(['type', 'contextTypes'], children);
    // eslint-disable-next-line no-console
    if (!hasContextTypes) console.log('ContextTypes not found, using WebContext');
    return hasContextTypes ? /*#__PURE__*/React.createElement(Provider, _extends({}, rest, {
      translate: translate
    }), children) : /*#__PURE__*/React.createElement(WebContext, _extends({}, rest, {
      translate: translate
    }), children);
  };
  wrapper.propTypes = process.env.NODE_ENV !== "production" ? {
    children: PropTypes.node
  } : {};
  return render(component, {
    ...renderOptions,
    wrapper
  });
};
//# sourceMappingURL=render-with-context.js.map