"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _react = require("@testing-library/react");

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

var _ConfigProvider = _interopRequireWildcard(require("../ConfigProvider"));

var customRender = function customRender(ui, _ref) {
  var providerProps = _ref.providerProps,
      renderOptions = (0, _objectWithoutProperties2.default)(_ref, ["providerProps"]);
  return (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_ConfigProvider.default, providerProps, ui), renderOptions);
};

describe('ConfigProvider', function () {
  test('should provide default context config via default props', function () {
    customRender( /*#__PURE__*/_react2.default.createElement(_ConfigProvider.ConfigContext.Consumer, null, function (value) {
      return /*#__PURE__*/_react2.default.createElement(_react2.default.Fragment, null, /*#__PURE__*/_react2.default.createElement("span", {
        "data-testid": "prefixCls"
      }, value.prefixCls), /*#__PURE__*/_react2.default.createElement("span", {
        "data-testid": "safeArea"
      }, value.safeArea ? 1 : 0));
    }), {
      providerProps: {}
    });
    expect(_react.screen.getByTestId('prefixCls').textContent).toEqual(_ConfigProvider.defaultConfig.prefixCls);
    expect(document.body.getAttribute('data-theme')).toEqual(_ConfigProvider.defaultConfig.theme);
    expect(!!+_react.screen.getByTestId('safeArea').textContent).toEqual(_ConfigProvider.defaultConfig.safeArea);
  });
  test('should custum the value from context provider', function () {
    customRender( /*#__PURE__*/_react2.default.createElement(_ConfigProvider.ConfigContext.Consumer, null, function (value) {
      return /*#__PURE__*/_react2.default.createElement("span", null, "theme: ", value.theme);
    }), {
      providerProps: {
        theme: 'dark'
      }
    });
    expect(document.body.getAttribute('data-theme')).toEqual('dark');
  });
  test('should throw error if children has more than one child', function () {
    var errorSpy = jest.spyOn(console, 'error').mockImplementation(function () {
      return 'silence';
    });
    expect(function () {
      return (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_ConfigProvider.default, null, /*#__PURE__*/_react2.default.createElement("span", null, "child 1"), /*#__PURE__*/_react2.default.createElement("span", null, "child 2")));
    }).toThrow();
    expect(errorSpy).toBeCalled();
  });
});