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

test("Pull request find preserves focus in the Author submenu", WEB, async ({ t3, app, screen, browser }) => {
  await t3.project("demo");
  await t3.open("/pull-requests");
  await screen.getByRole("button", "Filters", { exact: true }).tap();
  await screen.getByRole("menuitem", /^Author/).hover();
  await browser.keyboard.press("ArrowRight");
  await browser.keyboard.press("ArrowDown");
  await screen.getByRole("menuitemradio", "Anyone", { exact: true }).waitFor();
  await app.screenshot("author-menu-before-shortcut");
  await browser.keyboard.press("Control+f");
  try {
    await expect.poll(() => browser.evaluate(() => ({
      role: document.activeElement?.getAttribute("role"),
      text: document.activeElement?.textContent,
      insideMenu: Boolean(document.activeElement?.closest('[role="menu"]')),
    }))).toEqual({ role: "menuitemradio", text: "Anyone", insideMenu: true });
  } finally {
    await app.screenshot("author-menu-after-shortcut");
  }
});
