"use strict";

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

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

var React = _interopRequireWildcard(require("react"));

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

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

describe('Rate', function () {
  var getBoundingClientRectMock = jest.spyOn(HTMLElement.prototype, 'getBoundingClientRect');
  beforeAll(function () {
    getBoundingClientRectMock.mockReturnValue({
      left: 20,
      width: 300
    });
  });
  it('renders correctly', function () {
    var _render = (0, _react2.render)( /*#__PURE__*/React.createElement(_index.default, {
      allowHalf: true
    })),
        container = _render.container;

    expect(container).toMatchSnapshot();
  });
  it('should be render the specified number of nodes', function () {
    var _render2 = (0, _react2.render)( /*#__PURE__*/React.createElement(_index.default, {
      count: 10
    })),
        container = _render2.container;

    expect(container).toMatchSnapshot();
    expect(document.getElementsByClassName('za-rate__item')).toHaveLength(10);
  });
  it('should emit change and value event when rate icon is clicked', function () {
    var onChange = jest.fn();

    var _render3 = (0, _react2.render)( /*#__PURE__*/React.createElement(_index.default, {
      onChange: onChange,
      allowClear: true
    })),
        container = _render3.container;

    expect(container).toMatchSnapshot();
    var items = [].slice.call(document.getElementsByClassName('za-rate__item'));

    _react2.fireEvent.click(items === null || items === void 0 ? void 0 : items[0]);

    expect(onChange).toBeCalled();

    _react2.fireEvent.click(items === null || items === void 0 ? void 0 : items[0]);

    expect(onChange).toHaveBeenCalledTimes(2);
  });
  it('readOnly should be work', function () {
    var onChange = jest.fn();

    var _render4 = (0, _react2.render)( /*#__PURE__*/React.createElement(_index.default, {
      count: 10,
      readonly: true,
      onChange: onChange
    })),
        container = _render4.container;

    var items = container.getElementsByClassName('za-rate__item');

    _react2.fireEvent.click(items === null || items === void 0 ? void 0 : items[0]);

    expect(onChange).toBeCalledTimes(0);
  });
  it('drag should be work', function () {
    var onChange = jest.fn();

    var _render5 = (0, _react2.render)( /*#__PURE__*/React.createElement(_index.default, {
      count: 10,
      onChange: onChange,
      allowHalf: true
    })),
        container = _render5.container;

    var rate = container.querySelector('.za-rate');

    _react2.fireEvent.mouseDown(rate, {
      pointerId: 15,
      clientX: 10,
      buttons: 1
    });

    _react2.fireEvent.mouseMove(rate, {
      pointerId: 15,
      clientX: 100,
      buttons: 1
    });

    _react2.fireEvent.mouseUp(rate, {
      pointerId: 15,
      clientX: 200,
      buttons: 1
    });

    expect(onChange).toBeCalled();
  });
});