"use strict";

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

var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));

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

var _react = _interopRequireDefault(require("react"));

var _testUtils = require("react-dom/test-utils");

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

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

var _zh_CN = _interopRequireDefault(require("../locale/zh_CN"));

var _en_US = _interopRequireDefault(require("../locale/en_US"));

var props = {
  visible: true,
  actions: [{
    text: '操作一',
    onClick: jest.fn()
  }, {
    text: '操作二',
    onClick: jest.fn()
  }, {
    theme: 'danger',
    text: '操作三',
    onClick: jest.fn()
  }],
  onMaskClick: jest.fn(),
  onCancel: jest.fn()
};
describe('ActionSheet', function () {
  it('renders correctly', function () {
    var wrapper = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, props));
    expect(wrapper.asFragment()).toMatchSnapshot();
  });
  it('locale', function () {
    expect(_zh_CN.default.cancelText).toEqual('取消');
    expect(_en_US.default.cancelText).toEqual('Cancel');
  });
  it('onClick', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
    var click, _render, getByText, btn;

    return _regenerator.default.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            click = jest.fn();
            _render = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
              visible: true,
              actions: [{
                text: 'item1',
                onClick: function onClick() {
                  click();
                }
              }]
            })), getByText = _render.getByText;
            btn = getByText('item1');

            _react2.fireEvent.click(btn);

            _context.next = 6;
            return (0, _react2.waitFor)(function () {
              expect(click).toBeCalled();
            });

          case 6:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  })));
});
describe('UseActionSheet', function () {
  var container = document.createElement('div');
  it('mount correctly', function () {
    (0, _testUtils.act)(function () {
      var _ActionSheet$show = _index.default.show({
        actions: props.actions,
        mountContainer: container
      }),
          close = _ActionSheet$show.close;

      expect(container.childNodes.length).toBe(1);
      close();
    });
  });
});