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

test("A branch beginning with a parenthesis retains branch git controls", WEB, async ({ t3, app, screen }) => {
  const project = await t3.project("parenthesis-branch", { "README.md": "Synthetic branch reproduction\n" });
  const git = (...args: string[]) => execFileSync("git", args, { cwd: project });
  git("init", "--bare", `${project}-origin.git`);
  git("remote", "add", "origin", `${project}-origin.git`);
  git("push", "-u", "origin", "main");
  git("switch", "-c", "(topic");
  await t3.thread({ project, title: "Inspect parenthesis branch", messages: ["Inspect this branch"] });
  await t3.open();
  await screen.getByRole("button", "Inspect parenthesis branch, Done, parenthesis-branch").tap();
  try {
    await expect(screen.getByText("Push", { exact: true })).toBeVisible();
  } finally {
    await screen.getByText("Syncing messages...", { exact: false }).waitFor({ state: "hidden" });
    await app.screenshot("parenthesis-branch-git-panel");
  }
});
