import { execFileSync } from "node:child_process";
import { expect } from "e2e";
import { test, WEB } from "./t3.ts";

test("Forgejo finds the branch PR when another PR has a one megabyte description", WEB, async ({ t3, app, screen }) => {
  const project = await t3.project("forgejo-demo");
  const git = (...args: string[]) => execFileSync("git", args, { cwd: project, stdio: "pipe" });
  git("remote", "add", "origin", "http://127.0.0.1:38201/factory/demo.git");
  git("fetch", "origin");
  git("checkout", "-B", "feature-a", "origin/feature-a");
  const thread = await t3.thread({ project, title: "Find Feature A pull request", messages: ["Check this branch"] });
  await t3.open(thread);
  await screen.getByRole("group", "Git actions", { exact: true }).waitFor({ state: "visible" });
  await screen.getByText("first fixture turn complete").waitFor({ state: "visible" });
  await screen.getByText("Syncing messages...", { exact: false }).waitFor({ state: "hidden" });
  try {
    await expect(screen.getByRole("button", "Pull request #1, open: Feature A", { exact: true })).toBeVisible();
  } finally {
    await app.screenshot("branch-pr-lookup");
  }
});
