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

test("Unsupported GitHub qualifiers leave open PRs visible", WEB, async ({ t3, app, browser, screen }) => {
  const project = await t3.project("t3code");
  await runPromise(run("git", ["remote", "add", "origin", "https://github.com/pingdotgg/t3code.git"], { cwd: project }));
  await t3.open("/pull-requests?involvement=all&state=open");
  const rows = browser.locator("[data-pull-request-key]");
  await rows.first().waitFor({ timeout: 60000 });
  await app.screenshot("empty-search");
  const search = screen.getByRole("searchbox", "Search pull requests");
  const results: Record<string, number> = {};
  for (const query of ["repo:pingdotgg/t3code", "assignee:@me", "base:main", "-base:main", "size:XS"]) {
    await search.fill(query);
    await search.press("Enter");
    await browser.locator('[data-slot="input-group"]:has([role="searchbox"]) .lucide-search').waitFor({ timeout: 60000 });
    await browser.locator('[data-pull-request-key], [data-slot="empty-title"]').first().waitFor({ timeout: 60000 });
    await app.screenshot(query.replace(/[^a-zA-Z0-9-]/g, "-"));
    results[query] = await rows.count();
  }
  expect(results["assignee:@me"]).toBeGreaterThan(0);
  expect(results["base:main"]).toBeGreaterThan(0);
});
