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

const title = "Document the release (proof 48669)";

test("Pasted pending status preserves matching Azure pull requests", WEB, async ({ t3, app, screen, browser }) => {
  const project = await t3.project("Pending query proof");
  await runPromise(run("git", ["remote", "add", "origin", "https://dev.azure.com/t3code-factory-test/t3-factory-test/_git/t3-factory-test"], { cwd: project }));
  await t3.open("/pull-requests?host=dev.azure.com&state=open&involvement=all");
  await screen.getByText(title, { exact: true }).waitFor({ timeout: 60_000 });
  const search = screen.getByRole("searchbox", "Search pull requests");
  const results: boolean[] = [];
  for (const query of ["Document", "Document -status:failure", "Document -status:pending", "Document status:pending"]) {
    await search.fill(query);
    await search.press("Enter");
    await screen.getByText(new RegExp("^(Document the release \\(proof 48669\\)|Nothing matches)")).waitFor({ timeout: 60_000 });
    await browser.locator('main:not(:has(svg[aria-label="Loading"]))').waitFor({ timeout: 60_000 });
    await app.screenshot(query.replaceAll(" ", "-").replaceAll(":", "-"));
    results.push(await browser.evaluate(() => document.body.innerText.includes("Document the release (proof 48669)")));
  }
  expect(results).toEqual([true, true, true, true]);
});
