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

test("GitLab system approval appears in the merge request timeline", WEB, async ({ t3, app, screen }) => {
  const project = await t3.project("approval-demo");
  const git = (...args: string[]) => execFileSync("git", args, { cwd: project });
  git("remote", "add", "origin", "https://gitlab.com/julius54/t3-approval-proof-9802.git");
  git("fetch", "origin");
  git("checkout", "-B", "feature", "origin/feature");
  const thread = await t3.thread({ project, title: "Review approval", messages: ["Inspect this merge request"] });
  await t3.open(thread);
  await screen.getByRole("link", /MR #1/).tap();
  await screen.getByText("regular comment", { exact: true }).waitFor({ state: "visible" });
  await app.screenshot("summary");
  await screen.getByRole("button", "Timeline").tap();
  await screen.getByText("Merge request opened", { exact: true }).waitFor({ state: "visible" });
  await app.screenshot("approval-timeline");
  await expect(screen.getByText("Approved", { exact: true, visible: true })).toBeVisible();
});
