"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 = require("@testing-library/react");

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

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

var _button = _interopRequireDefault(require("../../button"));

describe('DatePicker', function () {
  it('snapshot', function () {
    var wrapper = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, null));
    expect(wrapper.asFragment()).toMatchSnapshot();
  });
  it('should trigger onConfirm when press ok button', function () {
    var onConfirmFn = jest.fn();
    (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, {
      value: new Date('2009/3/4'),
      visible: true,
      onConfirm: onConfirmFn
    }));

    _react.fireEvent.click(document.body.querySelectorAll('.za-picker__confirm')[0]);

    expect(onConfirmFn).toBeCalled();
  });
  it('should trigger onCancel when press cancel button', function () {
    var onCancelFn = jest.fn();
    (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, {
      value: new Date('2009/3/4'),
      visible: true,
      onCancel: onCancelFn
    }));

    _react.fireEvent.click(document.body.querySelectorAll('.za-picker__cancel')[0]);

    expect(onCancelFn).toBeCalled();
  });
  it('static method prompt', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
    var confirm, cancel, _render, getByText, btn;

    return _regenerator.default.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            confirm = jest.fn();
            cancel = jest.fn();
            _render = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_button.default, {
              size: "xs",
              onClick: /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
                return _regenerator.default.wrap(function _callee$(_context) {
                  while (1) {
                    switch (_context.prev = _context.next) {
                      case 0:
                        _context.next = 2;
                        return _index.default.prompt({
                          defaultValue: new Date('2023/2/23'),
                          onConfirm: confirm,
                          onCancel: cancel,
                          confirmText: 'date picker confirm',
                          cancelText: 'date picker cancel'
                        });

                      case 2:
                      case "end":
                        return _context.stop();
                    }
                  }
                }, _callee);
              }))
            }, "date picker")), getByText = _render.getByText;
            btn = getByText('date picker');

            _react.fireEvent.click(btn);

            _react.fireEvent.click(getByText('date picker confirm'));

            expect(confirm).toHaveBeenCalledWith(new Date('2023/2/23'), [{
              "label": "2023年",
              "value": 2023
            }, {
              "label": "2月",
              "value": 2
            }, {
              "label": "23日",
              "value": 23
            }]); // fireEvent.click(btn);

            _react.fireEvent.click(getByText('date picker cancel'));

            expect(cancel).toBeCalled();

          case 9:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  })));
});