import { expect } from "e2e";
import { test, WEB } from "./t3.ts";

test("Enabled send button and arrow stay still on hover", WEB, async ({ t3, app, screen, browser }) => {
  await t3.project("Hover demo");
  await t3.open();
  await screen.getByTestId("composer-editor").fill("Check the send button hover");
  const send = screen.getByRole("button", "Submit message");
  await send.hover();
  await browser.mouse.move(640, 400);
  const measure = async () => browser.evaluate(async () => {
    const button = document.querySelector('button[aria-label="Submit message"]')!;
    await Promise.all(button.getAnimations({ subtree: true }).map(a => a.finished));
    const rect = (element: Element) => {
      const r = element.getBoundingClientRect();
      return { x: r.x, y: r.y, width: r.width, height: r.height };
    };
    return { button: rect(button), arrow: rect(button.querySelector(":scope > svg")!), feedback: { background: getComputedStyle(button).backgroundColor, filter: getComputedStyle(button).filter } };
  });
  const resting = await measure();
  await app.screenshot("resting");
  for (let i = 0; i < 3; i++) {
    await send.hover();
    await measure();
    await browser.mouse.move(640, 400);
    await measure();
  }
  await send.hover();
  const hovered = await measure();
  await app.screenshot("hovered");
  console.log(JSON.stringify({ resting, hovered }));
  expect(hovered.button).toEqual(resting.button);
  expect(hovered.arrow).toEqual(resting.arrow);
  expect(hovered.feedback).not.toEqual(resting.feedback);
});
