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

test("Cancelled checks fail the mobile overview and offer repair", IOS, async ({ t3, app, screen }) => {
  const project = await t3.project("Deployment example");
  const git = (...args: string[]) => execFileSync("git", ["-C", project, ...args], { stdio: "pipe" });
  git("remote", "add", "origin", "https://gitlab.com/julius54/cancelled-checks-proof-29809-1794668427.git");
  git("fetch", "origin", "main", "feature");
  git("checkout", "-B", "main", "origin/main");
  await t3.open();
  await screen.getByTestId("workspace-tab-pullRequests").tap();
  await screen.getByText("Deployment checks example", { exact: false }).first().tap();
  await screen.getByRole("button", /^Checks,/).tap();
  await app.screenshot("expanded-checks");
  await expect(screen.getByRole("button", "Checks, 1 check failing")).toBeVisible();
  await expect(screen.getByRole("button", /Fix failing checks/)).toBeVisible();
  await expect(screen.getByRole("button", /external \/ deploy.*Cancelled/)).toBeVisible();
});
