import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import React from 'react';
import { act } from 'react-dom/test-utils';
import { fireEvent, render, waitFor } from '@testing-library/react';
import ActionSheet from '../index';
import zhCN from '../locale/zh_CN';
import enUS from '../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 = render( /*#__PURE__*/React.createElement(ActionSheet, props));
    expect(wrapper.asFragment()).toMatchSnapshot();
  });
  it('locale', function () {
    expect(zhCN.cancelText).toEqual('取消');
    expect(enUS.cancelText).toEqual('Cancel');
  });
  it('onClick', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
    var click, _render, getByText, btn;

    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            click = jest.fn();
            _render = render( /*#__PURE__*/React.createElement(ActionSheet, {
              visible: true,
              actions: [{
                text: 'item1',
                onClick: function onClick() {
                  click();
                }
              }]
            })), getByText = _render.getByText;
            btn = getByText('item1');
            fireEvent.click(btn);
            _context.next = 6;
            return 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 () {
    act(function () {
      var _ActionSheet$show = ActionSheet.show({
        actions: props.actions,
        mountContainer: container
      }),
          close = _ActionSheet$show.close;

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