"use strict";

var _jsxRuntime = require("react/jsx-runtime");

var _enzyme = require("enzyme");

var _Button = _interopRequireDefault(require("../../Button"));

var _Header = _interopRequireDefault(require("../../Header"));

var _Panel = _interopRequireDefault(require("../Panel"));

var _Panels = _interopRequireWildcard(require("../Panels"));

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

describe('Panels Specs', function () {
  test('should set {autoFocus} on child to "default-element" on first render', function () {
    // eslint-disable-next-line enact/prop-types
    var DivPanel = function DivPanel(_ref) {
      var autoFocus = _ref.autoFocus,
          id = _ref.id;
      return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        id: id,
        children: autoFocus
      });
    };

    var panels = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Panels["default"], {
      index: 0,
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(DivPanel, {})
    }));
    var expected = 'default-element';
    var actual = panels.find('DivPanel').prop('autoFocus');
    expect(actual).toBe(expected);
  });
  test('should set {autoFocus} on child to "default-element" when navigating to a higher index', function () {
    // eslint-disable-next-line enact/prop-types
    var DivPanel = function DivPanel(_ref2) {
      var autoFocus = _ref2.autoFocus,
          id = _ref2.id;
      return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        id: id,
        children: autoFocus
      });
    };

    var panels = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Panels["default"], {
      index: 0,
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(DivPanel, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(DivPanel, {
        id: "p2"
      })]
    }));
    panels.setProps({
      index: 1
    });
    var expected = 'default-element';
    var actual = panels.find('DivPanel#p2').prop('autoFocus');
    expect(actual).toBe(expected);
  });
  test('should not set {autoFocus} on child when navigating to a higher index when it has an autoFocus prop set', function () {
    // eslint-disable-next-line enact/prop-types
    var DivPanel = function DivPanel(_ref3) {
      var autoFocus = _ref3.autoFocus,
          id = _ref3.id;
      return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        id: id,
        children: autoFocus
      });
    };

    var panels = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Panels["default"], {
      index: 0,
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(DivPanel, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(DivPanel, {
        id: "p2",
        autoFocus: "last-focused"
      })]
    }));
    panels.setProps({
      index: 1
    });
    var expected = 'last-focused';
    var actual = panels.find('DivPanel#p2').prop('autoFocus');
    expect(actual).toBe(expected);
  });
  describe('with Panel and Header', function () {
    test('should render close button', function () {
      var panels = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Panels["default"], {
        index: 0,
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Panel["default"], {
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Header["default"], {
            title: "Panel Title"
          })
        })
      }));
      var closeButton = panels.find('Controls').find('Button');
      var expected = 1;
      var actual = closeButton.length;
      expect(actual).toBe(expected);
    });
    test('should not render close button when \'noCloseButton\' is set to true', function () {
      var panels = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Panels["default"], {
        index: 0,
        noCloseButton: true,
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Panel["default"], {
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Header["default"], {
            title: "Panel Title"
          })
        })
      }));
      var backButton = panels.find('Controls').find('Button');
      var expected = 0;
      var actual = backButton.length;
      expect(actual).toBe(expected);
    });
    test('should set close button "aria-label" to closeButtonAriaLabel', function () {
      var label = 'custom close button label';
      var panels = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Panels["default"], {
        closeButtonAriaLabel: label,
        index: 0,
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Panel["default"], {
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Header["default"], {
            title: "Panel Title"
          })
        })
      }));
      var expected = label;
      var actual = panels.find('Controls').find('Button').prop('aria-label');
      expect(actual).toBe(expected);
    });
    test('should insert additional Panels-level buttons into the global-navigation area when declaring controls prop', function () {
      var panels = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Panels["default"], {
        controls: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button["default"], {
          id: "controlButtonTest",
          children: "Control button"
        }),
        index: 0,
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Panel["default"], {
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Header["default"], {
            title: "Panel Title"
          })
        })
      }));
      var controlButton = panels.find('Controls').find('Button#controlButtonTest');
      var expected = 1;
      var actual = controlButton.length;
      expect(actual).toBe(expected);
    });
  });
  describe('childProps', function () {
    test('should not add aria-owns when noCloseButton is true and no controls', function () {
      var id = 'id';
      var childProps = {};
      var props = {
        childProps: childProps,
        noCloseButton: true,
        id: id
      };
      var expected = childProps;

      var actual = _Panels.PanelsBase.computed.childProps(props);

      expect(actual).toBe(expected);
    });
    test('should not add aria-owns when id is not set', function () {
      var childProps = {};
      var props = {
        childProps: childProps,
        noCloseButton: false
      };
      var expected = childProps;

      var actual = _Panels.PanelsBase.computed.childProps(props);

      expect(actual).toBe(expected);
    });
    test('should add aria-owns', function () {
      var id = 'id';
      var childProps = {};
      var props = {
        childProps: childProps,
        noCloseButton: false,
        id: id
      };
      var expected = "".concat(id, "-controls");

      var actual = _Panels.PanelsBase.computed.childProps(props)['aria-owns'];

      expect(actual).toBe(expected);
    });
    test('should append aria-owns', function () {
      var id = 'id';
      var ariaOwns = ':allthethings:';
      var childProps = {
        'aria-owns': ariaOwns
      };
      var props = {
        childProps: childProps,
        noCloseButton: false,
        id: id
      };
      var expected = "".concat(ariaOwns, " ").concat(id, "-controls");

      var actual = _Panels.PanelsBase.computed.childProps(props)['aria-owns'];

      expect(actual).toBe(expected);
    });
    test('should append aria-owns with noCloseButton and controls', function () {
      var id = 'id';
      var ariaOwns = ':allthethings:';
      var childProps = {
        'aria-owns': ariaOwns
      };
      var props = {
        childProps: childProps,
        controls: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
          children: "Hello"
        }),
        noCloseButton: true,
        id: id
      };
      var expected = "".concat(ariaOwns, " ").concat(id, "-controls");

      var actual = _Panels.PanelsBase.computed.childProps(props)['aria-owns'];

      expect(actual).toBe(expected);
    });
  });
});