var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
import { jsx, jsxs } from "react/jsx-runtime";
import React from "react";
import { render, fireEvent } from "@testing-library/react";
import { ThemeProvider } from "../..";
import Rating from ".";
describe("<Rating />", () => {
  const originalOffsetWidth = Object.getOwnPropertyDescriptor(
    HTMLElement.prototype,
    "offsetWidth"
  );
  beforeAll(() => {
    Object.defineProperty(HTMLElement.prototype, "offsetWidth", {
      configurable: true,
      value: 76
      // 5 stars (5 * 12px + 4 * 4px gutter)
    });
  });
  afterAll(() => {
    Object.defineProperty(
      HTMLElement.prototype,
      "offsetWidth",
      originalOffsetWidth
    );
  });
  describe("Snapshots", () => {
    it("should match snapshot with Rating", () => {
      const { container } = render(
        /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(Rating, {}) })
      );
      expect(container).toMatchSnapshot();
    });
    it("should match snapshot with different values", () => {
      const { container } = render(
        /* @__PURE__ */ jsxs(ThemeProvider, { children: [
          /* @__PURE__ */ jsx(Rating, { value: 0 }),
          /* @__PURE__ */ jsx(Rating, { value: 0.5 }),
          /* @__PURE__ */ jsx(Rating, { value: 1 }),
          /* @__PURE__ */ jsx(Rating, { value: 1.1 }),
          /* @__PURE__ */ jsx(Rating, { value: 1.2 }),
          /* @__PURE__ */ jsx(Rating, { value: 1.3 }),
          /* @__PURE__ */ jsx(Rating, { value: 1.4 }),
          /* @__PURE__ */ jsx(Rating, { value: 1.5 }),
          /* @__PURE__ */ jsx(Rating, { value: 1.6 }),
          /* @__PURE__ */ jsx(Rating, { value: 1.7 }),
          /* @__PURE__ */ jsx(Rating, { value: 1.8 }),
          /* @__PURE__ */ jsx(Rating, { value: 1.9 }),
          /* @__PURE__ */ jsx(Rating, { value: 2 }),
          /* @__PURE__ */ jsx(Rating, { value: 2.5 }),
          /* @__PURE__ */ jsx(Rating, { value: 3 }),
          /* @__PURE__ */ jsx(Rating, { value: 3.5 }),
          /* @__PURE__ */ jsx(Rating, { value: 4 }),
          /* @__PURE__ */ jsx(Rating, { value: 4.5 })
        ] })
      );
      expect(container).toMatchSnapshot();
    });
    it("should match snapshot with different icon quantity", () => {
      const { container } = render(
        /* @__PURE__ */ jsxs(ThemeProvider, { children: [
          /* @__PURE__ */ jsx(Rating, { max: 3, value: 0 }),
          /* @__PURE__ */ jsx(Rating, { max: 3, value: 0.5 }),
          /* @__PURE__ */ jsx(Rating, { max: 3, value: 1 }),
          /* @__PURE__ */ jsx(Rating, { max: 3, value: 1.5 }),
          /* @__PURE__ */ jsx(Rating, { max: 3, value: 2 }),
          /* @__PURE__ */ jsx(Rating, { max: 3, value: 2.5 }),
          /* @__PURE__ */ jsx(Rating, { max: 3, value: 3 })
        ] })
      );
      expect(container).toMatchSnapshot();
    });
    it("should match snapshot with different icon", () => {
      const Circle = (props) => /* @__PURE__ */ jsx("svg", __spreadProps(__spreadValues({}, props), { children: /* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "12" }) }));
      const { container } = render(
        /* @__PURE__ */ jsxs(ThemeProvider, { children: [
          /* @__PURE__ */ jsx(Rating, { icon: { type: Circle }, value: 0 }),
          /* @__PURE__ */ jsx(Rating, { icon: { type: Circle }, value: 1 }),
          /* @__PURE__ */ jsx(Rating, { icon: { type: Circle }, value: 2 })
        ] })
      );
      expect(container).toMatchSnapshot();
    });
    it("should match snapshot when mouse over", () => {
      const { container } = render(
        /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(Rating, { readOnly: false }) })
      );
      const { firstChild } = container;
      fireEvent.mouseMove(firstChild, {
        /** Each star has 12px. Gutter is 4px.
         * For the third star, we should set clentX > 32px and < 48px */
        clientX: 40
      });
      expect(container).toMatchSnapshot();
    });
  });
  describe("Events", () => {
    it("should call onRate when clicking", () => {
      const onRateMock = jest.fn();
      const { container } = render(
        /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(Rating, { onRate: onRateMock, readOnly: false }) })
      );
      const { firstChild } = container;
      fireEvent.mouseMove(firstChild, {
        clientX: 40
        // third star position
      });
      fireEvent.click(firstChild);
      expect(onRateMock).toHaveBeenCalled();
      expect(onRateMock).toHaveBeenCalledWith(3);
    });
    it("should call onMouseOver callback", () => {
      const onMouseOverMock = jest.fn();
      const { container } = render(
        /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(Rating, { onMouseOver: onMouseOverMock, readOnly: false }) })
      );
      const { firstChild } = container;
      fireEvent.mouseOver(firstChild);
      expect(onMouseOverMock).toHaveBeenCalled();
    });
    it("should call onMouseLeave callback", () => {
      const onMouseLeaveMock = jest.fn();
      const { container } = render(
        /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(Rating, { onMouseLeave: onMouseLeaveMock, readOnly: false }) })
      );
      const { firstChild } = container;
      fireEvent.mouseLeave(firstChild);
      expect(onMouseLeaveMock).toHaveBeenCalled();
    });
  });
});
