import * as React from 'react';
import { fireEvent, render } from '@testing-library/react';
import Rate from '../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 = render( /*#__PURE__*/React.createElement(Rate, {
      allowHalf: true
    })),
        container = _render.container;

    expect(container).toMatchSnapshot();
  });
  it('should be render the specified number of nodes', function () {
    var _render2 = render( /*#__PURE__*/React.createElement(Rate, {
      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 = render( /*#__PURE__*/React.createElement(Rate, {
      onChange: onChange,
      allowClear: true
    })),
        container = _render3.container;

    expect(container).toMatchSnapshot();
    var items = [].slice.call(document.getElementsByClassName('za-rate__item'));
    fireEvent.click(items === null || items === void 0 ? void 0 : items[0]);
    expect(onChange).toBeCalled();
    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 = render( /*#__PURE__*/React.createElement(Rate, {
      count: 10,
      readonly: true,
      onChange: onChange
    })),
        container = _render4.container;

    var items = container.getElementsByClassName('za-rate__item');
    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 = render( /*#__PURE__*/React.createElement(Rate, {
      count: 10,
      onChange: onChange,
      allowHalf: true
    })),
        container = _render5.container;

    var rate = container.querySelector('.za-rate');
    fireEvent.mouseDown(rate, {
      pointerId: 15,
      clientX: 10,
      buttons: 1
    });
    fireEvent.mouseMove(rate, {
      pointerId: 15,
      clientX: 100,
      buttons: 1
    });
    fireEvent.mouseUp(rate, {
      pointerId: 15,
      clientX: 200,
      buttons: 1
    });
    expect(onChange).toBeCalled();
  });
});