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

test("Typed GitHub draft qualifiers update PR filters", WEB, async ({ t3, app, browser, screen }) => {
  const project = await t3.project("PR search proof");
  await runPromise(run("git", ["remote", "add", "origin", "https://github.com/pingdotgg/t3code.git"], { cwd: project }));
  await t3.open("/pull-requests");
  const search = screen.getByRole("searchbox", "Search pull requests");
  const seen: string[] = [];
  for (const [query, label] of [["draft:true", "draft-true"], ["is:draft", "is-draft"], ["-is:draft", "minus-is-draft"], ["-draft:true", "minus-draft-true"], ["is:pr is:open is:draft", "github-query"]]) {
    await search.fill(query);
    await browser.keyboard.press("Enter");
    await screen.getByText("Loading pull requests…", { exact: true }).waitFor({ state: "hidden", timeout: 120_000 });
    await browser.locator("[data-pull-request-key]").first().waitFor({ timeout: 120_000 });
    await browser.locator('[data-slot="input-group"] [role="status"]').waitFor({ state: "hidden", timeout: 120_000 });
    await browser.locator('button[aria-label="Refresh pull requests"]:not(:disabled)').waitFor({ timeout: 120_000 });
    await screen.getByRole("button", /^Filters/).tap();
    const draft = screen.getByRole("menuitem", /^Draft/);
    await draft.waitFor();
    await app.screenshot(label);
    seen.push(await draft.textContent() ?? "");
    await browser.keyboard.press("Escape");
  }
  expect(seen).toEqual(["Draft Drafts only", "Draft Drafts only", "Draft Hide drafts", "Draft Hide drafts", "Draft Drafts only"]);
});
