import React from 'react';
import { act, cleanup, fireEvent, render, screen } from '@testing-library/react';
import Keyboard from '../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(cleanup);
  it('should render keyboard dom', function () {
    var _render = render( /*#__PURE__*/React.createElement(Keyboard, {
      "data-testid": "root"
    })),
        container = _render.container;

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

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

    var _render3 = render( /*#__PURE__*/React.createElement(Keyboard, {
      "data-testid": "root",
      onKeyClick: keyClick
    })),
        container = _render3.container;

    var keys = container.getElementsByClassName('za-keyboard__item');
    fireEvent.click(keys[0]);
    expect(keyClick).toBeCalledWith('1');
  });
  it('disabled keyboard click', function () {
    var keyClick = jest.fn();

    var _render4 = render( /*#__PURE__*/React.createElement(Keyboard, {
      "data-testid": "root",
      onKeyClick: keyClick,
      dataSource: CAR_PLATE
    })),
        container = _render4.container;

    var keys = container.getElementsByClassName('za-keyboard__item');
    fireEvent.click(keys[2]);
    expect(keyClick).toBeCalledTimes(0);
    fireEvent.click(keys[1]);
    expect(keyClick).toBeCalledWith('苏');
  });
  it('on Press', function () {
    var keyClick = jest.fn();

    var _render5 = render( /*#__PURE__*/React.createElement(Keyboard, {
      "data-testid": "root",
      onKeyClick: keyClick
    })),
        container = _render5.container;

    var keys = container.getElementsByClassName('za-keyboard__item');
    fireEvent.mouseDown(keys[3]);
    jest.useFakeTimers();
    act(function () {
      jest.advanceTimersByTime(1000);
    });
    expect(keyClick).toBeCalledWith('delete');
  });
});