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

test("Local main upstream retains its behind status", WEB, async ({ t3, app, screen }) => {
  const project = await t3.project("local-upstream-demo", { "README.md": "Local upstream reproduction\n" });
  const git = (args: string[]) => runPromise(run("git", args, { cwd: project }));
  await git(["branch", "feature"]);
  await git(["-c", "user.name=Scenario", "-c", "user.email=scenario@example.invalid", "commit", "--allow-empty", "-m", "Advance main"]);
  await git(["branch", "base/main"]);
  await git(["switch", "feature"]);
  await git(["branch", "--set-upstream-to=base/main"]);
  await git(["branch", "--set-upstream-to=main"]);
  await t3.thread({ project, title: "Local upstream status", messages: ["Show the repository status"] });
  await t3.open();
  await screen.getByRole("button", "Git action options", { exact: true }).tap();
  await app.screenshot("local-upstream-status");
  await expect(screen.getByText("Behind upstream. Pull/rebase first.", { exact: true })).toBeVisible();
});
