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

test("Renamed origin still shows the existing same-repository pull request", WEB, async ({ t3, app, screen, browser }) => {
  await browser.emulateMedia({ colorScheme: "dark" });
  const project = await t3.project("renamed-origin");
  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", "--track", "origin/factory/issue-45859"]);
  const thread = await t3.thread({ project, title: "Renamed origin PR lookup", messages: ["Start"], model: "command-output" });
  await t3.open(thread);
  await screen.getByText("factory/issue-45859", { exact: true }).first().waitFor({ timeout: 60_000 });
  try {
    await expect(screen.getByText("#45948", { exact: false }).first()).toBeVisible({ timeout: 30_000 });
  } finally {
    await app.screenshot("renamed-origin-pr");
  }
});
