import { render } from '@testing-library/react';
import { createBEM } from '@zarm-design/bem';
import React, { useEffect, useRef } from 'react';
import { defaultConfig } from '../../config-provider/ConfigProvider';
import Panel from '../index';
var bem = createBEM('panel', {
  prefixCls: defaultConfig.prefixCls
});
describe('Panel', function () {
  test('snapshots with title and more props', function () {
    var _render = render( /*#__PURE__*/React.createElement(Panel, {
      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 = render( /*#__PURE__*/React.createElement(Panel, 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 = render( /*#__PURE__*/React.createElement(Panel, {
      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__*/React.createRef();
    render( /*#__PURE__*/React.createElement(Panel, {
      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 = useRef(null);
      useEffect(function () {
        if (ref.current) {
          expect(ref.current.className).toEqual('za-panel');
          expect(ref.current.nodeName.toLocaleLowerCase()).toBe('div');
          done();
        }
      }, []);
      return /*#__PURE__*/React.createElement(Panel, {
        bordered: false,
        ref: ref
      }, "body");
    };

    render( /*#__PURE__*/React.createElement(TestComp, null));
  });
});