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

test("Typed and picked labels both restrict pull requests", WEB, async ({ t3, app, screen, browser }) => {
  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");
  await screen.getByRole("searchbox", "Search pull requests").fill("label:needs-rebase");
  await browser.keyboard.press("Enter");
  await screen.getByText("#34203", { exact: true }).waitFor({ timeout: 60000 });
  await screen.getByRole("button", /^Filters/).tap();
  await screen.getByRole("menuitem", /^Labels/).tap();
  await screen.getByRole("searchbox", "Search labels").fill("size:L");
  await screen.getByRole("menuitemcheckbox", /^size:L/).tap();
  await browser.keyboard.press("Escape");
  await browser.keyboard.press("Escape");
  await browser.locator('[data-slot="input-group"]:has([aria-label="Search pull requests"]) svg[aria-label="Loading"]').waitFor({ state: "hidden", timeout: 60000 });
  try {
    await expect(screen.getByText("#34203", { exact: true })).toBeHidden();
    await expect(screen.getByText("#38311", { exact: true })).toBeVisible();
  } finally {
    await app.screenshot("typed-and-picked-labels");
  }
});
