"use strict";

var _react = _interopRequireDefault(require("react"));
var _testUtilities = require("testUtilities");
var _portaledSidebar = require("./portaled-sidebar");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
var TEST_ANCHOR = "test text";
describe("PortalSidebar component test", function () {
  it(" * should render with no props", function () {
    var _renderWithProviders = (0, _testUtilities.renderWithProviders)(/*#__PURE__*/_react["default"].createElement(_portaledSidebar.PortalSidebar, null)),
      container = _renderWithProviders.container;
    // somehow queryselector does not searches for monotags like <aside />
    var aside = container && container.nextSibling && container.nextSibling.firstChild;
    expect(aside && aside.nodeName).toBe("ASIDE");
  });
  it(" * should render on the right side", function () {
    var _renderWithProviders2 = (0, _testUtilities.renderWithProviders)(/*#__PURE__*/_react["default"].createElement(_portaledSidebar.PortalSidebar, {
        right: true
      }, TEST_ANCHOR)),
      queryByText = _renderWithProviders2.queryByText;
    var result = queryByText(TEST_ANCHOR);
    expect(result && result.textContent).not.toBeNull();
  });
  it(" * should render with children", function () {
    var _renderWithProviders3 = (0, _testUtilities.renderWithProviders)(/*#__PURE__*/_react["default"].createElement(_portaledSidebar.PortalSidebar, null, TEST_ANCHOR)),
      queryByText = _renderWithProviders3.queryByText;
    var result = queryByText(TEST_ANCHOR);
    expect(result && result.textContent).toBe(TEST_ANCHOR);
  });
  it(" * should be closed after `Esc` pressed", function () {
    var handler = jest.fn();
    var _renderWithProviders4 = (0, _testUtilities.renderWithProviders)(/*#__PURE__*/_react["default"].createElement(_portaledSidebar.PortalSidebar, {
        closeOnEsc: true,
        onClose: handler
      }, TEST_ANCHOR)),
      queryByText = _renderWithProviders4.queryByText;
    var result = queryByText(TEST_ANCHOR);
    if (result) {
      (0, _testUtilities.act)(function () {
        var event = new KeyboardEvent("keydown", {
          keyCode: 27
        });
        document.dispatchEvent(event);
      });
    }
    expect(handler).toHaveBeenCalledTimes(1);
  });
});