import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import { fireEvent, render } from '@testing-library/react';
import React from 'react';
import DatePicker from '../index';
import Button from '../../button';
describe('DatePicker', function () {
  it('snapshot', function () {
    var wrapper = render( /*#__PURE__*/React.createElement(DatePicker, null));
    expect(wrapper.asFragment()).toMatchSnapshot();
  });
  it('should trigger onConfirm when press ok button', function () {
    var onConfirmFn = jest.fn();
    render( /*#__PURE__*/React.createElement(DatePicker, {
      value: new Date('2009/3/4'),
      visible: true,
      onConfirm: onConfirmFn
    }));
    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();
    render( /*#__PURE__*/React.createElement(DatePicker, {
      value: new Date('2009/3/4'),
      visible: true,
      onCancel: onCancelFn
    }));
    fireEvent.click(document.body.querySelectorAll('.za-picker__cancel')[0]);
    expect(onCancelFn).toBeCalled();
  });
  it('static method prompt', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
    var confirm, cancel, _render, getByText, btn;

    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            confirm = jest.fn();
            cancel = jest.fn();
            _render = render( /*#__PURE__*/React.createElement(Button, {
              size: "xs",
              onClick: /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
                return _regeneratorRuntime.wrap(function _callee$(_context) {
                  while (1) {
                    switch (_context.prev = _context.next) {
                      case 0:
                        _context.next = 2;
                        return DatePicker.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');
            fireEvent.click(btn);
            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);

            fireEvent.click(getByText('date picker cancel'));
            expect(cancel).toBeCalled();

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