"use strict";

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

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

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

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

var CAR_PLATE = {
  columns: 7,
  keys: [{
    text: '沪'
  }, {
    text: '苏'
  }, {
    text: '黑',
    disabled: true
  }, {
    text: '辽',
    disabled: true
  }, {
    text: 'ok',
    rowSpan: 2,
    colSpan: 2
  }]
};
describe('Keyboard', function () {
  afterEach(_react2.cleanup);
  it('should render keyboard dom', function () {
    var _render = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
      "data-testid": "root"
    })),
        container = _render.container;

    expect(container).toMatchSnapshot();
    expect(_react2.screen.getByTestId('root')).toBeTruthy();
    expect(_react2.screen.getByTestId('root').className).toEqual('za-keyboard');
  });
  it('custom keyboard', function () {
    var _render2 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
      "data-testid": "root",
      dataSource: CAR_PLATE
    })),
        container = _render2.container;

    expect(container).toMatchSnapshot();
  });
  it('keyboard click', function () {
    var keyClick = jest.fn();

    var _render3 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
      "data-testid": "root",
      onKeyClick: keyClick
    })),
        container = _render3.container;

    var keys = container.getElementsByClassName('za-keyboard__item');

    _react2.fireEvent.click(keys[0]);

    expect(keyClick).toBeCalledWith('1');
  });
  it('disabled keyboard click', function () {
    var keyClick = jest.fn();

    var _render4 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
      "data-testid": "root",
      onKeyClick: keyClick,
      dataSource: CAR_PLATE
    })),
        container = _render4.container;

    var keys = container.getElementsByClassName('za-keyboard__item');

    _react2.fireEvent.click(keys[2]);

    expect(keyClick).toBeCalledTimes(0);

    _react2.fireEvent.click(keys[1]);

    expect(keyClick).toBeCalledWith('苏');
  });
  it('on Press', function () {
    var keyClick = jest.fn();

    var _render5 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
      "data-testid": "root",
      onKeyClick: keyClick
    })),
        container = _render5.container;

    var keys = container.getElementsByClassName('za-keyboard__item');

    _react2.fireEvent.mouseDown(keys[3]);

    jest.useFakeTimers();
    (0, _react2.act)(function () {
      jest.advanceTimersByTime(1000);
    });
    expect(keyClick).toBeCalledWith('delete');
  });
});