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

test("An old remote name still finds the same-repository pull request", WEB, async ({ t3, app, screen }) => {
  const project = await t3.project("renamed-repository");
  const git = (args: string[]) => runPromise(run("git", args, { cwd: project }));
  await git(["remote", "add", "origin", "https://github.com/pingdotgg/t3-code.git"]);
  await git(["fetch", "--depth=1", "origin", "factory/issue-45859"]);
  await git(["checkout", "-B", "factory/issue-45859", "FETCH_HEAD"]);
  await git(["config", "branch.factory/issue-45859.remote", "origin"]);
  await git(["config", "branch.factory/issue-45859.merge", "refs/heads/factory/issue-45859"]);
  const thread = await t3.thread({ project, title: "Renamed repository PR lookup", messages: ["Check the existing pull request"] });
  await t3.open(thread);
  try {
    await expect(screen.getByText("#45948", { exact: true })).toBeVisible({ timeout: 90_000 });
  } finally {
    await app.screenshot("renamed-repository-pr");
  }
});
