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

test("Escape clears pull request search and keeps focus on the page", WEB, async ({ t3, app, screen, browser }) => {
  const project = await t3.project("demo");
  await t3.thread({ project, title: "Search demonstration", messages: ["Hello"] });
  await t3.open("/pull-requests");
  const search = screen.getByRole("searchbox", "Search pull requests", { exact: true });
  await search.click();
  await search.fill("label:bug");
  await browser.keyboard.press("Escape");
  try {
    await expect(search).toBeVisible();
    await expect(search).toHaveValue("");
    await expect(search).toBeFocused();
  } finally {
    await app.screenshot("after-first-escape");
  }
});
