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

test("Fork PR lookup tolerates lowercase remote owner behind 21 newer fork PRs", WEB, async ({t3, app, screen}) => {
  const project = await t3.project("project");
  const git = (...args: string[]) => execFileSync("git", args, {cwd: project, encoding: "utf8"});
  git("remote", "add", "origin", "http://127.0.0.1:14935/maria/project.git");
  git("remote", "add", "alice", "http://127.0.0.1:14935/alice/project.git");
  git("fetch", "origin");
  git("fetch", "alice");
  git("checkout", "-B", "feature", "alice/feature");
  const thread = await t3.thread({project, title: "Fork pull request", messages: ["Show this project."]});
  await t3.open(thread);
  await screen.getByRole("region", "Version Control", {exact: true}).waitFor();
  try {
    await expect(screen.getByRole("button", "Pull request #1, open: Alice feature", {exact: true})).toBeVisible();
  } finally {
    await screen.getByText("Syncing messages...", {exact: true}).waitFor({state: "hidden"});
    await screen.getByText("Loading messages...", {exact: true}).waitFor({state: "hidden"});
    await app.screenshot("fork-pr-lowercase-owner");
  }
});
