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

test("Status finds the original MR beyond twenty newer same-named fork MRs", WEB, async ({ t3, app, screen }) => {
  const project = await t3.project("Branch MR lookup");
  const git = (...args: string[]) => execFileSync("git", args, { cwd: project, encoding: "utf8" });
  git("remote", "add", "origin", process.env.MR_FIXTURE_URL!);
  git("fetch", "origin");
  git("checkout", "-B", "feature", "origin/feature");
  git("branch", "--set-upstream-to=origin/feature", "feature");
  const thread = await t3.thread({ project, title: "Find original MR", messages: ["Verify original MR"] });
  await t3.open(thread);
  await screen.getByRole("group", "Git actions").waitFor({ state: "visible" });
  await screen.getByText(/Create MR|#1: Original branch MR/).first().waitFor({ state: "visible", timeout: 60000 });
  await app.screenshot("branch-status");
  await expect(screen.getByText("#1: Original branch MR", { exact: true })).toBeVisible();
});
