import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import { render, screen } from '@testing-library/react';
import React from 'react';
import ConfigProvider, { ConfigContext, defaultConfig } from '../ConfigProvider';

var customRender = function customRender(ui, _ref) {
  var providerProps = _ref.providerProps,
      renderOptions = _objectWithoutProperties(_ref, ["providerProps"]);

  return render( /*#__PURE__*/React.createElement(ConfigProvider, providerProps, ui), renderOptions);
};

describe('ConfigProvider', function () {
  test('should provide default context config via default props', function () {
    customRender( /*#__PURE__*/React.createElement(ConfigContext.Consumer, null, function (value) {
      return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", {
        "data-testid": "prefixCls"
      }, value.prefixCls), /*#__PURE__*/React.createElement("span", {
        "data-testid": "safeArea"
      }, value.safeArea ? 1 : 0));
    }), {
      providerProps: {}
    });
    expect(screen.getByTestId('prefixCls').textContent).toEqual(defaultConfig.prefixCls);
    expect(document.body.getAttribute('data-theme')).toEqual(defaultConfig.theme);
    expect(!!+screen.getByTestId('safeArea').textContent).toEqual(defaultConfig.safeArea);
  });
  test('should custum the value from context provider', function () {
    customRender( /*#__PURE__*/React.createElement(ConfigContext.Consumer, null, function (value) {
      return /*#__PURE__*/React.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 render( /*#__PURE__*/React.createElement(ConfigProvider, null, /*#__PURE__*/React.createElement("span", null, "child 1"), /*#__PURE__*/React.createElement("span", null, "child 2")));
    }).toThrow();
    expect(errorSpy).toBeCalled();
  });
});