/* eslint-disable @typescript-eslint/no-unused-vars */
import React from "react";
import { testExamples, fireEvent, render, act } from "@test/utils";
import { getOverlayRoot } from "../../_util/get-overlay-root";
import { Popover } from "../Popover";

// 测试组件代码 Example 快照
testExamples(__dirname);

test("popout correctly", () => {
  const hoverPopupText = "这是浮层内容";
  const hoverTargetText = "鼠标上来";
  const { getByText } = render(
    <Popover placement="top-start" overlay={<div>{hoverPopupText}</div>}>
      鼠标上来
    </Popover>
  );

  const overlayRoot = getOverlayRoot();

  // 鼠标进入前，不应该有内容
  expect(overlayRoot.textContent.indexOf(hoverPopupText)).toBe(-1);

  act(() => {
    // 模拟鼠标进入
    fireEvent.mouseEnter(getByText(hoverTargetText));
    jest.runAllTimers();
  });
  // 鼠标进入后，有内容
  expect(overlayRoot.textContent.indexOf(hoverPopupText)).not.toBe(-1);

  act(() => {
    // 模拟鼠标离开
    fireEvent.mouseOut(getByText(hoverTargetText));
    jest.runAllTimers();
  });
  // 鼠标离开，不应该有内容
  expect(overlayRoot.textContent.indexOf(hoverPopupText)).toBe(-1);
});
