"use strict";

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

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

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

var _bem = require("@zarm-design/bem");

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

var _ConfigProvider = require("../../config-provider/ConfigProvider");

var _index = _interopRequireDefault(require("../index"));

var bem = (0, _bem.createBEM)('panel', {
  prefixCls: _ConfigProvider.defaultConfig.prefixCls
});
describe('Panel', function () {
  test('snapshots with title and more props', function () {
    var _render = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, {
      title: "title",
      more: "more"
    }, "body")),
        asFragment = _render.asFragment;

    expect(asFragment().firstChild).toMatchSnapshot();
  });
  test('should not render header if do not have title and more props', function () {
    var _render2 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, null, "body")),
        container = _render2.container;

    expect(container.children).toHaveLength(1);
    expect(container.querySelector(".".concat(bem('header')))).not.toBeInTheDocument();
    expect(container.querySelector(".".concat(bem('body')))).toBeInTheDocument();
  });
  test('should accept custom css vars', function () {
    var _render3 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, {
      title: "title",
      style: {
        '--header-padding': 0
      }
    }, "body")),
        container = _render3.container;

    expect(container.querySelector(".".concat(bem('header')))).toHaveStyle({
      padding: 'var(--header-padding)'
    });
  });
  test('should forward ref created by React.createRef() API', function (done) {
    var ref = /*#__PURE__*/_react2.default.createRef();

    (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, {
      bordered: false,
      ref: ref
    }, "body"));
    if (!ref.current) return done('ref.current does not exist');
    expect(ref.current.className).toEqual('za-panel');
    expect(ref.current.nodeName.toLocaleLowerCase()).toBe('div');
    done();
  });
  test('should forward ref created by useRef() hook', function (done) {
    expect.assertions(2);

    var TestComp = function TestComp() {
      var ref = (0, _react2.useRef)(null);
      (0, _react2.useEffect)(function () {
        if (ref.current) {
          expect(ref.current.className).toEqual('za-panel');
          expect(ref.current.nodeName.toLocaleLowerCase()).toBe('div');
          done();
        }
      }, []);
      return /*#__PURE__*/_react2.default.createElement(_index.default, {
        bordered: false,
        ref: ref
      }, "body");
    };

    (0, _react.render)( /*#__PURE__*/_react2.default.createElement(TestComp, null));
  });
});