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

test("Leading-slash SCP GitCafe remote finds its open pull request", WEB, async ({ t3, app, screen }) => {
  const project = await t3.project("webls");
  const git = (args: string[]) => runPromise(run("git", args, { cwd: project }));
  await git(["remote", "add", "origin", "https://git.cafe/versecafe/webls.git"]);
  await git(["fetch", "--quiet", "origin", "from_string()"]);
  await git(["checkout", "--quiet", "-B", "from_string()", "--track", "origin/from_string()"]);
  await git(["remote", "set-url", "origin", "ssh@git.cafe:/versecafe/webls.git"]);
  const thread = await t3.thread({ project, title: "GitCafe pull request lookup", messages: ["Start"] });
  await t3.open(thread);
  const pr = screen.getByRole("link", /#1.*webls v2/);
  try {
    await expect(pr).toBeVisible();
  } finally {
    await screen.getByText("Syncing messages...", { exact: true }).waitFor({ state: "hidden" });
    await app.screenshot("gitcafe-leading-slash-pull-request");
  }
});
