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

test("Pasted type:pr keeps the is:pr search results", WEB, async ({ t3, app, screen }) => {
  const project = await t3.project("Search evidence", {
    ".git/config": '[core]\n\trepositoryformatversion = 0\n[remote "origin"]\n\turl = https://github.com/pingdotgg/t3code.git\n',
  });
  await t3.thread({ project, title: "Search evidence", messages: ["Start"] });
  await t3.open("/pull-requests");
  const search = screen.getByRole("searchbox", "Search pull requests");
  await search.waitFor({ timeout: 60_000 });
  await search.fill("is:pr is:open bug");
  await screen.getByText("matched in the description", { exact: true }).first().waitFor({ timeout: 60_000 });
  await app.screenshot("is-pr-baseline");
  const matches = [];
  for (const [query, label] of [
    ["type:pr is:open bug", "type-pr-selector"],
    ["TYPE:PR is:open bug", "uppercase-type-pr-selector"],
  ]) {
    await search.fill(query);
    await screen.getByText(/Nothing matches|matched in the description/).first().waitFor({ timeout: 60_000 });
    await app.screenshot(label);
    matches.push(await screen.getByText("matched in the description", { exact: true }).first().isVisible());
  }
  expect(matches, "Both type:pr spellings retain matching PRs").toEqual([true, true]);
});
